GoogleCloudPlatform / k8s-config-connector

GCP Config Connector, a Kubernetes add-on for managing GCP resources
https://cloud.google.com/config-connector/docs/overview
Apache License 2.0
862 stars 202 forks source link

Workaround to hide output-only spec field but support it in observed state #2075

Closed maqiuyujoyce closed 1 week ago

maqiuyujoyce commented 2 weeks ago

Change description

This is a workaround for #2051 so that the output-only field spec.softDeletePolicy.EffectiveTime won't be added to CRD.

Tests you have done

go test -v -tags=integration ./pkg/controller/dynamic/ -test.run TestCreateNoChangeUpdateDelete -run-tests storagebucket -timeout 900s

Verified that the created resource doesn't have spec.softDeletePolicy.EffectiveTime field even if state-into-spec: merge is configured by default:

dynamic_controller_integration_test.go:248: created resource is &{map[apiVersion:storage.cnrm.cloud.google.com/v1beta1 kind:StorageBucket metadata:map[annotations:map[cnrm.cloud.google.com/management-conflict-prevention-policy:none cnrm.cloud.google.com/project-id:[PROJECT_ID] cnrm.cloud.google.com/state-into-spec:merge] creationTimestamp:2024-06-21T23:51:21Z finalizers:[cnrm.cloud.google.com/finalizer cnrm.cloud.google.com/deletion-defender] generation:4 labels:map[cnrm-test:true label-one:value-one managed-by-cnrm:true newkey:newval] managedFields:[map[apiVersion:storage.cnrm.cloud.google.com/v1beta1 fieldsType:FieldsV1 fieldsV1:map[f:metadata:map[f:labels:map[.:map[] f:cnrm-test:map[] f:label-one:map[] f:newkey:map[]]] f:spec:map[.:map[] f:location:map[] f:softDeletePolicy:map[.:map[] f:retentionDurationSeconds:map[]] f:versioning:map[.:map[] f:enabled:map[]]]] manager:___198TestCreateNoChangeUpdateDelete_in_github_com_GoogleCloudPlatform_k8s_config_connector_pkg_controller_dynamic.test operation:Update time:2024-06-21T23:58:13Z] map[apiVersion:storage.cnrm.cloud.google.com/v1beta1 fieldsType:FieldsV1 fieldsV1:map[f:metadata:map[f:annotations:map[f:cnrm.cloud.google.com/state-into-spec:map[]] f:finalizers:map[.:map[] v:"cnrm.cloud.google.com/deletion-defender":map[] v:"cnrm.cloud.google.com/finalizer":map[]]] f:spec:map[f:publicAccessPrevention:map[] f:resourceID:map[] f:storageClass:map[]] f:status:map[.:map[] f:conditions:map[] f:observedGeneration:map[] f:observedState:map[.:map[] f:softDeletePolicy:map[.:map[] f:effectiveTime:map[] f:retentionDurationSeconds:map[]]] f:selfLink:map[] f:url:map[]]] manager:cnrm-controller-manager operation:Update time:2024-06-22T00:16:40Z]] name:storagebucket-sample-7lyh7jdpfbs5usazbgdq namespace:7lyh7jdpfbs5usazbgdq resourceVersion:1555 uid:dd773a67-40f3-45c7-85f0-79ebf814ac14] spec:map[location:US publicAccessPrevention:inherited resourceID:storagebucket-sample-7lyh7jdpfbs5usazbgdq softDeletePolicy:map[retentionDurationSeconds:6000000] storageClass:STANDARD versioning:map[enabled:true]] status:map[conditions:[map[lastTransitionTime:2024-06-22T00:16:40Z message:The resource is up to date reason:UpToDate status:True type:Ready]] observedGeneration:4 observedState:map[softDeletePolicy:map[effectiveTime:2024-06-22T00:16:10.816Z retentionDurationSeconds:6000000]] selfLink:https://www.googleapis.com/storage/v1/b/storagebucket-sample-7lyh7jdpfbs5usazbgdq url:gs://storagebucket-sample-7lyh7jdpfbs5usazbgdq]]}

maqiuyujoyce commented 2 weeks ago

@yuwenma just a heads up that #2051 should not be released unless this PR is merged.

yuwenma commented 1 week ago

The API, CRD and golden log looks good to me. @gemmahou Could you take another eye on the krm2tf code part?

gemmahou commented 1 week ago

Looks good to me! /lgtm /approve

google-oss-prow[bot] commented 1 week ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gemmahou

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files: - ~~[OWNERS](https://github.com/GoogleCloudPlatform/k8s-config-connector/blob/master/OWNERS)~~ [gemmahou] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment