[Add] CEL rule for validating App and PackageInstall Spec
What this PR does / why we need it:
This PR:
- Adds KB marker to ensure that either spec.ServiceAccount or spec.Cluster is present in App CR.
- Bumps controller-tools to 0.10.0 to support CEL based validation marker. That is the latest version compatible with the k8s release the project is currently at.
Which issue(s) this PR fixes:
Fixes #1380
Does this PR introduce a user-facing change?
No. The validation already exists, this change performs the same action before the resource is created.
Additional Notes for your reviewer:
Review Checklist:
- [ ] Follows the developer guidelines
- [ ] Relevant tests are added or updated
- [ ] Relevant docs in this repo added or updated
- [ ] Relevant carvel.dev docs added or updated in a separate PR and there's a link to that PR
- [ ] Code is at least as readable and maintainable as it was before this change
Additional documentation e.g., Proposal, usage docs, etc.:
one comment based on my first glance. currently if both serviceAccount and cluster are specified in a PackageInstall CRD, the serviceAccount is read and used. if none are specified, we get an error.
so validation in PR might break some existing configuration. @praveenrewar @100mik Is current behaviour to choose serviceAccount over cluster config by design?
@prembhaskal @praveenrewar I've modified the validation to just check the existence of atleast one of it. This should retain the current behaviour and fix the failing tests.
~~all seems fine.~~ Well test is failing actually.
I think test is failing because k8s version of minikube is set to 1.20 which does not support CEL validation. https://github.com/carvel-dev/kapp-controller/blob/b4886dfaff8050fc7221e1d7bce9e69e2a4264e3/.github/workflows/test-gh.yml#L49
We could bump k8s version in the tests, but I don't want us to indicate that we don't support any version before 1.26. Since the kind tests with the latest version are passing, I think we can add a check in this test to skip if k8s version is <1.26.x (as the validation won't work on older versions but there shouldn't be any other issue because of it).
Sorry for not being able to follow up due to other commitments. The recent changes should skip the test if the server version is less than 1.26.
@varshaprasad96 The test seems to be failing while getting the server version (I haven't taken a closer look so not sure exactly which part).
cel_validation_test.go:26: Error getting Kubernetes version: unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined
failing because the test code is not running on the kind cluster.