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 Oct 30, 2023
1 parent 5b1294b commit c8dbf0f
Show file tree
Hide file tree
Showing 45 changed files with 724 additions and 214 deletions.
9 changes: 9 additions & 0 deletions config/config/crds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,9 @@ spec:
type: object
type: array
type: object
x-kubernetes-validations:
- message: Expected service account or cluster.
rule: has(self.serviceAccountName) || has(self.cluster)
required:
- spec
type: object
Expand Down Expand Up @@ -1306,6 +1309,9 @@ spec:
type: object
type: array
type: object
x-kubernetes-validations:
- message: Expected service account or cluster.
rule: has(self.serviceAccountName) || has(self.cluster)
status:
properties:
conditions:
Expand Down Expand Up @@ -1555,6 +1561,9 @@ spec:
type: object
type: array
type: object
x-kubernetes-validations:
- message: Expected service account or cluster.
rule: has(self.serviceAccountName) || has(self.cluster)
status:
properties:
conditions:
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 @@ -44,6 +44,7 @@ type AppList struct {
}

// +k8s:openapi-gen=true
// +kubebuilder:validation:XValidation:rule="has(self.serviceAccountName) || has(self.cluster)", message="Expected service account or cluster."
type AppSpec struct {
// Specifies that app should be deployed authenticated via
// given service account, found in this namespace (optional; v0.6.0+)
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 @@ -43,6 +43,7 @@ type PackageInstallList struct {
Items []PackageInstall `json:"items"`
}

// +kubebuilder:validation:XValidation:rule="has(self.serviceAccountName) || has(self.cluster)", message="Expected service account or cluster."

Check warning on line 46 in pkg/apis/packaging/v1alpha1/package_install.go

View workflow job for this annotation

GitHub Actions / lint

exported: comment on exported type PackageInstallSpec should be of the form "PackageInstallSpec ..." (with optional leading article) (revive)
type PackageInstallSpec struct {
// Specifies service account that will be used to install underlying package contents
// +optional
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 c8dbf0f

Please sign in to comment.