Skip to content

Commit

Permalink
Merge pull request GoogleCloudPlatform#2432 from maqiuyujoyce/202408-…
Browse files Browse the repository at this point in the history
…make-absent-default

Use 'Absent' as the default state-into-spec behavior
  • Loading branch information
google-oss-prow[bot] committed Sep 11, 2024
2 parents 598be97 + 7e4d3c3 commit e4bf65d
Show file tree
Hide file tree
Showing 134 changed files with 253 additions and 1,500 deletions.
7 changes: 5 additions & 2 deletions pkg/controller/direct/compute/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,12 @@ func ResolveComputeAddress(ctx context.Context, reader client.Reader, src client

// targetField: address
// See compute servicemappings for details
address, _, err := unstructured.NestedString(computeAddress.Object, "spec", "address")
// Because `spec.address` field is optional, we can't guarantee it always
// exists in a successfully reconciled ComputeAddress CR, so we should use
// the `status.observedState.address` instead.
address, _, err := unstructured.NestedString(computeAddress.Object, "status", "observedState", "address")
if err != nil || address == "" {
return nil, fmt.Errorf("cannot get address for referenced %s %v (spec.address is empty)", computeAddress.GetKind(), computeAddress.GetNamespace())
return nil, fmt.Errorf("cannot get address for referenced %s %v (status.observedState.address is empty)", computeAddress.GetKind(), computeAddress.GetNamespace())
}
return &refs.ComputeAddressRef{
External: address}, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/k8s/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const (
// State into spec annotation values
StateMergeIntoSpec = "merge"
StateAbsentInSpec = "absent"
StateIntoSpecDefaultValueV1Beta1 = StateMergeIntoSpec
StateIntoSpecDefaultValueV1Beta1 = StateAbsentInSpec

// Core kubernetes constants
LastAppliedConfigurationAnnotation = "kubectl.kubernetes.io/last-applied-configuration"
Expand Down
2 changes: 1 addition & 1 deletion pkg/k8s/stateintospecdefaulter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestStateIntoSpecDefaulter_ApplyDefaults(t *testing.T) {
},
},
expectChanged: true,
expectValue: "merge",
expectValue: "absent",
},
{
name: "use 'absent' if resource doesn't support 'merge'",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ kind: AlloyDBCluster
metadata:
annotations:
cnrm.cloud.google.com/management-conflict-prevention-policy: none
cnrm.cloud.google.com/mutable-but-unreadable-fields: '{"spec":{"deletionPolicy":"DEFAULT","initialUser":{"password":{"value":"postgres"},"user":"postgres"}}}'
cnrm.cloud.google.com/mutable-but-unreadable-fields: '{"spec":{"initialUser":{"password":{"value":"postgres"},"user":"postgres"}}}'
cnrm.cloud.google.com/observed-secret-versions: (removed)
cnrm.cloud.google.com/state-into-spec: merge
cnrm.cloud.google.com/state-into-spec: absent
finalizers:
- cnrm.cloud.google.com/finalizer
- cnrm.cloud.google.com/deletion-defender
generation: 3
generation: 2
labels:
cnrm-test: "true"
name: alloydbcluster-${uniqueId}
Expand All @@ -18,8 +18,6 @@ spec:
automatedBackupPolicy:
labels:
source: kcc-test
clusterType: PRIMARY
deletionPolicy: DEFAULT
initialUser:
password:
value: postgres
Expand All @@ -40,6 +38,6 @@ status:
type: Ready
databaseVersion: DATABASE_VERSION_UNSPECIFIED
name: projects/${projectId}/locations/southamerica-east1/clusters/alloydbcluster${uniqueId}
observedGeneration: 3
observedGeneration: 2
observedState:
clusterType: PRIMARY
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
cnrm.cloud.google.com/management-conflict-prevention-policy: none
cnrm.cloud.google.com/mutable-but-unreadable-fields: '{"spec":{"deletionPolicy":"FORCE"}}'
cnrm.cloud.google.com/observed-secret-versions: (removed)
cnrm.cloud.google.com/state-into-spec: merge
cnrm.cloud.google.com/state-into-spec: absent
finalizers:
- cnrm.cloud.google.com/finalizer
- cnrm.cloud.google.com/deletion-defender
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ kind: AlloyDBCluster
metadata:
annotations:
cnrm.cloud.google.com/management-conflict-prevention-policy: none
cnrm.cloud.google.com/mutable-but-unreadable-fields: '{"spec":{"deletionPolicy":"DEFAULT","initialUser":{"password":{"value":"Postgres123"},"user":"postgres"}}}'
cnrm.cloud.google.com/mutable-but-unreadable-fields: '{"spec":{"initialUser":{"password":{"value":"Postgres123"},"user":"postgres"}}}'
cnrm.cloud.google.com/observed-secret-versions: (removed)
cnrm.cloud.google.com/state-into-spec: merge
cnrm.cloud.google.com/state-into-spec: absent
finalizers:
- cnrm.cloud.google.com/finalizer
- cnrm.cloud.google.com/deletion-defender
Expand Down Expand Up @@ -38,10 +38,8 @@ spec:
minutes: 0
nanos: 0
seconds: 0
clusterType: PRIMARY
continuousBackupConfig:
enabled: false
deletionPolicy: DEFAULT
encryptionConfig:
kmsKeyNameRef:
name: kmscryptokey-${uniqueId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: AlloyDBInstance
metadata:
annotations:
cnrm.cloud.google.com/management-conflict-prevention-policy: none
cnrm.cloud.google.com/state-into-spec: merge
cnrm.cloud.google.com/state-into-spec: absent
finalizers:
- cnrm.cloud.google.com/finalizer
- cnrm.cloud.google.com/deletion-defender
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: AlloyDBInstance
metadata:
annotations:
cnrm.cloud.google.com/management-conflict-prevention-policy: none
cnrm.cloud.google.com/state-into-spec: merge
cnrm.cloud.google.com/state-into-spec: absent
finalizers:
- cnrm.cloud.google.com/finalizer
- cnrm.cloud.google.com/deletion-defender
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ kind: AlloyDBInstance
metadata:
annotations:
cnrm.cloud.google.com/management-conflict-prevention-policy: none
cnrm.cloud.google.com/state-into-spec: merge
cnrm.cloud.google.com/state-into-spec: absent
finalizers:
- cnrm.cloud.google.com/finalizer
- cnrm.cloud.google.com/deletion-defender
generation: 4
generation: 2
labels:
cnrm-test: "true"
name: alloydbinstance-${uniqueId}
namespace: ${uniqueId}
spec:
availabilityType: AVAILABILITY_TYPE_UNSPECIFIED
clusterRef:
name: alloydbcluster-${uniqueId}
databaseFlags:
Expand All @@ -24,6 +23,7 @@ spec:
machineConfig:
cpuCount: 4
networkConfig:
authorizedExternalNetworks: []
enablePublicIp: false
resourceID: alloydbinstance${uniqueId}
status:
Expand All @@ -35,5 +35,5 @@ status:
type: Ready
createTime: "1970-01-01T00:00:00Z"
name: projects/${projectId}/locations/europe-north1/clusters/alloydbcluster${uniqueId}/instances/alloydbinstance${uniqueId}
observedGeneration: 4
observedGeneration: 2
state: STATE_UNSPECIFIED
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ kind: AlloyDBInstance
metadata:
annotations:
cnrm.cloud.google.com/management-conflict-prevention-policy: none
cnrm.cloud.google.com/state-into-spec: merge
cnrm.cloud.google.com/state-into-spec: absent
finalizers:
- cnrm.cloud.google.com/finalizer
- cnrm.cloud.google.com/deletion-defender
generation: 3
generation: 2
labels:
cnrm-test: "true"
name: alloydbreadinstance-${uniqueId}
namespace: ${uniqueId}
spec:
availabilityType: AVAILABILITY_TYPE_UNSPECIFIED
clusterRef:
name: alloydbcluster-${uniqueId}
instanceTypeRef:
Expand All @@ -32,5 +31,5 @@ status:
type: Ready
createTime: "1970-01-01T00:00:00Z"
name: projects/${projectId}/locations/europe-southwest1/clusters/alloydbcluster${uniqueId}/instances/alloydbreadinstance${uniqueId}
observedGeneration: 3
observedGeneration: 2
state: STATE_UNSPECIFIED
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: AlloyDBInstance
metadata:
annotations:
cnrm.cloud.google.com/management-conflict-prevention-policy: none
cnrm.cloud.google.com/state-into-spec: merge
cnrm.cloud.google.com/state-into-spec: absent
finalizers:
- cnrm.cloud.google.com/finalizer
- cnrm.cloud.google.com/deletion-defender
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
annotations:
cnrm.cloud.google.com/management-conflict-prevention-policy: none
cnrm.cloud.google.com/project-id: ${projectId}
cnrm.cloud.google.com/state-into-spec: merge
cnrm.cloud.google.com/state-into-spec: absent
finalizers:
- cnrm.cloud.google.com/finalizer
- cnrm.cloud.google.com/deletion-defender
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: bigquery.cnrm.cloud.google.com/v1beta1
kind: BigQueryDataset
metadata:
annotations:
cnrm.cloud.google.com/management-conflict-prevention-policy: none
cnrm.cloud.google.com/state-into-spec: merge
cnrm.cloud.google.com/state-into-spec: absent
finalizers:
- cnrm.cloud.google.com/finalizer
- cnrm.cloud.google.com/deletion-defender
Expand All @@ -27,17 +13,7 @@ metadata:
name: bigquerydatasetsample${uniqueId}
namespace: ${uniqueId}
spec:
access:
- role: OWNER
specialGroup: projectOwners
- role: OWNER
userByEmail: [email protected]
- role: READER
specialGroup: projectReaders
- role: WRITER
specialGroup: projectWriters
friendlyName: bigquerydataset-sample-updated
location: US
projectRef:
external: ${projectId}
resourceID: bigquerydatasetsample${uniqueId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ kind: BigQueryDataset
metadata:
annotations:
cnrm.cloud.google.com/management-conflict-prevention-policy: none
cnrm.cloud.google.com/state-into-spec: merge
cnrm.cloud.google.com/state-into-spec: absent
finalizers:
- cnrm.cloud.google.com/finalizer
- cnrm.cloud.google.com/deletion-defender
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
annotations:
cnrm.cloud.google.com/management-conflict-prevention-policy: none
cnrm.cloud.google.com/project-id: ${projectId}
cnrm.cloud.google.com/state-into-spec: merge
cnrm.cloud.google.com/state-into-spec: absent
finalizers:
- cnrm.cloud.google.com/finalizer
- cnrm.cloud.google.com/deletion-defender
Expand All @@ -18,14 +18,12 @@ spec:
name: bigquerydatasetsample${uniqueId}
externalDataConfiguration:
autodetect: true
compression: NONE
sourceFormat: CSV
sourceUris:
- gs://gcp-public-data-landsat/LC08/01/044/034/LC08_L1GT_044034_20130330_20170310_01_T2/LC08_L1GT_044034_20130330_20170310_01_T2_ANG.txt
friendlyName: bigquerytable-sample-updated
requirePartitionFilter: false
resourceID: bigquerytablesample${uniqueId}
schema: '[{"mode":"NULLABLE","name":"string_field_0","type":"STRING"},{"mode":"NULLABLE","name":"string_field_1","type":"STRING"},{"mode":"NULLABLE","name":"string_field_2","type":"STRING"},{"mode":"NULLABLE","name":"string_field_3","type":"STRING"},{"mode":"NULLABLE","name":"string_field_4","type":"STRING"},{"mode":"NULLABLE","name":"string_field_5","type":"STRING"},{"mode":"NULLABLE","name":"int64_field_6","type":"INTEGER"},{"mode":"NULLABLE","name":"int64_field_7","type":"INTEGER"},{"mode":"NULLABLE","name":"int64_field_8","type":"INTEGER"},{"mode":"NULLABLE","name":"int64_field_9","type":"INTEGER"},{"mode":"NULLABLE","name":"string_field_10","type":"STRING"},{"mode":"NULLABLE","name":"int64_field_11","type":"INTEGER"},{"mode":"NULLABLE","name":"int64_field_12","type":"INTEGER"},{"mode":"NULLABLE","name":"string_field_13","type":"STRING"}]'
status:
conditions:
- lastTransitionTime: "1970-01-01T00:00:00Z"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
cnrm.cloud.google.com/management-conflict-prevention-policy: none
cnrm.cloud.google.com/mutable-but-unreadable-fields: '{"spec":{"instanceType":"PRODUCTION"}}'
cnrm.cloud.google.com/project-id: ${projectId}
cnrm.cloud.google.com/state-into-spec: merge
cnrm.cloud.google.com/state-into-spec: absent
finalizers:
- cnrm.cloud.google.com/finalizer
- cnrm.cloud.google.com/deletion-defender
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ metadata:
cnrm.cloud.google.com/management-conflict-prevention-policy: none
cnrm.cloud.google.com/mutable-but-unreadable-fields: '{"spec":{"instanceType":"PRODUCTION"}}'
cnrm.cloud.google.com/project-id: ${projectId}
cnrm.cloud.google.com/state-into-spec: merge
cnrm.cloud.google.com/state-into-spec: absent
finalizers:
- cnrm.cloud.google.com/finalizer
- cnrm.cloud.google.com/deletion-defender
generation: 4
generation: 3
labels:
cnrm-test: "true"
name: btinstance-${uniqueId}
Expand All @@ -20,27 +20,19 @@ spec:
cpuTarget: 70
maxNodes: 5
minNodes: 2
storageTarget: 2560
clusterId: cluster-1-${uniqueId}
numNodes: 2
storageType: SSD
zone: us-central1-a
- autoscalingConfig:
cpuTarget: 70
maxNodes: 5
minNodes: 2
storageTarget: 2560
clusterId: cluster-2-${uniqueId}
numNodes: 2
storageType: SSD
zone: us-central1-b
- autoscalingConfig:
cpuTarget: 70
maxNodes: 5
minNodes: 2
clusterId: cluster-3-${uniqueId}
numNodes: 2
storageType: SSD
zone: us-central1-c
displayName: BigtableSample
instanceType: PRODUCTION
Expand All @@ -52,4 +44,4 @@ status:
reason: UpToDate
status: "True"
type: Ready
observedGeneration: 4
observedGeneration: 3
Loading

0 comments on commit e4bf65d

Please sign in to comment.