Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat empty array and nil as equivalent when diffing #293

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

barney-s
Copy link
Member

Treat an empty array and nil as equivalent

Fix for #289

@barney-s
Copy link
Member Author

@Manny2014 FYI

@barney-s
Copy link
Member Author

Tested by porting these changes over to e2e PR.
testcase.go:193: Running step3: Update RGD to set the deployment spec to have an empty env array

❯ make test-e2e
go test -v ./test/e2e/suites/basic/...
=== RUN   TestAutoscaledDeploymentRGD
    multi_resource_test.go:38: Using namespace: e2e-autoscaled-deployment-rgd-1739345557, from: testdata/../../../../test/e2e/testdata/autoscaled-deployment-rgd
    testcase.go:193: Running step0: Install the RGD AutoscaledDeployment that creates a ConfigMap, Service, Deployment, and HPA 
    testcase.go:359:    Applying ResourceGraphDefinition/autoscaled-deployment-rgd[rgd.yaml]
    verify.go:57:       Verifying ResourceGraphDefinition/autoscaled-deployment-rgd[0rgd.yaml]
    verify.go:57:       Verifying CustomResourceDefinition/autoscaleddeployments.kro.run[1instancecrd.yaml]
    testcase.go:193: Running step1: Create an instance of AutoscaledDeployment with initial settings (version 1.24, 1 replica, 20% CPU utilization) 
    testcase.go:359:    Applying AutoscaledDeployment/test-app-instance[instance.yaml]
    verify.go:57:       Verifying Deployment/test-app-deployment[deployment.yaml]
    verify.go:57:       Verifying HorizontalPodAutoscaler/test-app-hpa[hpa.yaml]
    verify.go:57:       Verifying AutoscaledDeployment/test-app-instance[instance.yaml]
    verify.go:57:       Verifying Service/test-app-service[service.yaml]
    testcase.go:193: Running step2: Update the instance to use a newer version (1.25) which should trigger a rolling update of the Deployment 
    testcase.go:359:    Applying AutoscaledDeployment/test-app-instance[instance.yaml]
    verify.go:57:       Verifying Deployment/test-app-deployment[deployment.yaml]
    testcase.go:193: Running step3: Update the instance to increase replicas to 3 and adjust HPA settings (min: 2, max: 5) 
    testcase.go:359:    Applying AutoscaledDeployment/test-app-instance[instance.yaml]
    verify.go:57:       Verifying Deployment/test-app-deployment[deployment.yaml]
    verify.go:57:       Verifying HorizontalPodAutoscaler/test-app-hpa[hpa.yaml]
    testcase.go:134: Deleting namespace: e2e-autoscaled-deployment-rgd-1739345557
    testcase.go:148: Deleting cluster-scoped object: ResourceGraphDefinition/autoscaled-deployment-rgd
--- PASS: TestAutoscaledDeploymentRGD (30.23s)
=== RUN   TestSimpleDeploymentRGD
    simple_deployment_test.go:27: Using namespace: e2e-simple-deployment-rgd-1739345587, from: testdata/../../../../test/e2e/testdata/simple-deployment-rgd
    testcase.go:193: Running step0: Install RGD and verify that the RGD is created
    testcase.go:359:    Applying ResourceGraphDefinition/simple-deployment-rgd[rgd.yaml]
    verify.go:57:       Verifying ResourceGraphDefinition/simple-deployment-rgd[0rgd.yaml]
    verify.go:57:       Verifying CustomResourceDefinition/simpledeployments.kro.run[1instancecrd.yaml]
    testcase.go:193: Running step1: Create instance SimpleDeployment with replicas=2
    testcase.go:359:    Applying SimpleDeployment/test-instance[instance.yaml]
    verify.go:57:       Verifying Deployment/test-instance[deployment.yaml]
    verify.go:57:       Verifying SimpleDeployment/test-instance[instance.yaml]
    testcase.go:193: Running step2: Update instance SimpleDeployment with replicas=3
    testcase.go:359:    Applying SimpleDeployment/test-instance[instance.yaml]
    verify.go:57:       Verifying Deployment/test-instance[deployment.yaml]
    testcase.go:193: Running step3: Update RGD to set the deployment spec to have an empty env array
    testcase.go:359:    Applying ResourceGraphDefinition/simple-deployment-rgd[rgd.yaml]
    verify.go:57:       Verifying ResourceGraphDefinition/simple-deployment-rgd[0rgd.yaml]
    verify.go:57:       Verifying SimpleDeployment/test-instance[1instance.yaml]
    testcase.go:134: Deleting namespace: e2e-simple-deployment-rgd-1739345587
    testcase.go:148: Deleting cluster-scoped object: ResourceGraphDefinition/simple-deployment-rgd
    testcase.go:148: Deleting cluster-scoped object: ResourceGraphDefinition/simple-deployment-rgd
--- PASS: TestSimpleDeploymentRGD (15.21s)
PASS

barney-s added a commit to barney-s/kro that referenced this pull request Feb 12, 2025
@barney-s barney-s requested a review from matthchr February 12, 2025 07:53
barney-s added a commit to barney-s/kro that referenced this pull request Feb 12, 2025
- test step for testing kro-run#293. skip it for now till that PR is merged
- test for verifying kro-run#299 - Using
  secrets with stringData
- test for verifying kro-run#300 - using
  secret.metadata.resourceVersion in deployment
@@ -113,7 +113,17 @@ func walkCompare(desired, observed interface{}, path string, differences *[]Diff
}
walkMap(d, e, path, differences)

case nil:
// Special case: treat empty array and nil as equivalent
if isEmptyArrayOrNil(desired) && isEmptyArrayOrNil(observed) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle for map ?

@barney-s
Copy link
Member Author

Few things to try:

  1. Identify who is throwing away the empty array ? API server or unstructured.unstructred lib
  2. what about CRDs.
  3. What about maps{}.

barney-s added a commit to barney-s/kro that referenced this pull request Feb 14, 2025
- test step for testing kro-run#293. skip it for now till that PR is merged
- test for verifying kro-run#299 - Using
  secrets with stringData
- test for verifying kro-run#300 - using
  secret.metadata.resourceVersion in deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant