Skip to content

Commit

Permalink
Merge pull request #1919 from justinsb/dont_hide_state_into_spec
Browse files Browse the repository at this point in the history
tests: Don't ignore annotations with direct reconciler
  • Loading branch information
google-oss-prow[bot] authored Jun 4, 2024
2 parents 8b55156 + a93f167 commit eae1fe8
Show file tree
Hide file tree
Showing 18 changed files with 475 additions and 1,171 deletions.
50 changes: 9 additions & 41 deletions pkg/test/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ func CompareGoldenFile(t *testing.T, p string, got string, normalizers ...func(s
return
}

if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("unexpected diff in %s: %s", p, diff)
}

if writeGoldenOutput {
// Write the output to the golden file
if err := os.WriteFile(p, []byte(got), 0644); err != nil {
t.Fatalf("failed to write golden output %s: %v", p, err)
}
t.Errorf("wrote updated golden output to %s", p)
} else {
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("unexpected diff in %s: %s", p, diff)
}
t.Logf("wrote updated golden output to %s", p)
}
}

Expand Down Expand Up @@ -169,50 +169,18 @@ func CompareGoldenObject(t *testing.T, p string, got []byte) {
t.Errorf("Failed parsing file: %s", err)
}

diff := cmp.Diff(postWriteNormalization(wantMap), gotMap)
diff := cmp.Diff(wantMap, gotMap)
if diff == "" {
return
}

t.Errorf("unexpected diff in %s: %s", p, diff)

if writeGoldenOutput {
// Write the output to the golden file
if err := os.WriteFile(p, []byte(got), 0644); err != nil {
t.Fatalf("failed to write golden output %s: %v", p, err)
}
t.Errorf("wrote updated golden output to %s", p)
} else {
t.Errorf("unexpected diff in %s: %s", p, diff)
}
}

func postWriteNormalization(wantMap map[string]interface{}) map[string]interface{} {
if os.Getenv("KCC_USE_DIRECT_RECONCILERS") != "" {
metadataMap, ok := wantMap["metadata"].(map[string]interface{})
if !ok {
panic("metadata is not a map")
}

annotations := metadataMap["annotations"]
if annotations == nil {
// nothing to normalize
return wantMap
}
annotationsMap, ok := annotations.(map[string]interface{})
if !ok {
panic("annotations is not a map")
}

// for direct resources, we don't support the state-into-spec annotation
if annotationsMap["cnrm.cloud.google.com/state-into-spec"] != "" {
delete(annotationsMap, "cnrm.cloud.google.com/state-into-spec")
}
// we also don't support the mutable but unreadable annotation yet
if annotationsMap["cnrm.cloud.google.com/mutable-but-unreadable-fields"] != "" {
delete(annotationsMap, "cnrm.cloud.google.com/mutable-but-unreadable-fields")
}

metadataMap["annotations"] = annotationsMap
t.Logf("wrote updated golden output to %s", p)
}

return wantMap
}
5 changes: 2 additions & 3 deletions scripts/github-actions/tests-e2e-direct.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,23 @@ cd ${REPO_ROOT}/
echo "Downloading envtest assets..."
export KUBEBUILDER_ASSETS=$(go run sigs.k8s.io/controller-runtime/tools/setup-envtest@latest use -p path)

#export KCC_USE_DIRECT_RECONCILERS=LoggingLogMetric

echo "Running e2e tests samples for LoggingLogMetric direct reconciliation..."

KCC_USE_DIRECT_RECONCILERS=LoggingLogMetric \
GOLDEN_OBJECT_CHECKS=1 \
GOLDEN_REQUEST_CHECKS=1 \
E2E_KUBE_TARGET=envtest RUN_E2E=1 E2E_GCP_TARGET=mock \
go test -test.count=1 -timeout 600s -v ./tests/e2e -run 'TestAllInSeries/samples/linear-log-metric|TestAllInSeries/samples/exponential-log-metric|TestAllInSeries/samples/int-log-metric|TestAllInSeries/samples/explicit-log-metric'

echo "Running e2e tests fixtures for LoggingLogMetric direct reconciliation..."

KCC_USE_DIRECT_RECONCILERS=LoggingLogMetric \
GOLDEN_OBJECT_CHECKS=1 \
GOLDEN_REQUEST_CHECKS=1 \
E2E_KUBE_TARGET=envtest RUN_E2E=1 E2E_GCP_TARGET=mock \
go test -test.count=1 -timeout 600s -v ./tests/e2e -run 'TestAllInSeries/fixtures/explicitlogmetric|TestAllInSeries/fixtures/exponentiallogmetric|TestAllInSeries/fixtures/linearlogmetric|TestAllInSeries/fixtures/logbucketmetric'

echo "Running scenarios tests for LoggingLogMetric direct reconciliation..."

KCC_USE_DIRECT_RECONCILERS=LoggingLogMetric \
GOLDEN_REQUEST_CHECKS=1 E2E_KUBE_TARGET=envtest E2E_GCP_TARGET=mock RUN_E2E=1 \
go test -test.count=1 -timeout 360s -v ./tests/e2e -run TestE2EScript/scenarios/fields
Original file line number Diff line number Diff line change
@@ -1,70 +1,5 @@
GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json
Content-Type: application/json
User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1

404 Not Found
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

{
"error": {
"code": 404,
"errors": [
{
"domain": "global",
"message": "logMetric \"projects/${projectId}/metrics/logginglogmetric-${uniqueId}\" not found",
"reason": "notFound"
}
],
"message": "logMetric \"projects/${projectId}/metrics/logginglogmetric-${uniqueId}\" not found",
"status": "NOT_FOUND"
}
}

---

GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json
Content-Type: application/json
User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1

