Skip to content

Commit

Permalink
[Add] CEL rules for validating App and PackageInstall Spec
Browse files Browse the repository at this point in the history
This PR:
- Adds KB marker to ensure that either spec.ServiceAccount
  or spec.Cluster is present in App and PackageInstall 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.

Signed-off-by: Varsha Prasad Narsing <[email protected]>
  • Loading branch information
varshaprasad96 committed Nov 1, 2023
1 parent 5b1294b commit 821176c
Show file tree
Hide file tree
Showing 45 changed files with 721 additions and 214 deletions.
6 changes: 6 additions & 0 deletions config/config/crds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,9 @@ spec:
required:
- spec
type: object
x-kubernetes-validations:
- message: Expected service account or cluster.
rule: has(self.spec.serviceAccountName) || has(self.spec.cluster)
served: true
storage: true
subresources:
Expand Down Expand Up @@ -1594,6 +1597,9 @@ spec:
required:
- spec
type: object
x-kubernetes-validations:
- message: Expected service account or cluster.
rule: has(self.spec.serviceAccountName) || has(self.spec.cluster)
served: true
storage: true
subresources:
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
k8s.io/kube-aggregator v0.22.17
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1
sigs.k8s.io/controller-runtime v0.13.1
sigs.k8s.io/controller-tools v0.7.0
sigs.k8s.io/controller-tools v0.10.0
sigs.k8s.io/yaml v1.3.0
)

Expand Down Expand Up @@ -61,7 +61,7 @@ require (
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.6 // indirect
github.com/go-openapi/swag v0.19.15 // indirect
github.com/gobuffalo/flect v0.2.3 // indirect
github.com/gobuffalo/flect v0.2.5 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
Expand Down
55 changes: 4 additions & 51 deletions go.sum

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pkg/apis/kappctrl/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
// +kubebuilder:printcolumn:name=Description,JSONPath=.status.friendlyDescription,description=Friendly description,type=string
// +kubebuilder:printcolumn:name=Since-Deploy,JSONPath=.status.deploy.startedAt,description=Last time app started being deployed. Does not mean anything was changed.,type=date
// +kubebuilder:printcolumn:name=Age,JSONPath=.metadata.creationTimestamp,description=Time since creation,type=date
// +kubebuilder:validation:XValidation:rule="has(self.spec.serviceAccountName) || has(self.spec.cluster)", message="Expected service account or cluster."
// +protobuf=false
// An App is a set of Kubernetes resources. These resources could span any number of namespaces or could be cluster-wide (e.g. CRDs). An App is represented in kapp-controller using a App CR.
// The App CR comprises of three main sections:
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/packaging/v1alpha1/package_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
// +kubebuilder:printcolumn:name=Package version,JSONPath=.status.version,description=PackageMetadata version,type=string
// +kubebuilder:printcolumn:name=Description,JSONPath=.status.friendlyDescription,description=Friendly description,type=string
// +kubebuilder:printcolumn:name=Age,JSONPath=.metadata.creationTimestamp,description=Time since creation,type=date
// +kubebuilder:validation:XValidation:rule="has(self.spec.serviceAccountName) || has(self.spec.cluster)", message="Expected service account or cluster."
// A Package Install is an actual installation of a package and its underlying resources on a Kubernetes cluster.
// It is represented in kapp-controller by a PackageInstall CR.
// A PackageInstall CR must reference a Package CR.
Expand Down
4 changes: 0 additions & 4 deletions vendor/github.com/gobuffalo/flect/camelize.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions vendor/github.com/gobuffalo/flect/pascalize.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions vendor/github.com/gobuffalo/flect/plural_rules.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions vendor/github.com/gobuffalo/flect/singular_rules.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ github.com/go-openapi/jsonreference
# github.com/go-openapi/swag v0.19.15
## explicit; go 1.11
github.com/go-openapi/swag
# github.com/gobuffalo/flect v0.2.3
# github.com/gobuffalo/flect v0.2.5
## explicit; go 1.13
github.com/gobuffalo/flect
# github.com/gogo/protobuf v1.3.2
Expand Down Expand Up @@ -1248,8 +1248,8 @@ sigs.k8s.io/controller-runtime/pkg/source/internal
sigs.k8s.io/controller-runtime/pkg/webhook
sigs.k8s.io/controller-runtime/pkg/webhook/admission
sigs.k8s.io/controller-runtime/pkg/webhook/internal/metrics
# sigs.k8s.io/controller-tools v0.7.0
## explicit; go 1.16
# sigs.k8s.io/controller-tools v0.10.0
## explicit; go 1.19
sigs.k8s.io/controller-tools/cmd/controller-gen
sigs.k8s.io/controller-tools/pkg/crd
sigs.k8s.io/controller-tools/pkg/crd/markers
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions vendor/sigs.k8s.io/controller-tools/pkg/crd/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions vendor/sigs.k8s.io/controller-tools/pkg/crd/flatten.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 33 additions & 6 deletions vendor/sigs.k8s.io/controller-tools/pkg/crd/gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions vendor/sigs.k8s.io/controller-tools/pkg/crd/known_types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vendor/sigs.k8s.io/controller-tools/pkg/crd/markers/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 821176c

Please sign in to comment.