From c86273e4586d566fc8c2cf98d8f3c322808a7b5e Mon Sep 17 00:00:00 2001 From: Nikhil Bhoyar Date: Wed, 23 Oct 2024 08:09:41 +0530 Subject: [PATCH] Addressing review comments - 4 --- apis/kms/v1alpha1/autokeyconfig_reference.go | 5 ++--- apis/kms/v1alpha1/kmsautokeyconfig_types.go | 6 +++--- apis/kms/v1alpha1/zz_generated.deepcopy.go | 4 ++-- .../direct/kms/autokeyconfig/autokeyconfig_controller.go | 6 +++--- pkg/controller/direct/kms/autokeyconfig/mapper.generated.go | 2 +- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/apis/kms/v1alpha1/autokeyconfig_reference.go b/apis/kms/v1alpha1/autokeyconfig_reference.go index 522b128575..318653fd76 100644 --- a/apis/kms/v1alpha1/autokeyconfig_reference.go +++ b/apis/kms/v1alpha1/autokeyconfig_reference.go @@ -33,7 +33,7 @@ var _ refsv1beta1.ExternalNormalizer = &KMSAutokeyConfigRef{} // holds the GCP identifier for the KRM object. type KMSAutokeyConfigRef struct { // A reference to an externally managed KMSAutokeyConfig resource. - // Should be in the format "projects//locations//autokeyconfigs/". + // Should be in the format "folders//autokeyConfig". External string `json:"external,omitempty"` // The name of a KMSAutokeyConfig resource. @@ -136,7 +136,6 @@ func (r *KMSAutokeyConfigRef) Parent() (*KMSAutokeyConfigParent, error) { type KMSAutokeyConfigParent struct { FolderID string - Location string } func (p *KMSAutokeyConfigParent) String() string { @@ -151,7 +150,7 @@ func ParseKMSAutokeyConfigExternal(external string) (parent *KMSAutokeyConfigPar external = strings.TrimPrefix(external, "/") tokens := strings.Split(external, "/") if len(tokens) != 3 || tokens[0] != "folders" || tokens[2] != "autokeyConfig" { - return nil, fmt.Errorf("format of KMSAutokeyConfig external=%q was not known (use projects//locations//autokeyconfigs/)", external) + return nil, fmt.Errorf("format of KMSAutokeyConfig external=%q was not known (use folders//autokeyConfig)", external) } parent = &KMSAutokeyConfigParent{ FolderID: tokens[1], diff --git a/apis/kms/v1alpha1/kmsautokeyconfig_types.go b/apis/kms/v1alpha1/kmsautokeyconfig_types.go index 6d767c8437..47a49d7a83 100644 --- a/apis/kms/v1alpha1/kmsautokeyconfig_types.go +++ b/apis/kms/v1alpha1/kmsautokeyconfig_types.go @@ -33,10 +33,11 @@ type KMSAutokeyConfigSpec struct { // NOTE: ResourceID field is not required for AutokeyConfig as its ID has the format folders//autokeyConfig i.e., it doesnt have any unique ID of its own and relies on folderID for uniqueness. // Immutable. The folder that this resource belongs to. + // +required FolderRef *refs.FolderRef `json:"folderRef"` // +optional - KeyProject *refs.ProjectRef `json:"keyProject,omitempty"` + KeyProjectRef *refs.ProjectRef `json:"keyProject,omitempty"` } // KMSAutokeyConfigStatus defines the config connector machine state of KMSAutokeyConfig @@ -47,8 +48,6 @@ type KMSAutokeyConfigStatus struct { // ObservedGeneration is the generation of the resource that was most recently observed by the Config Connector controller. If this is equal to metadata.generation, then that means that the current reported status reflects the most recent desired state of the resource. ObservedGeneration *int64 `json:"observedGeneration,omitempty"` - //KeyProject *refs.ProjectRef `json:"projectRef,omitempty"` - //State *string `json:"state,omitempty"` // A unique specifier for the KMSAutokeyConfig resource in GCP. ExternalRef *string `json:"externalRef,omitempty"` @@ -67,6 +66,7 @@ type KMSAutokeyConfigObservedState struct { // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +kubebuilder:resource:categories=gcp,shortName=gcpkmsautokeyconfig;gcpkmsautokeyconfigs // +kubebuilder:resource:categories=gcp // +kubebuilder:subresource:status // +kubebuilder:metadata:labels="cnrm.cloud.google.com/managed-by-kcc=true";"cnrm.cloud.google.com/system=true" diff --git a/apis/kms/v1alpha1/zz_generated.deepcopy.go b/apis/kms/v1alpha1/zz_generated.deepcopy.go index 50807dc863..7089af9da9 100644 --- a/apis/kms/v1alpha1/zz_generated.deepcopy.go +++ b/apis/kms/v1alpha1/zz_generated.deepcopy.go @@ -176,8 +176,8 @@ func (in *KMSAutokeyConfigSpec) DeepCopyInto(out *KMSAutokeyConfigSpec) { *out = new(v1beta1.FolderRef) **out = **in } - if in.KeyProject != nil { - in, out := &in.KeyProject, &out.KeyProject + if in.KeyProjectRef != nil { + in, out := &in.KeyProjectRef, &out.KeyProjectRef *out = new(v1beta1.ProjectRef) **out = **in } diff --git a/pkg/controller/direct/kms/autokeyconfig/autokeyconfig_controller.go b/pkg/controller/direct/kms/autokeyconfig/autokeyconfig_controller.go index 8f4238a046..ff340e5e13 100644 --- a/pkg/controller/direct/kms/autokeyconfig/autokeyconfig_controller.go +++ b/pkg/controller/direct/kms/autokeyconfig/autokeyconfig_controller.go @@ -82,9 +82,9 @@ func (m *model) AdapterForObject(ctx context.Context, reader client.Reader, u *u return nil, fmt.Errorf("unable to resolve folder for autokeyConfig name: %s", obj.GetName()) } var keyProject *refs.Project - if obj.Spec.KeyProject != nil { + if obj.Spec.KeyProjectRef != nil { var err error - keyProject, err = refs.ResolveProject(ctx, reader, obj, obj.Spec.KeyProject) + keyProject, err = refs.ResolveProject(ctx, reader, obj, obj.Spec.KeyProjectRef) if err != nil { return nil, fmt.Errorf("unable to resolve key project for autokeyConfig naem: %s", obj.GetName()) } @@ -221,7 +221,7 @@ func (a *Adapter) Export(ctx context.Context) (*unstructured.Unstructured, error // Delete implements the Adapter interface. // Note: Delete operation is not supported for GCP AutokeyConfig resource. // However in KCC, the user has full flexibility to delete the KCC AutokeyConfig resource. -// To make this KKCC operation effective, as part of KCC AutokeyConfig deletion we will update the AutokeyConfig resource in GCP with empty key_project which will prevent further use of AutokeyConfig. +// To make this KCC operation effective, as part of KCC AutokeyConfig deletion we will update the AutokeyConfig resource in GCP with empty key_project which will prevent further use of AutokeyConfig. // Because of the above decision we will update the observedstate for AutokeyConfig with state = UNINITIALIZED func (a *Adapter) Delete(ctx context.Context, deleteOp *directbase.DeleteOperation) (bool, error) { log := klog.FromContext(ctx).WithName(ctrlName) diff --git a/pkg/controller/direct/kms/autokeyconfig/mapper.generated.go b/pkg/controller/direct/kms/autokeyconfig/mapper.generated.go index 29cfdce6ab..63fb1b3129 100644 --- a/pkg/controller/direct/kms/autokeyconfig/mapper.generated.go +++ b/pkg/controller/direct/kms/autokeyconfig/mapper.generated.go @@ -69,7 +69,7 @@ func KMSAutokeyConfigSpec_FromProto(mapCtx *direct.MapContext, in *pb.AutokeyCon External: parent.String(), } if in.GetKeyProject() != "" { - out.KeyProject = &refs.ProjectRef{ + out.KeyProjectRef = &refs.ProjectRef{ External: in.GetKeyProject(), } }