404 Not Found
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

{
"error": {
"code": 404,
"errors": [
{
"domain": "global",
"message": "logMetric \"projects/${projectId}/metrics/logginglogmetric-${uniqueId}\" not found",
"reason": "notFound"
}
],
"message": "logMetric \"projects/${projectId}/metrics/logginglogmetric-${uniqueId}\" not found",
"status": "NOT_FOUND"
}
}

---

GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json
Content-Type: application/json
User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1
GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json&prettyPrint=false
User-Agent: google-api-go-client/0.5

404 Not Found
Cache-Control: private
Expand All @@ -80,23 +15,16 @@ X-Xss-Protection: 0
{
"error": {
"code": 404,
"errors": [
{
"domain": "global",
"message": "logMetric \"projects/${projectId}/metrics/logginglogmetric-${uniqueId}\" not found",
"reason": "notFound"
}
],
"message": "logMetric \"projects/${projectId}/metrics/logginglogmetric-${uniqueId}\" not found",
"message": "Metric logginglogmetric-${uniqueId} does not exist.",
"status": "NOT_FOUND"
}
}

---

POST https://logging.googleapis.com/v2/projects/${projectId}/metrics?alt=json
POST https://logging.googleapis.com/v2/projects/${projectId}/metrics?alt=json&prettyPrint=false
Content-Type: application/json
User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1
User-Agent: google-api-go-client/0.5

{
"bucketOptions": {
Expand Down Expand Up @@ -172,9 +100,8 @@ X-Xss-Protection: 0

---

GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json
Content-Type: application/json
User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1
GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json&prettyPrint=false
User-Agent: google-api-go-client/0.5

200 OK
Cache-Control: private
Expand Down Expand Up @@ -221,20 +148,9 @@ X-Xss-Protection: 0

---

GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json
PUT https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json&prettyPrint=false
Content-Type: application/json
User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1

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
User-Agent: google-api-go-client/0.5

{
"bucketOptions": {
Expand All @@ -255,74 +171,18 @@ X-Xss-Protection: 0
"labels": [
{
"description": "a label description",
"key": "testkey"
}
],
"metricKind": "DELTA",
"name": "projects/${projectId}/metricDescriptors/logging.googleapis.com/user/logginglogmetric-${uniqueId}",
"type": "logging.googleapis.com/user/logginglogmetric-${uniqueId}",
"valueType": "DISTRIBUTION"
},
"name": "logginglogmetric-${uniqueId}",
"updateTime": "2024-04-01T12:34:56.123456Z",
"valueExtractor": "EXTRACT(jsonPayload.response)"
}

---

GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json
Content-Type: application/json
User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1

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": {
"bounds": [
1.5,
4.5
]
}
},
"createTime": "2024-04-01T12:34:56.123456Z",
"filter": "resource.type=gae_app AND severity\u003c=ERROR",
"labelExtractors": {
"testkey": "EXTRACT(jsonPayload.request)"
},
"metricDescriptor": {
"displayName": "a concise name",
"labels": [
{
"description": "a label description",
"key": "testkey"
"key": "testkey",
"valueType": "STRING"
}
],
"metricKind": "DELTA",
"name": "projects/${projectId}/metricDescriptors/logging.googleapis.com/user/logginglogmetric-${uniqueId}",
"type": "logging.googleapis.com/user/logginglogmetric-${uniqueId}",
"valueType": "DISTRIBUTION"
},
"name": "logginglogmetric-${uniqueId}",
"updateTime": "2024-04-01T12:34:56.123456Z",
"valueExtractor": "EXTRACT(jsonPayload.response)"
}

---

GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json
Content-Type: application/json
User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1

200 OK
Cache-Control: private
Content-Type: application/json; charset=UTF-8
Expand Down Expand Up @@ -368,9 +228,8 @@ X-Xss-Protection: 0

---

GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json
Content-Type: application/json
User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1
GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json&prettyPrint=false
User-Agent: google-api-go-client/0.5

200 OK
Cache-Control: private
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json
Content-Type: application/json
User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1
GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json&prettyPrint=false
User-Agent: google-api-go-client/0.5

200 OK
Cache-Control: private
Expand Down Expand Up @@ -47,9 +46,39 @@ X-Xss-Protection: 0

---

GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json
PUT https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json&prettyPrint=false
Content-Type: application/json
User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1
User-Agent: google-api-go-client/0.5

{
"bucketOptions": {
"explicitBuckets": {
"bounds": [
1.5,
4.5
]
}
},
"createTime": "2024-04-01T12:34:56.123456Z",
"filter": "resource.type=gae_app AND severity\u003c=ERROR",
"labelExtractors": {
"testkey": "EXTRACT(jsonPayload.request)"
},
"metricDescriptor": {
"displayName": "a concise name",
"labels": [
{
"description": "a label description",
"key": "testkey"
}
],
"metricKind": "DELTA",
"valueType": "DISTRIBUTION"
},
"name": "logginglogmetric-${uniqueId}",
"updateTime": "2024-04-01T12:34:56.123456Z",
"valueExtractor": "EXTRACT(jsonPayload.response)"
}

200 OK
Cache-Control: private
Expand Down Expand Up @@ -96,9 +125,8 @@ X-Xss-Protection: 0

---

GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json
Content-Type: application/json
User-Agent: kcc/controller-manager DeclarativeClientLib/0.0.1
GET https://logging.googleapis.com/v2/projects/${projectId}/metrics/logginglogmetric-${uniqueId}?alt=json&prettyPrint=false
User-Agent: google-api-go-client/0.5

200 OK
Cache-Control: private
Expand Down
Loading

0 comments on commit eae1fe8

Please sign in to comment.