From bb052e4ae2577d48d8f1dd169a8c64bee0edcbea Mon Sep 17 00:00:00 2001 From: Sebastian Widmer Date: Mon, 27 May 2024 16:20:17 +0200 Subject: [PATCH] Remove required attribute from tenant.Id and cluster.Id The codegen does now correctly detect required attributes and fails if no id is present. Ids are not required for `create` and set with the URL parameters for all other requsts. --- openapi.yaml | 4 -- pkg/api/openapi.go | 126 ++++++++++++++++++------------------ pkg/api/openapi_custom.go | 7 +- pkg/api/utils.go | 28 ++++---- pkg/api/utils_test.go | 7 +- pkg/service/cluster.go | 5 +- pkg/service/cluster_test.go | 21 +++--- pkg/service/tenant.go | 3 +- pkg/service/tenant_test.go | 15 +++-- 9 files changed, 112 insertions(+), 104 deletions(-) diff --git a/openapi.yaml b/openapi.yaml index 9276854..20d2596 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -78,8 +78,6 @@ components: example: v1.2.3 TenantId: type: object - required: - - id properties: id: $ref: '#/components/schemas/Id' @@ -138,8 +136,6 @@ components: - $ref: '#/components/schemas/ClusterProperties' ClusterId: type: object - required: - - id properties: id: $ref: '#/components/schemas/Id' diff --git a/pkg/api/openapi.go b/pkg/api/openapi.go index fac8481..4bfe408 100644 --- a/pkg/api/openapi.go +++ b/pkg/api/openapi.go @@ -51,7 +51,7 @@ type ClusterFacts map[string]interface{} // ClusterId defines model for ClusterId. type ClusterId struct { // Id A unique object identifier string. Automatically generated by the API on creation (in the form "---" where all letters are lowercase, max 63 characters in total). - Id Id `json:"id"` + Id *Id `json:"id,omitempty"` } // ClusterProperties A cluster defition object. @@ -161,7 +161,7 @@ type Tenant struct { // TenantId defines model for TenantId. type TenantId struct { // Id A unique object identifier string. Automatically generated by the API on creation (in the form "---" where all letters are lowercase, max 63 characters in total). - Id Id `json:"id"` + Id *Id `json:"id,omitempty"` } // TenantProperties A tenant definition object. @@ -3278,67 +3278,67 @@ var swaggerSpec = []string{ "HpgwwkYIiwFRAospCkHhACvs1Ty4w2FEQcMMOSOKC8JGDTllDcU5lU1Jsbft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xnvPkUMSpR4yVxL5Wn41bFW7vcJ8wz9UQw6dSi/zAtnwM8+RkvwrjpF", + "c+efeIiWKkPJieQiWvN78rvgFQdo8zZqzIHUBn6sy1n+tfNq07N+slD4zMOzPN6nm53Nl98PTs7miOwA", + "1FPKa+0ZnJ8TxLKhmYuJv3dmtkicSydmc0RoDzyyFJ92XFZeSZ47b8iL7e82LFuqk88+KivgfaJJ2UId", + "XnlONkeZT2P1GzT5scReMSNbORv7PWr5/ykL/GcYYLUVldO7YsejuKf+5VLbhv0lZ1Vv9Ij7mKIAJkB5", + "FILBYDe/m155dza/WZ7bNz4VPIh9kxvZpkdxd7z0U/zVIXeZgpFb/p8Duk6Y+lnw+zCZCzaAySzYy5T7", + "s/Bza/aFgr64p1ymq/hdbuG1+H8Yqvgy6fwX2+zph8XH8z/POoSKhOBGs65Z6EBlvcIyGF1bu85Ztiht", + "/364fPi/AAAA//+2KOvJk0kAAA==", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/pkg/api/openapi_custom.go b/pkg/api/openapi_custom.go index d45007f..549a5be 100644 --- a/pkg/api/openapi_custom.go +++ b/pkg/api/openapi_custom.go @@ -1,6 +1,9 @@ package api // String returns the underlying string value of `Id`. -func (id Id) String() string { - return string(id) +func (id *Id) String() string { + if id == nil { + return "" + } + return string(*id) } diff --git a/pkg/api/utils.go b/pkg/api/utils.go index 007d36f..8fd1f51 100644 --- a/pkg/api/utils.go +++ b/pkg/api/utils.go @@ -31,7 +31,7 @@ var ( func GenerateClusterID() (ClusterId, error) { id, err := generateID(ClusterIDPrefix) return ClusterId{ - Id: id, + Id: &id, }, err } @@ -39,7 +39,7 @@ func GenerateClusterID() (ClusterId, error) { func GenerateTenantID() (TenantId, error) { id, err := generateID(TenantIDPrefix) return TenantId{ - Id: id, + Id: &id, }, err } @@ -60,8 +60,9 @@ func generateID(prefix string) (Id, error) { // NewAPITenantFromCRD transforms a CRD tenant into the API representation func NewAPITenantFromCRD(tenant synv1alpha1.Tenant) *Tenant { + id := Id(tenant.Name) apiTenant := &Tenant{ - TenantId: TenantId{Id: Id(tenant.Name)}, + TenantId: TenantId{Id: &id}, TenantProperties: TenantProperties{ GitRepo: &RevisionedGitRepo{}, }, @@ -107,14 +108,15 @@ func NewAPITenantFromCRD(tenant synv1alpha1.Tenant) *Tenant { // NewCRDFromAPITenant transforms an API tenant into the CRD representation func NewCRDFromAPITenant(apiTenant Tenant) (*synv1alpha1.Tenant, error) { if !strings.HasPrefix(apiTenant.Id.String(), TenantIDPrefix) { - if apiTenant.Id == "" { + if apiTenant.Id.String() == "" { id, err := GenerateTenantID() if err != nil { return nil, err } apiTenant.TenantId = id } else { - apiTenant.Id = TenantIDPrefix + apiTenant.Id + id := TenantIDPrefix + *apiTenant.Id + apiTenant.Id = &id } } if apiTenant.GitRepo == nil || @@ -131,7 +133,7 @@ func NewCRDFromAPITenant(apiTenant Tenant) (*synv1alpha1.Tenant, error) { } if apiTenant.GitRepo != nil { - tmpl, err := newGitRepoTemplate(&apiTenant.GitRepo.GitRepo, string(apiTenant.Id)) + tmpl, err := newGitRepoTemplate(&apiTenant.GitRepo.GitRepo, apiTenant.Id.String()) if err != nil { return nil, fmt.Errorf("failed to create git repo template: %w", err) } @@ -179,8 +181,9 @@ func SyncCRDFromAPITenant(source TenantProperties, target *synv1alpha1.Tenant) { // NewAPIClusterFromCRD transforms a CRD cluster into the API representation func NewAPIClusterFromCRD(cluster synv1alpha1.Cluster) *Cluster { + id := Id(cluster.Name) apiCluster := &Cluster{ - ClusterId: ClusterId{Id: Id(cluster.Name)}, + ClusterId: ClusterId{Id: &id}, ClusterProperties: ClusterProperties{ GitRepo: &GitRepo{}, }, @@ -257,20 +260,21 @@ func unmarshalFact(fact string) interface{} { // NewCRDFromAPICluster transforms an API cluster into the CRD representation func NewCRDFromAPICluster(apiCluster Cluster) (*synv1alpha1.Cluster, error) { - if !strings.HasPrefix(string(apiCluster.Id), ClusterIDPrefix) { - if apiCluster.Id == "" { + if !strings.HasPrefix(apiCluster.Id.String(), ClusterIDPrefix) { + if apiCluster.Id.String() == "" { id, err := GenerateClusterID() if err != nil { return nil, err } apiCluster.ClusterId = id } else { - apiCluster.Id = ClusterIDPrefix + apiCluster.Id + id := Id(ClusterIDPrefix + apiCluster.Id.String()) + apiCluster.Id = &id } } cluster := &synv1alpha1.Cluster{ ObjectMeta: metav1.ObjectMeta{ - Name: string(apiCluster.ClusterId.Id), + Name: apiCluster.Id.String(), Annotations: map[string]string{}, }, Spec: synv1alpha1.ClusterSpec{ @@ -280,7 +284,7 @@ func NewCRDFromAPICluster(apiCluster Cluster) (*synv1alpha1.Cluster, error) { }, } - tmpl, err := newGitRepoTemplate(apiCluster.GitRepo, string(apiCluster.Id)) + tmpl, err := newGitRepoTemplate(apiCluster.GitRepo, apiCluster.Id.String()) if err != nil { return nil, fmt.Errorf("failed to create git repo template: %w", err) } diff --git a/pkg/api/utils_test.go b/pkg/api/utils_test.go index 4c58ffc..1f863f5 100644 --- a/pkg/api/utils_test.go +++ b/pkg/api/utils_test.go @@ -80,7 +80,7 @@ func TestGenerateClusterID(t *testing.T) { assertGeneratedID(t, ClusterIDPrefix, func() (s string) { id, err := GenerateClusterID() require.NoError(t, err) - return string(id.Id) + return id.Id.String() }) } @@ -168,9 +168,10 @@ var tenantTests = map[string]struct { func TestNewCRDFromAPITenant(t *testing.T) { for name, test := range tenantTests { t.Run(name, func(t *testing.T) { + id := Id(fmt.Sprintf("t-%s", t.Name())) apiTenant := Tenant{ TenantId{ - Id: Id(fmt.Sprintf("t-%s", t.Name())), + Id: &id, }, test.properties, } @@ -234,7 +235,7 @@ func TestNewCRDFromAPICluster(t *testing.T) { t.Run(name, func(t *testing.T) { apiCluster := Cluster{ ClusterId{ - Id: Id(fmt.Sprintf("c-%s", t.Name())), + Id: pointer.To(Id(fmt.Sprintf("c-%s", t.Name()))), }, ClusterTenant{fmt.Sprintf("t-%s", t.Name())}, test.properties, diff --git a/pkg/service/cluster.go b/pkg/service/cluster.go index d1e6bda..f52b635 100644 --- a/pkg/service/cluster.go +++ b/pkg/service/cluster.go @@ -7,6 +7,7 @@ import ( "os" "sort" + "github.com/AlekSi/pointer" "github.com/labstack/echo/v4" synv1alpha1 "github.com/projectsyn/lieutenant-operator/api/v1alpha1" "k8s.io/apimachinery/pkg/api/errors" @@ -70,7 +71,7 @@ func sortClustersBy(clusters []api.Cluster, by *api.ListClustersParamsSortBy) { return di < dj default: - return clusters[i].Id < clusters[j].Id + return clusters[i].Id.String() < clusters[j].Id.String() } }) } @@ -188,7 +189,7 @@ func (s *APIImpl) PutCluster(c echo.Context, clusterID api.ClusterIdParameter) e return echo.NewHTTPError(http.StatusBadRequest, err) } apiCluster := api.Cluster(*body) - apiCluster.Id = api.Id(clusterID) + apiCluster.Id = pointer.To(api.Id(clusterID)) cluster, err := api.NewCRDFromAPICluster(apiCluster) if err != nil { diff --git a/pkg/service/cluster_test.go b/pkg/service/cluster_test.go index 9ce7ebe..8fd73bf 100644 --- a/pkg/service/cluster_test.go +++ b/pkg/service/cluster_test.go @@ -104,7 +104,7 @@ func TestListCluster_Sort(t *testing.T) { assert.NoError(t, err) assert.Len(t, clusters, 3) for i := range tc.order { - assert.Equal(t, tc.order[i], string(clusters[i].Id)) + assert.Equal(t, tc.order[i], clusters[i].Id.String()) } }) } @@ -165,7 +165,7 @@ func TestCreateCluster(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, cluster) - assert.Contains(t, cluster.Id, api.ClusterIDPrefix) + assert.Contains(t, cluster.Id.String(), api.ClusterIDPrefix) assert.Equal(t, cluster.DisplayName, newCluster.DisplayName) assert.Equal(t, newCluster.Facts, cluster.Facts) assert.Equal(t, newCluster.DynamicFacts, cluster.DynamicFacts) @@ -194,7 +194,7 @@ func TestCreateClusterWithId(t *testing.T) { request := api.Cluster{ ClusterId: api.ClusterId{ - Id: tt.request, + Id: pointer.To(tt.request), }, ClusterProperties: api.ClusterProperties{ DisplayName: pointer.ToString("My test cluster"), @@ -210,7 +210,7 @@ func TestCreateClusterWithId(t *testing.T) { cluster := &api.Cluster{} err := result.UnmarshalJsonToObject(cluster) assert.NoError(t, err) - assert.Equal(t, tt.response, cluster.Id) + assert.Equal(t, tt.response.String(), cluster.Id.String()) }) } } @@ -280,6 +280,7 @@ func TestCreateClusterNoTenant(t *testing.T) { e, _ := setupTest(t) createCluster := map[string]string{ + "id": "c-1234", "displayName": "cluster-name", } result := testutil.NewRequest(). @@ -331,7 +332,7 @@ func TestClusterGet(t *testing.T) { err := result.UnmarshalJsonToObject(cluster) assert.NoError(t, err) assert.NotNil(t, cluster) - assert.Equal(t, clusterA.Name, string(cluster.ClusterId.Id)) + assert.Equal(t, clusterA.Name, cluster.Id.String()) assert.Equal(t, tenantA.Name, cluster.Tenant) assert.Equal(t, clusterA.Spec.GitHostKeys, *cluster.GitRepo.HostKeys) assert.True(t, strings.HasSuffix(*cluster.InstallURL, clusterA.Status.BootstrapToken.Token)) @@ -350,7 +351,7 @@ func TestClusterGetNoToken(t *testing.T) { err := result.UnmarshalJsonToObject(cluster) assert.NoError(t, err) assert.NotNil(t, cluster) - assert.Equal(t, clusterB.Name, string(cluster.ClusterId.Id)) + assert.Equal(t, clusterB.Name, cluster.Id.String()) assert.Equal(t, tenantB.Name, cluster.Tenant) assert.Nil(t, cluster.InstallURL) } @@ -504,7 +505,7 @@ func TestClusterUpdate(t *testing.T) { err := result.UnmarshalJsonToObject(cluster) require.NoError(t, err) assert.NotNil(t, cluster) - assert.Equal(t, clusterB.Name, string(cluster.Id)) + assert.Equal(t, clusterB.Name, cluster.Id.String()) assert.Equal(t, newDisplayName, *cluster.DisplayName) assert.Equal(t, *updateCluster.GitRepo.DeployKey, *cluster.GitRepo.DeployKey) assert.Empty(t, (*cluster.Annotations)["existing"]) @@ -576,7 +577,7 @@ var putClusterTestCases = map[string]struct { "put new object": { cluster: &api.Cluster{ ClusterId: api.ClusterId{ - Id: "c-new-2379", + Id: pointer.To(api.Id("c-new-2379")), }, ClusterProperties: api.ClusterProperties{ DisplayName: pointer.ToString("My new cluster"), @@ -596,7 +597,7 @@ var putClusterTestCases = map[string]struct { }, code: http.StatusCreated, valid: func(t *testing.T, act *api.Cluster) bool { - assert.Contains(t, act.Id, api.ClusterIDPrefix) + assert.Contains(t, act.Id.String(), api.ClusterIDPrefix) assert.Equal(t, pointer.ToString("My new cluster"), act.DisplayName) return true }, @@ -637,7 +638,7 @@ func TestClusterPutCreateNameMissmatch(t *testing.T) { e, client := setupTest(t) cluster := &api.Cluster{ ClusterId: api.ClusterId{ - Id: "c-bar", + Id: pointer.To(api.Id("c-new-2379")), }, ClusterProperties: api.ClusterProperties{ DisplayName: pointer.ToString("My new cluster"), diff --git a/pkg/service/tenant.go b/pkg/service/tenant.go index 9df0e23..09ab681 100644 --- a/pkg/service/tenant.go +++ b/pkg/service/tenant.go @@ -5,6 +5,7 @@ import ( "net/http" "os" + "github.com/AlekSi/pointer" "github.com/labstack/echo/v4" synv1alpha1 "github.com/projectsyn/lieutenant-operator/api/v1alpha1" "k8s.io/apimachinery/pkg/api/errors" @@ -128,7 +129,7 @@ func (s *APIImpl) PutTenant(c echo.Context, tenantID api.TenantIdParameter) erro return echo.NewHTTPError(http.StatusBadRequest, err) } apiTenant := api.Tenant(*newTenant) - apiTenant.Id = api.Id(tenantID) + apiTenant.Id = pointer.To(api.Id(tenantID)) tenant, err := api.NewCRDFromAPITenant(apiTenant) if err != nil { diff --git a/pkg/service/tenant_test.go b/pkg/service/tenant_test.go index 94436de..1487745 100644 --- a/pkg/service/tenant_test.go +++ b/pkg/service/tenant_test.go @@ -63,7 +63,7 @@ func TestCreateTenant(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, tenant) assert.NotNil(t, tenant.GitRepo) - assert.Contains(t, tenant.Id, api.TenantIDPrefix) + assert.Contains(t, tenant.Id.String(), api.TenantIDPrefix) assert.Equal(t, newTenant.DisplayName, tenant.DisplayName) assert.Equal(t, newTenant.GitRepo.Url, tenant.GitRepo.Url) assert.NotNil(t, tenant.GitRepo.Type) @@ -73,7 +73,7 @@ func TestCreateTenant(t *testing.T) { tenantCRD := &synv1alpha1.Tenant{} err = client.Get(context.TODO(), types.NamespacedName{ - Name: string(tenant.Id), + Name: tenant.Id.String(), Namespace: "default", }, tenantCRD) assert.NoError(t, err) @@ -101,7 +101,7 @@ func TestCreateTenantWithID(t *testing.T) { requestBody := api.Tenant{ TenantId: api.TenantId{ - Id: tt.request, + Id: &tt.request, }, TenantProperties: api.TenantProperties{ DisplayName: pointer.ToString("Tenant with ID"), @@ -119,7 +119,8 @@ func TestCreateTenantWithID(t *testing.T) { assert.Equal(t, http.StatusCreated, response.Code()) tenant := &api.Tenant{} assert.NoError(t, response.UnmarshalJsonToObject(tenant)) - assert.Equal(t, tt.response, tenant.Id) + require.NotNil(t, tenant.Id) + assert.Equal(t, tt.response, *tenant.Id) }) } } @@ -195,7 +196,7 @@ func TestTenantGet(t *testing.T) { tenant := &api.Tenant{} err := result.UnmarshalJsonToObject(tenant) assert.NoError(t, err) - assert.Equal(t, tenantA.Name, string(tenant.Id)) + assert.Equal(t, tenantA.Name, tenant.Id.String()) assert.Equal(t, tenantA.Spec.DisplayName, *tenant.DisplayName) assert.Equal(t, tenantA.Spec.GitRepoURL, *tenant.GitRepo.Url) assert.Contains(t, *tenant.Annotations, "monitoring.syn.tools/sla") @@ -265,7 +266,7 @@ func TestTenantUpdate(t *testing.T) { err := result.UnmarshalJsonToObject(tenant) assert.NoError(t, err) assert.NotNil(t, tenant) - assert.Contains(t, string(tenant.Id), tenantB.Name) + assert.Contains(t, tenant.Id.String(), tenantB.Name) assert.Equal(t, newDisplayName, *tenant.DisplayName) assert.Contains(t, *tenant.Annotations, "some") assert.Len(t, *tenant.Annotations, 1) @@ -331,7 +332,7 @@ var putTenantTestCases = map[string]struct { "put new object": { tenant: &api.Tenant{ TenantId: api.TenantId{ - Id: "t-buzz-24", + Id: pointer.To(api.Id("t-buzz-24")), }, TenantProperties: api.TenantProperties{ DisplayName: pointer.ToString("My test Tenant"),