From 789490589a4869c7f2bffae727d41ae0b1ae79c8 Mon Sep 17 00:00:00 2001 From: Sebastian Widmer Date: Tue, 28 May 2024 10:01:17 +0200 Subject: [PATCH] Implement `compileMeta` endpoint --- openapi.yaml | 133 ++++++++++++ pkg/api/openapi.go | 407 ++++++++++++++++++++++++++++++------ pkg/service/cluster.go | 42 ++++ pkg/service/cluster_test.go | 116 ++++++++++ 4 files changed, 629 insertions(+), 69 deletions(-) diff --git a/openapi.yaml b/openapi.yaml index 20d2596..c8a976d 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -102,6 +102,8 @@ components: $ref: '#/components/schemas/ClusterFacts' dynamicFacts: $ref: '#/components/schemas/DynamicClusterFacts' + compileMeta: + $ref: '#/components/schemas/ClusterCompileMeta' gitRepo: $ref: '#/components/schemas/GitRepo' tenantGitRepoRevision: @@ -160,6 +162,104 @@ components: major: "1" minor: "20" platform: linux/amd64 + # ClusterCompileMeta is exported from k8s. Must match the k8s structure. + # kubectl get --raw /openapi/v3/apis/syn.tools/v1alpha1 | yq --prettyPrint '.components.schemas["tools.syn.v1alpha1.Cluster"].properties.status.properties.compileMeta' + ClusterCompileMeta: + description: CompileMeta contains information about the last compilation with Commodore. + type: object + properties: + commodoreBuildInfo: + description: CommodoreBuildInfo is the freeform build information reported by the Commodore binary used for the last compilation. + type: object + additionalProperties: + type: string + global: + description: Global contains the information of the global configuration used for the last compilation. + type: object + properties: + gitSha: + description: GitSHA is the git commit SHA of the used commit. + type: string + path: + description: Path is the path inside the git repository where the configuration is stored. + type: string + url: + description: URL is the URL of the git repository. + type: string + version: + description: |- + Version is the version of the configuration. + Can point to a tag, branch or any other git reference. + type: string + instances: + description: |- + Instances contains the information of the component instances used for the last compilation. + The key is the name of the component instance. + type: object + additionalProperties: + description: CompileMetaInstanceVersionInfo contains information about the version of a component instance. + type: object + properties: + component: + description: Component is the name of a component instance. + type: string + gitSha: + description: GitSHA is the git commit SHA of the used commit. + type: string + path: + description: Path is the path inside the git repository where the configuration is stored. + type: string + url: + description: URL is the URL of the git repository. + type: string + version: + description: |- + Version is the version of the configuration. + Can point to a tag, branch or any other git reference. + type: string + lastCompile: + description: LastCompile is the time of the last successful compilation. + type: string + format: date-time + packages: + description: Packages contains the information of the packages used for the last compilation. + type: object + additionalProperties: + description: CompileMetaVersionInfo contains information about the version of a configuration repo or a package. + type: object + properties: + gitSha: + description: GitSHA is the git commit SHA of the used commit. + type: string + path: + description: Path is the path inside the git repository where the configuration is stored. + type: string + url: + description: URL is the URL of the git repository. + type: string + version: + description: |- + Version is the version of the configuration. + Can point to a tag, branch or any other git reference. + type: string + tenant: + description: Tenant contains the information of the tenant configuration used for the last compilation. + type: object + properties: + gitSha: + description: GitSHA is the git commit SHA of the used commit. + type: string + path: + description: Path is the path inside the git repository where the configuration is stored. + type: string + url: + description: URL is the URL of the git repository. + type: string + version: + description: |- + Version is the version of the configuration. + Can point to a tag, branch or any other git reference. + type: string Cluster: allOf: - $ref: '#/components/schemas/ClusterId' @@ -623,6 +723,39 @@ paths: $ref: '#/components/schemas/Reason' default: $ref: '#/components/responses/Default' + /clusters/{clusterId}/compileMeta: + post: + operationId: postClusterCompileMeta + summary: Stores compilation metadata for a cluster + description: | + Stores compilation metadata for a cluster. + + Intended for commodore to report the last compilation. + Contains version information and timestamps. + tags: + - cluster + - metadata + - version-information + parameters: + - $ref: '#/components/parameters/ClusterIdParameter' + requestBody: + description: Stores compilation metadata for a cluster + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/ClusterCompileMeta' + responses: + '204': + description: Data stored + '403': + description: Cluster update forbidden + content: + application/json: + schema: + $ref: '#/components/schemas/Reason' + default: + $ref: '#/components/responses/Default' /install/steward.json: get: operationId: installSteward diff --git a/pkg/api/openapi.go b/pkg/api/openapi.go index 4bfe408..008ce6c 100644 --- a/pkg/api/openapi.go +++ b/pkg/api/openapi.go @@ -15,6 +15,7 @@ import ( "net/url" "path" "strings" + "time" "github.com/getkin/kin-openapi/openapi3" "github.com/labstack/echo/v4" @@ -45,6 +46,83 @@ type Cluster struct { ClusterProperties `yaml:",inline"` } +// ClusterCompileMeta CompileMeta contains information about the last compilation with Commodore. +type ClusterCompileMeta struct { + // CommodoreBuildInfo CommodoreBuildInfo is the freeform build information reported by the Commodore binary used for the last compilation. + CommodoreBuildInfo *map[string]string `json:"commodoreBuildInfo,omitempty"` + + // Global Global contains the information of the global configuration used for the last compilation. + Global *struct { + // GitSha GitSHA is the git commit SHA of the used commit. + GitSha *string `json:"gitSha,omitempty"` + + // Path Path is the path inside the git repository where the configuration is stored. + Path *string `json:"path,omitempty"` + + // Url URL is the URL of the git repository. + Url *string `json:"url,omitempty"` + + // Version Version is the version of the configuration. + // Can point to a tag, branch or any other git reference. + Version *string `json:"version,omitempty"` + } `json:"global,omitempty"` + + // Instances Instances contains the information of the component instances used for the last compilation. + // The key is the name of the component instance. + Instances *map[string]struct { + // Component Component is the name of a component instance. + Component *string `json:"component,omitempty"` + + // GitSha GitSHA is the git commit SHA of the used commit. + GitSha *string `json:"gitSha,omitempty"` + + // Path Path is the path inside the git repository where the configuration is stored. + Path *string `json:"path,omitempty"` + + // Url URL is the URL of the git repository. + Url *string `json:"url,omitempty"` + + // Version Version is the version of the configuration. + // Can point to a tag, branch or any other git reference. + Version *string `json:"version,omitempty"` + } `json:"instances,omitempty"` + + // LastCompile LastCompile is the time of the last successful compilation. + LastCompile *time.Time `json:"lastCompile,omitempty"` + + // Packages Packages contains the information of the packages used for the last compilation. + Packages *map[string]struct { + // GitSha GitSHA is the git commit SHA of the used commit. + GitSha *string `json:"gitSha,omitempty"` + + // Path Path is the path inside the git repository where the configuration is stored. + Path *string `json:"path,omitempty"` + + // Url URL is the URL of the git repository. + Url *string `json:"url,omitempty"` + + // Version Version is the version of the configuration. + // Can point to a tag, branch or any other git reference. + Version *string `json:"version,omitempty"` + } `json:"packages,omitempty"` + + // Tenant Tenant contains the information of the tenant configuration used for the last compilation. + Tenant *struct { + // GitSha GitSHA is the git commit SHA of the used commit. + GitSha *string `json:"gitSha,omitempty"` + + // Path Path is the path inside the git repository where the configuration is stored. + Path *string `json:"path,omitempty"` + + // Url URL is the URL of the git repository. + Url *string `json:"url,omitempty"` + + // Version Version is the version of the configuration. + // Can point to a tag, branch or any other git reference. + Version *string `json:"version,omitempty"` + } `json:"tenant,omitempty"` +} + // ClusterFacts Facts about a cluster object. Statically configured key/value pairs. type ClusterFacts map[string]interface{} @@ -61,6 +139,9 @@ type ClusterProperties struct { // Annotations Unstructured key value map containing arbitrary metadata Annotations *Annotations `json:"annotations,omitempty"` + // CompileMeta CompileMeta contains information about the last compilation with Commodore. + CompileMeta *ClusterCompileMeta `json:"compileMeta,omitempty"` + // DisplayName Display Name of the cluster DisplayName *string `json:"displayName,omitempty"` @@ -224,6 +305,9 @@ type UpdateClusterApplicationMergePatchPlusJSONRequestBody ClusterProperties // PutClusterJSONRequestBody defines body for PutCluster for application/json ContentType. type PutClusterJSONRequestBody Cluster +// PostClusterCompileMetaJSONRequestBody defines body for PostClusterCompileMeta for application/json ContentType. +type PostClusterCompileMetaJSONRequestBody ClusterCompileMeta + // UpdateInventoryJSONRequestBody defines body for UpdateInventory for application/json ContentType. type UpdateInventoryJSONRequestBody Inventory @@ -336,6 +420,11 @@ type ClientInterface interface { PutCluster(ctx context.Context, clusterId ClusterIdParameter, body PutClusterJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + // PostClusterCompileMetaWithBody request with any body + PostClusterCompileMetaWithBody(ctx context.Context, clusterId ClusterIdParameter, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + PostClusterCompileMeta(ctx context.Context, clusterId ClusterIdParameter, body PostClusterCompileMetaJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + // Docs request Docs(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -501,6 +590,30 @@ func (c *Client) PutCluster(ctx context.Context, clusterId ClusterIdParameter, b return c.Client.Do(req) } +func (c *Client) PostClusterCompileMetaWithBody(ctx context.Context, clusterId ClusterIdParameter, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPostClusterCompileMetaRequestWithBody(c.Server, clusterId, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) PostClusterCompileMeta(ctx context.Context, clusterId ClusterIdParameter, body PostClusterCompileMetaJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPostClusterCompileMetaRequest(c.Server, clusterId, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + func (c *Client) Docs(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewDocsRequest(c.Server) if err != nil { @@ -987,6 +1100,53 @@ func NewPutClusterRequestWithBody(server string, clusterId ClusterIdParameter, c return req, nil } +// NewPostClusterCompileMetaRequest calls the generic PostClusterCompileMeta builder with application/json body +func NewPostClusterCompileMetaRequest(server string, clusterId ClusterIdParameter, body PostClusterCompileMetaJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewPostClusterCompileMetaRequestWithBody(server, clusterId, "application/json", bodyReader) +} + +// NewPostClusterCompileMetaRequestWithBody generates requests for PostClusterCompileMeta with any type of body +func NewPostClusterCompileMetaRequestWithBody(server string, clusterId ClusterIdParameter, contentType string, body io.Reader) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "clusterId", runtime.ParamLocationPath, clusterId) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/clusters/%s/compileMeta", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + // NewDocsRequest generates requests for Docs func NewDocsRequest(server string) (*http.Request, error) { var err error @@ -1505,6 +1665,11 @@ type ClientWithResponsesInterface interface { PutClusterWithResponse(ctx context.Context, clusterId ClusterIdParameter, body PutClusterJSONRequestBody, reqEditors ...RequestEditorFn) (*PutClusterResponse, error) + // PostClusterCompileMetaWithBodyWithResponse request with any body + PostClusterCompileMetaWithBodyWithResponse(ctx context.Context, clusterId ClusterIdParameter, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostClusterCompileMetaResponse, error) + + PostClusterCompileMetaWithResponse(ctx context.Context, clusterId ClusterIdParameter, body PostClusterCompileMetaJSONRequestBody, reqEditors ...RequestEditorFn) (*PostClusterCompileMetaResponse, error) + // DocsWithResponse request DocsWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*DocsResponse, error) @@ -1715,6 +1880,29 @@ func (r PutClusterResponse) StatusCode() int { return 0 } +type PostClusterCompileMetaResponse struct { + Body []byte + HTTPResponse *http.Response + JSON403 *Reason + JSONDefault *Default +} + +// Status returns HTTPResponse.Status +func (r PostClusterCompileMetaResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r PostClusterCompileMetaResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + type DocsResponse struct { Body []byte HTTPResponse *http.Response @@ -2077,6 +2265,23 @@ func (c *ClientWithResponses) PutClusterWithResponse(ctx context.Context, cluste return ParsePutClusterResponse(rsp) } +// PostClusterCompileMetaWithBodyWithResponse request with arbitrary body returning *PostClusterCompileMetaResponse +func (c *ClientWithResponses) PostClusterCompileMetaWithBodyWithResponse(ctx context.Context, clusterId ClusterIdParameter, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostClusterCompileMetaResponse, error) { + rsp, err := c.PostClusterCompileMetaWithBody(ctx, clusterId, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParsePostClusterCompileMetaResponse(rsp) +} + +func (c *ClientWithResponses) PostClusterCompileMetaWithResponse(ctx context.Context, clusterId ClusterIdParameter, body PostClusterCompileMetaJSONRequestBody, reqEditors ...RequestEditorFn) (*PostClusterCompileMetaResponse, error) { + rsp, err := c.PostClusterCompileMeta(ctx, clusterId, body, reqEditors...) + if err != nil { + return nil, err + } + return ParsePostClusterCompileMetaResponse(rsp) +} + // DocsWithResponse request returning *DocsResponse func (c *ClientWithResponses) DocsWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*DocsResponse, error) { rsp, err := c.Docs(ctx, reqEditors...) @@ -2476,6 +2681,39 @@ func ParsePutClusterResponse(rsp *http.Response) (*PutClusterResponse, error) { return response, nil } +// ParsePostClusterCompileMetaResponse parses an HTTP response from a PostClusterCompileMetaWithResponse call +func ParsePostClusterCompileMetaResponse(rsp *http.Response) (*PostClusterCompileMetaResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &PostClusterCompileMetaResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest Reason + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest Default + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSONDefault = &dest + + } + + return response, nil +} + // ParseDocsResponse parses an HTTP response from a DocsWithResponse call func ParseDocsResponse(rsp *http.Response) (*DocsResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) @@ -2885,6 +3123,9 @@ type ServerInterface interface { // Updates or creates a cluster // (PUT /clusters/{clusterId}) PutCluster(ctx echo.Context, clusterId ClusterIdParameter) error + // Stores compilation metadata for a cluster + // (POST /clusters/{clusterId}/compileMeta) + PostClusterCompileMeta(ctx echo.Context, clusterId ClusterIdParameter) error // API documentation // (GET /docs) Docs(ctx echo.Context) error @@ -3047,6 +3288,24 @@ func (w *ServerInterfaceWrapper) PutCluster(ctx echo.Context) error { return err } +// PostClusterCompileMeta converts echo context to params. +func (w *ServerInterfaceWrapper) PostClusterCompileMeta(ctx echo.Context) error { + var err error + // ------------- Path parameter "clusterId" ------------- + var clusterId ClusterIdParameter + + err = runtime.BindStyledParameterWithOptions("simple", "clusterId", ctx.Param("clusterId"), &clusterId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter clusterId: %s", err)) + } + + ctx.Set(BearerAuthScopes, []string{}) + + // Invoke the callback with all the unmarshaled arguments + err = w.Handler.PostClusterCompileMeta(ctx, clusterId) + return err +} + // Docs converts echo context to params. func (w *ServerInterfaceWrapper) Docs(ctx echo.Context) error { var err error @@ -3252,6 +3511,7 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL router.GET(baseURL+"/clusters/:clusterId", wrapper.GetCluster) router.PATCH(baseURL+"/clusters/:clusterId", wrapper.UpdateCluster) router.PUT(baseURL+"/clusters/:clusterId", wrapper.PutCluster) + router.POST(baseURL+"/clusters/:clusterId/compileMeta", wrapper.PostClusterCompileMeta) router.GET(baseURL+"/docs", wrapper.Docs) router.GET(baseURL+"/healthz", wrapper.Healthz) router.GET(baseURL+"/install/steward.json", wrapper.InstallSteward) @@ -3270,75 +3530,84 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ - "H4sIAAAAAAAC/+Q8+VPbSJf/Spd2q5LU5wNjQwaqvtqPIwFPCBBsSDIJtbSlZ7uh1a10tw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KgSPhYqUhu", - "N5s4IsZJT+SYNRiopiOnKS0BDR2o/sfA+/fXeG2t7UvwBai+fmIegHEoODhhdJqEzhI3rHf/NflaGH8P", - "+S7wbC5olFymSp8X79ydSVSQ0jdI5D4AytlIS7RAVxhTRXwuokrSskzmS4L2soLgKpMvOyZ7CA0Xxqsd", - "ASgCQXjgolYcRNrZak96Krg+hHpTZryxHPOYBohxlehviJnx3zMB7SYegGCgQF6ASBRmEBMa7GOlr7K+", - "tt6qr3Xqrc1+a2t7rbPd6fzl1UyCS6jODLyR7xl3tMfDkOjs4o9grdNe/2O9g7eGwVbndWew+brV/mPw", - "erO95rfbw/U/NoJ2e31oP+sLAB2KbRYLmNnHKTlGP9Yam/+6acuWfsezVyPearQ2Gq01r+aF+JprcvSZ", - "kDDz73X9IqJYDbkIvW2PEhbfNXEYbHaq9esg86pFEe05VbYWUYyOtTQ2pgEwFx1L0S1IQmIZS693iKJ4", - "QIlvMsMmsmfNH9pjOZXwC8T4WGHKRzNEOT/mUJsIXo68RUOUclyHYH1jo7WFdnZ2dvbax/d4r0X/2u+2", - "jvtvNvSz7v7BFt74eHsU3/p378+mwfG3bocP4/tPsS9230UHJ5PTi63Tk84ovv7Kqpz2mEv1Dqay+vY3", - "jN8ypM/IxGS1+5EgtHd5aWySEgYo4lKSAQXDF/M4oqAZJV8VLjUiiuJBw+chWul+O8N47/DdRf/6W3w3", - "UZt77zdVcNDpHUWtXcWa7AQOD99snJ/cnwXDrywHHPxA4roc4/U6I1JF6xubBsmb9Yvrvw6Px0efjvnn", - "flcNQnofHO5Mj/ufDb7i37u7u29777/d/wkXW+L8/rxz85Gog2s465x+7OH1rd7ptz9bw4ubsbpuH95u", - "3V0fXXy6+CzOtz7Qzx/FydGn3ejD5ruP14Pr/n4/2L/hfPz2fjR48/nf1cKwD0qCiMAnQwJSRz1slCrx", - "KMUELhGPLlwEpxREA+24goYP0YuYucMvUAiYSUTUC2m8UohZDkb2fUF2OqesojoWtCLZjylFOurn1EZT", -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", + "FLSvoMZZNvHQ8GIu6+Zo9FUPhUperrAu8Oj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faqQ+jFTzQKg/unggeJb2IjW/Qof4RR+U2L1SH3mYKx+4pmDugmYep7we/D7VywAdzOgv2U", + "cX8WfuF7lVJCXx74r9JV3leYHC//XHHNzrTyXy6zZxvLj+dvzyuE5lfubGvWFQsdqLxWWAWjc2tXOcu/", + "OLD/P3x6+L8AAAD//2CuXPXgWQAA", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/pkg/service/cluster.go b/pkg/service/cluster.go index f52b635..4039343 100644 --- a/pkg/service/cluster.go +++ b/pkg/service/cluster.go @@ -12,6 +12,7 @@ import ( synv1alpha1 "github.com/projectsyn/lieutenant-operator/api/v1alpha1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" "github.com/projectsyn/lieutenant-api/pkg/api" @@ -211,6 +212,38 @@ func (s *APIImpl) PutCluster(c echo.Context, clusterID api.ClusterIdParameter) e return s.updateCluster(ctx, found) } +// PostClusterCompileMeta compiles the meta data of a cluster +func (s *APIImpl) PostClusterCompileMeta(c echo.Context, clusterID api.ClusterIdParameter) error { + ctx := c.(*APIContext) + + body := &api.ClusterCompileMeta{} + if err := ctx.Bind(body); err != nil { + return echo.NewHTTPError(http.StatusBadRequest, err) + } + + toPatch := &synv1alpha1.Cluster{ + ObjectMeta: metav1.ObjectMeta{ + Name: string(clusterID), + Namespace: s.namespace, + }, + } + patch := []map[string]any{ + {"op": "replace", "path": "/status/compileMeta", "value": body}, + } + rawPatch, err := json.Marshal(patch) + if err != nil { + return fmt.Errorf("failed to marshal patch: %w", err) + } + + if err := retryOnConflict(func() error { + return ctx.client.Status().Patch(ctx.Request().Context(), toPatch, client.RawPatch(types.JSONPatchType, rawPatch)) + }); err != nil { + return err + } + + return ctx.NoContent(http.StatusNoContent) +} + func apiClusterWithInstallURL(ctx *APIContext, cluster *synv1alpha1.Cluster) *api.Cluster { apiCluster := api.NewAPIClusterFromCRD(*cluster) @@ -230,3 +263,12 @@ func bootstrapToken(cluster *synv1alpha1.Cluster) (token string, valid bool) { return cluster.Status.BootstrapToken.Token, cluster.Status.BootstrapToken.TokenValid } + +// retryOnConflict retries the given function if the returned error is a conflict (HTTP 409) error once +func retryOnConflict(f func() error) error { + err := f() + if errors.IsConflict(err) { + return f() + } + return err +} diff --git a/pkg/service/cluster_test.go b/pkg/service/cluster_test.go index 47f3fb2..171e19b 100644 --- a/pkg/service/cluster_test.go +++ b/pkg/service/cluster_test.go @@ -2,11 +2,14 @@ package service import ( "context" + "encoding/json" "fmt" "net/http" "os" + "path" "strings" "testing" + "time" "github.com/AlekSi/pointer" "github.com/labstack/echo/v4" @@ -14,7 +17,9 @@ import ( synv1alpha1 "github.com/projectsyn/lieutenant-operator/api/v1alpha1" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/controller-runtime/pkg/client" "github.com/projectsyn/lieutenant-api/pkg/api" ) @@ -666,6 +671,117 @@ func TestClusterPutCreateNameMissmatch(t *testing.T) { require.NotNil(t, clusterObj) } +func TestClusterPostCompileMeta(t *testing.T) { + e, c := setupTest(t) + cluster := &synv1alpha1.Cluster{ + ObjectMeta: metav1.ObjectMeta{ + Name: "c-compile-meta", + Namespace: "default", + }, + } + require.NoError(t, c.Create(context.Background(), cluster)) + + compileOutput := map[string]any{ + "commodoreBuildInfo": map[string]any{ + "version": "1.0.0", + }, + "lastCompile": time.Date(2024, time.April, 14, 21, 5, 56, 0, time.UTC).Format(time.RFC3339), + "global": map[string]any{ + "gitSha": "68e5722a883f3044e287afe810ded53023175a32", + "url": "example.com/global.git", + "version": "master", + }, + "tenant": map[string]any{ + "gitSha": "c12b5847133adc2a62e484bfa5da34e1c09d4baf", + "url": "example.com/tenant.git", + "version": "master", + }, + "instances": map[string]any{ + "operations-operator-dev": map[string]any{ + "component": "operations-operator", + "gitSha": "cb0b6e77e8a213c614716155efc2de929a200ec0", + "url": "example.com/operations-operator.git", + "version": "v0.1.0", + }, + }, + "packages": map[string]any{ + "app1": map[string]any{ + "gitSha": "3ab3bf74860045601645a37c170dfe04fe7eddd8", + "url": "example.com/app1.git", + "version": "develop", + "path": "packages/main", + }, + }, + } + + result := testutil.NewRequest(). + Post("/"+path.Join("clusters", cluster.Name, "compileMeta")). + WithJsonBody(compileOutput). + WithHeader(echo.HeaderAuthorization, bearerToken). + GoWithHTTPHandler(t, e) + requireHTTPCode(t, http.StatusNoContent, result) + + require.NoError(t, c.Get(context.Background(), client.ObjectKeyFromObject(cluster), cluster)) + requireJSONMatch(t, compileOutput, cluster.Status.CompileMeta) +} + +func TestClusterPostCompileMeta_OverridesExisting_NoMerge(t *testing.T) { + e, c := setupTest(t) + cluster := &synv1alpha1.Cluster{ + ObjectMeta: metav1.ObjectMeta{ + Name: "c-compile-meta", + Namespace: "default", + }, + Status: synv1alpha1.ClusterStatus{ + CompileMeta: synv1alpha1.CompileMeta{ + CommodoreBuildInfo: map[string]string{ + "version": "6.6.6", + "otherkey": "othervalue", + }, + Instances: map[string]synv1alpha1.CompileMetaInstanceVersionInfo{ + "operations-operator-dev": { + Component: "operations-operator", + }, + }, + }, + }, + } + require.NoError(t, c.Create(context.Background(), cluster)) + + compileOutput := map[string]any{ + "commodoreBuildInfo": map[string]any{ + "version": "7.0.0", + }, + "instances": map[string]any{ + "operations-operator-prod": map[string]any{ + "component": "operations-operator", + }, + }, + } + + result := testutil.NewRequest(). + Post("/"+path.Join("clusters", cluster.Name, "compileMeta")). + WithJsonBody(compileOutput). + WithHeader(echo.HeaderAuthorization, bearerToken). + GoWithHTTPHandler(t, e) + requireHTTPCode(t, http.StatusNoContent, result) + + require.NoError(t, c.Get(context.Background(), client.ObjectKeyFromObject(cluster), cluster)) + require.NotContains(t, cluster.Status.CompileMeta.CommodoreBuildInfo, "otherkey") + require.NotContains(t, cluster.Status.CompileMeta.Instances, "operations-operator-dev") + require.Contains(t, cluster.Status.CompileMeta.Instances, "operations-operator-prod") +} + +// requireJSONMatch checks if the JSON representation of two objects are equal. +func requireJSONMatch(t *testing.T, expected, actual any) { + t.Helper() + expectedJSON, err := json.Marshal(expected) + require.NoError(t, err) + actualJSON, err := json.Marshal(actual) + require.NoError(t, err) + require.JSONEq(t, string(expectedJSON), string(actualJSON)) +} + // requireHTTPCode is a helper function to check the HTTP status code of a response and log the response body if the code is not as expected. func requireHTTPCode(t *testing.T, expected int, result *testutil.CompletedRequest) { t.Helper()