Skip to content

Commit

Permalink
tests: Introduce internal annotation to force reconciliation
Browse files Browse the repository at this point in the history
The internal.cnrm.cloud.google.com/reconcile-cookie annotation can be
changed without affecting the "true" desired state, but we special
case the annotation in our filtering, so that it still triggers the
reconciler.
  • Loading branch information
justinsb committed May 14, 2024
1 parent a7d5d00 commit 6708226
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 71 deletions.
5 changes: 5 additions & 0 deletions pkg/controller/predicate/predicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ func (UnderlyingResourceOutOfSyncPredicate) Update(e event.UpdateEvent) bool {
return true
}

// Recognize an internal annotation which can be used to force reconciles
if e.ObjectOld.GetAnnotations()[k8s.InternalForceReconcileAnnotation] != e.ObjectNew.GetAnnotations()[k8s.InternalForceReconcileAnnotation] {
return true
}

// The object's generation will increment when the spec is updated, so a different
// generation implies potential work to be done on the underlying API.
if e.ObjectNew.GetGeneration() != e.ObjectOld.GetGeneration() {
Expand Down
4 changes: 4 additions & 0 deletions pkg/k8s/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type ManagementConflictPreventionPolicy string
// TODO: clean up old conditions used in handcrafted controllers
const (
CNRMGroup = "cnrm.cloud.google.com"
CNRMInternalGroup = "internal.cnrm.cloud.google.com"
APIDomainSuffix = ".cnrm.cloud.google.com"
SystemNamespace = "cnrm-system"
ControllerManagerNamePrefix = "cnrm-controller-manager"
Expand Down Expand Up @@ -113,6 +114,9 @@ var (
OrgIDAnnotation,
}

// Internal Annotation to force reconciliation
InternalForceReconcileAnnotation = CNRMInternalGroup + "/reconcile-cookie"

ManagementConflictPreventionPolicyAnnotation = "management-conflict-prevention-policy"
ManagementConflictPreventionPolicyFullyQualifiedAnnotation = FormatAnnotation(ManagementConflictPreventionPolicyAnnotation)
ManagementConflictPreventionPolicyValues = []string{
Expand Down
39 changes: 0 additions & 39 deletions tests/e2e/testdata/scenarios/direct/llm_lazy_reconcile/_http01.log
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,6 @@ X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 0

{
"bucketOptions": {
"explicitBuckets": {
"bounds": [
2.5,
5
]
}
},
"createTime": "2024-04-01T12:34:56.123456Z",
"filter": "resource.type=gae_app AND severity\u003e=ERROR",
"metricDescriptor": {
"metricKind": "DELTA",
"name": "projects/${projectId}/metricDescriptors/logging.googleapis.com/user/lazyreconcile-${uniqueId}",
"type": "logging.googleapis.com/user/lazyreconcile-${uniqueId}",
"valueType": "DISTRIBUTION"
},
"name": "lazyreconcile-${uniqueId}",
"updateTime": "2024-04-01T12:34:56.123456Z",
"valueExtractor": "EXTRACT(jsonPayload.response)"
}

---

GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/lazyreconcile-${uniqueId}?alt=json&prettyPrint=false
User-Agent: google-api-go-client/0.5
X-Goog-Api-Client: gl-go/1.22.3 gdcl/0.177.0

200 OK
Cache-Control: private
Content-Type: application/json; charset=UTF-8
Server: ESF
Vary: Origin
Vary: X-Origin
Vary: Referer
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 0

{
"bucketOptions": {
"explicitBuckets": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +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: logging.cnrm.cloud.google.com/v1beta1
kind: LoggingLogMetric
metadata:
annotations:
cnrm.cloud.google.com/management-conflict-prevention-policy: none
cnrm.cloud.google.com/project-id: ${projectId}
cnrm.cloud.google.com/reconcile-interval-in-seconds: "1"
cnrm.cloud.google.com/state-into-spec: absent
finalizers:
- cnrm.cloud.google.com/finalizer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
# 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: logging.cnrm.cloud.google.com/v1beta1
kind: LoggingLogMetric
metadata:
annotations:
cnrm.cloud.google.com/management-conflict-prevention-policy: none
cnrm.cloud.google.com/project-id: ${projectId}
cnrm.cloud.google.com/reconcile-interval-in-seconds: "1"
cnrm.cloud.google.com/state-into-spec: absent
internal.cnrm.cloud.google.com/reconcile-cookie: B
finalizers:
- cnrm.cloud.google.com/finalizer
- cnrm.cloud.google.com/deletion-defender
Expand Down
20 changes: 18 additions & 2 deletions tests/e2e/testdata/scenarios/direct/llm_lazy_reconcile/script.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ metadata:
name: lazyreconcile-${uniqueId}
annotations:
cnrm.cloud.google.com/state-into-spec: absent
cnrm.cloud.google.com/reconcile-interval-in-seconds : "1"
spec:
filter: "resource.type=gae_app AND severity>=ERROR"
metricDescriptor:
Expand All @@ -33,8 +32,25 @@ spec:
projectRef:
external: "projects/${projectId}"
---
TEST: SLEEP
TEST: WAIT-FOR-HTTP-REQUEST
VALUE_PRESENT: "lazyreconcile"
apiVersion: logging.cnrm.cloud.google.com/v1beta1
kind: LoggingLogMetric
metadata:
name: lazyreconcile-${uniqueId}
annotations:
cnrm.cloud.google.com/state-into-spec: absent
internal.cnrm.cloud.google.com/reconcile-cookie: B
spec:
filter: "resource.type=gae_app AND severity>=ERROR"
metricDescriptor:
metricKind: "DELTA"
valueType: "DISTRIBUTION"
valueExtractor: "EXTRACT(jsonPayload.response)"
bucketOptions:
explicitBuckets:
bounds:
- 2.5
- 5
projectRef:
external: "projects/${projectId}"

0 comments on commit 6708226

Please sign in to comment.