-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Add] CEL rules for validating App and PackageInstall Spec
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.12.1 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
1 parent
6d83c43
commit 262b480
Showing
86 changed files
with
1,970 additions
and
875 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2021 VMware, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package kappcontroller | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/vmware-tanzu/carvel-kapp-controller/test/e2e" | ||
) | ||
|
||
// TestSAandClusterCELValidation tests packageInstall and App CR | ||
// to ensure that either SA or cluster is validated at admission. | ||
func TestSAandClusterCELValidation(t *testing.T) { | ||
env := e2e.BuildEnv(t) | ||
logger := e2e.Logger{} | ||
kapp := e2e.Kapp{t, env.Namespace, logger} | ||
kubectl := e2e.Kubectl{t, env.Namespace, logger} | ||
|
||
name := "incorrect-spec-without-sa-cluster" | ||
|
||
appYAML := fmt.Sprintf(` | ||
--- | ||
apiVersion: kappctrl.k14s.io/v1alpha1 | ||
kind: App | ||
metadata: | ||
name: %s | ||
annotations: | ||
kapp.k14s.io/change-group: kappctrl-e2e.k14s.io/apps | ||
spec: | ||
fetch: | ||
- inline: | ||
paths: | ||
file.yml: | | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: configmap | ||
template: | ||
- ytt: {} | ||
deploy: | ||
- kapp: {} | ||
`, name) | ||
|
||
pkginstallYAML := fmt.Sprintf(` | ||
--- | ||
apiVersion: packaging.carvel.dev/v1alpha1 | ||
kind: PackageInstall | ||
metadata: | ||
name: %[2]s | ||
namespace: %[1]s | ||
annotations: | ||
kapp.k14s.io/change-group: kappctrl-e2e.k14s.io/packageinstalls | ||
spec: | ||
packageRef: | ||
refName: pkg.incorrect.carvel.dev | ||
versionSelection: | ||
constraints: 1.0.0 | ||
`, env.Namespace, name) | ||
|
||
logger.Section("Create App CR with kubectl", func() { | ||
_, err := kubectl.RunWithOpts([]string{"apply", "-f", "-"}, e2e.RunOpts{StdinReader: strings.NewReader(appYAML), AllowError: true}) | ||
require.Error(t, err) | ||
require.ErrorContains(t, err, "Expected service account or cluster.") | ||
}) | ||
|
||
logger.Section("Create PackageInstall with kapp", func() { | ||
_, err := kapp.RunWithOpts([]string{"deploy", "-a", name, "-f", "-"}, e2e.RunOpts{StdinReader: strings.NewReader(pkginstallYAML), AllowError: true}) | ||
require.Error(t, err) | ||
require.ErrorContains(t, err, "Expected service account or cluster.") | ||
}) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.