From 242031426876b30c8305cdf06addc83cd7c56d71 Mon Sep 17 00:00:00 2001 From: Rashmi Gottipati Date: Tue, 20 Jun 2023 15:21:09 -0400 Subject: [PATCH] Fix e2e and lint errors Signed-off-by: Rashmi Gottipati --- api/core/v1alpha1/catalogmetadata_types.go | 10 +++++----- config/default/manager_auth_proxy_patch.yaml | 2 +- pkg/controllers/core/catalog_controller.go | 9 ++++++--- pkg/features/features.go | 2 +- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/api/core/v1alpha1/catalogmetadata_types.go b/api/core/v1alpha1/catalogmetadata_types.go index bbc4ce6d..457b9ba9 100644 --- a/api/core/v1alpha1/catalogmetadata_types.go +++ b/api/core/v1alpha1/catalogmetadata_types.go @@ -19,7 +19,7 @@ package v1alpha1 import ( "encoding/json" - v1 "k8s.io/api/core/v1" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -29,10 +29,10 @@ import ( // The `CatalogMetadataSpec` is an extension of the `Meta` schema that additionally contains a `Catalog` field which references the Catalog and a `Content` field // which is a JSON representation of the File-Based Catalog blob. type CatalogMetadataSpec struct { - Catalog v1.LocalObjectReference `json:"catalog"` - Schema string `json:"schema"` - Package string `json:"package,omitempty"` - Name string `json:"name,omitempty"` + Catalog corev1.LocalObjectReference `json:"catalog"` + Schema string `json:"schema"` + Package string `json:"package,omitempty"` + Name string `json:"name,omitempty"` // +kubebuilder:validation:Schemaless // +kubebuilder:pruning:PreserveUnknownFields // +kubebuilder:validation:Type=object diff --git a/config/default/manager_auth_proxy_patch.yaml b/config/default/manager_auth_proxy_patch.yaml index e0eea713..b9cd89f7 100644 --- a/config/default/manager_auth_proxy_patch.yaml +++ b/config/default/manager_auth_proxy_patch.yaml @@ -53,5 +53,5 @@ spec: - "--health-probe-bind-address=:8081" - "--metrics-bind-address=127.0.0.1:8080" - "--leader-elect" - - --feature-gates="PackagesBundleMetadataAPIs=true" + - "--feature-gates=PackagesBundleMetadataAPIs=true" diff --git a/pkg/controllers/core/catalog_controller.go b/pkg/controllers/core/catalog_controller.go index e35d301c..2958bf7f 100644 --- a/pkg/controllers/core/catalog_controller.go +++ b/pkg/controllers/core/catalog_controller.go @@ -18,6 +18,7 @@ package core import ( "context" + // #nosec "crypto/sha1" "encoding/hex" "encoding/json" @@ -447,10 +448,11 @@ func (r *CatalogReconciler) syncCatalogMetadata(ctx context.Context, fsys fs.FS, if err := r.List(ctx, &existingCatalogMetadataObjs); err != nil { return fmt.Errorf("list existing catalog metadata: %v", err) } - for _, existingCatalogMetadata := range existingCatalogMetadataObjs.Items { + for i, existingCatalogMetadata := range existingCatalogMetadataObjs.Items { if _, ok := newCatalogMetadataObjs[existingCatalogMetadata.Name]; !ok { // delete existing catalog metadata - if err := r.Delete(ctx, &existingCatalogMetadata); err != nil { + err := r.Delete(ctx, &existingCatalogMetadataObjs.Items[i]) + if err != nil { return fmt.Errorf("delete existing catalog metadata %q: %v", existingCatalogMetadata.Name, err) } } @@ -472,7 +474,7 @@ func (r *CatalogReconciler) syncCatalogMetadata(ctx context.Context, fsys fs.FS, // In the place of the empty `meta.Name`, it computes a hash of `meta.Blob` to prevent multiple FBC blobs colliding on the the object name. // Possible outcomes are: "{catalogName}-{meta.Schema}-{meta.Name}", "{catalogName}-{meta.Schema}-{meta.Package}-{meta.Name}", // "{catalogName}-{meta.Schema}-{hash{meta.Blob}}", "{catalogName}-{meta.Schema}-{meta.Package}-{hash{meta.Blob}}". -func generateCatalogMetadataName(ctx context.Context, catalogName string, meta *declcfg.Meta) (string, error) { +func generateCatalogMetadataName(_ context.Context, catalogName string, meta *declcfg.Meta) (string, error) { objName := fmt.Sprintf("%s-%s", catalogName, meta.Schema) if meta.Package != "" { objName = fmt.Sprintf("%s-%s", objName, meta.Package) @@ -484,6 +486,7 @@ func generateCatalogMetadataName(ctx context.Context, catalogName string, meta * if err != nil { return "", fmt.Errorf("JSON marshal error: %v", err) } + // #nosec h := sha1.New() h.Write(metaJSON) objName = fmt.Sprintf("%s-%s", objName, hex.EncodeToString(h.Sum(nil))) diff --git a/pkg/features/features.go b/pkg/features/features.go index 3f53ef99..c5ded7db 100644 --- a/pkg/features/features.go +++ b/pkg/features/features.go @@ -17,7 +17,7 @@ var catalogdFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{ // Add new feature gate definitions // Ex: SomeFeature: {...} - PackagesBundleMetadataAPIs: {Default: false, PreRelease: featuregate.Alpha}, + PackagesBundleMetadataAPIs: {Default: false, PreRelease: featuregate.Deprecated}, CatalogMetadataAPI: {Default: false, PreRelease: featuregate.Alpha}, }