Skip to content

Commit

Permalink
Add e2e test changes for cliplugins crd package
Browse files Browse the repository at this point in the history
Adds an e2e test that performs plugin sync using crd package built from
the package/cliplugin.cli.tanzu.vmware.com directory.
The specific test requires an envvar CRD_PACKAGE_IMAGE to be set
and pointing to a registry location that the test has push permissions
on.

Also adds build-crd-package.sh that will conditionally build and publish
the CRD package if CRD_PACKAGE_IMAGE is set.

Signed-off-by: Vui Lam <[email protected]>
  • Loading branch information
vuil committed Feb 14, 2024
1 parent 19acac2 commit 96e0ba0
Show file tree
Hide file tree
Showing 11 changed files with 3,024 additions and 12 deletions.
28 changes: 28 additions & 0 deletions hack/scripts/build-crd-package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

# Copyright 2024 VMware, Inc. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

set -e
set -x

if [ -z "$CRD_PACKAGE_IMAGE" ]; then
echo "skip building of CRD package because CRD_PACKAGE_IMAGE is not set"
exit 0
fi

BASE_DIR=$(cd $(dirname "${BASH_SOURCE[0]}"); pwd)
PACKAGE_DIR=${BASE_DIR}/../../package/cliplugin.cli.tanzu.vmware.com
BINDIR=${BASE_DIR}/../tools/bin

KCTRL=${KCTRL:-$BINDIR/kctrl}
YQ=${YQ:-$BINDIR/yq}

pushd ${PACKAGE_DIR}

$YQ e -i ".spec.template.spec.export[0].imgpkgBundle.image=\"${CRD_PACKAGE_IMAGE}\"" ./package-build.yml

PATH=${BINDIR}:$PATH ${KCTRL} package release --yes

popd

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ spec:
- kbld: {}
export:
- imgpkgBundle:
image: localhost:6001/tanzu_cli/lever-v2/cliplugin
image: localhost:6001/tanzu_cli/cliplugin
includePaths:
- cli.tanzu.vmware.com_cliplugins.yaml
- .imgpkg/images.yml
File renamed without changes.
2,676 changes: 2,676 additions & 0 deletions package/cliplugin.cli.tanzu.vmware.com/test/kapp-controller.yaml

Large diffs are not rendered by default.

174 changes: 174 additions & 0 deletions package/cliplugin.cli.tanzu.vmware.com/test/package-pi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
apiVersion: packaging.carvel.dev/v1alpha1
kind: PackageInstall
metadata:
annotations:
kctrl.carvel.dev/local-fetch-0: .
creationTimestamp: null
name: cliplugin
spec:
packageRef:
refName: cliplugin.cli.tanzu.vmware.com
versionSelection:
# XXX sufficient for now to pick up any version of package deployed during test
constraints: "<1.0.0"
serviceAccountName: tanzu-cliplugins-package-sa
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: tanzu-cliplugins-package-sa
namespace: default
annotations:
kapp.k14s.io/change-group: "cliplugins-packageinstall/serviceaccount-0"
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: tanzu-cliplugins-package-cluster-role
annotations:
kapp.k14s.io/change-group: "cliplugins-packageinstall/serviceaccount-0"
rules:
- apiGroups:
- ""
resources:
- configmaps
- secrets
- serviceaccounts
- services
- namespaces
verbs:
- create
- update
- get
- list
- delete
- watch
- patch
- apiGroups:
- apps
resources:
- deployments
verbs:
- create
- update
- get
- list
- delete
- apiGroups:
- apiextensions.k8s.io
resources:
- customresourcedefinitions
verbs:
- create
- update
- get
- list
- delete
- watch
- apiGroups:
- rbac.authorization.k8s.io
resources:
- clusterroles
- clusterrolebindings
verbs:
- create
- update
- get
- list
- delete
- apiGroups:
- cli.tanzu.vmware.com
resources:
- cliplugins
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- delete
- apiGroups:
- cli.tanzu.vmware.com
resources:
- cliplugins/finalizers
verbs:
- update
- apiGroups:
- cli.tanzu.vmware.com
resources:
- cliplugins/status
verbs:
- get
- patch
- update
- apiGroups:
- ""
resources:
- namespaces
verbs:
- get
- list
- watch
- apiGroups:
- data.packaging.carvel.dev
resources:
- packages
verbs:
- get
- list
- watch
- apiGroups:
- data.packaging.carvel.dev
resources:
- packages/status
verbs:
- get
- list
- apiGroups:
- packaging.carvel.dev
resources:
- packageinstalls
verbs:
- get
- list
- watch
- update
- patch
- apiGroups:
- packaging.carvel.dev
resources:
- packageinstalls/status
verbs:
- get
- apiGroups:
- "admissionregistration.k8s.io"
resources:
- mutatingwebhookconfigurations
- validatingwebhookconfigurations
verbs:
- create
- get
- list
- patch
- update
- watch
- delete
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: tanzu-cliplugins-package-cluster-rolebinding
annotations:
kapp.k14s.io/change-group: "cliplugins-packageinstall/serviceaccount"
kapp.k14s.io/change-rule.0: "upsert after upserting cliplugins-packageinstall/serviceaccount-0"
kapp.k14s.io/change-rule.1: "delete before deleting cliplugins-packageinstall/serviceaccount-0"
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: tanzu-cliplugins-package-cluster-role
subjects:
- kind: ServiceAccount
name: tanzu-cliplugins-package-sa
namespace: default
1 change: 0 additions & 1 deletion test/e2e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ E2E_TEST_USE_PLGINS_FROM_PLUGIN_GROUP_FOR_K8S ?= vmware-tkg/default:v9.9.9
.PHONY: e2e-cli-core-all ## Execute all CLI Core E2E Tests
e2e-cli-core-all: e2e-cli-lifecycle e2e-cli-config e2e-plugin-compatibility-tests e2e-plugin-lifecycle-tests e2e-plugin-sync-tmc e2e-plugin-sync-k8s e2e-context-tmc-tests e2e-context-k8s-tests e2e-airgapped-tests e2e-catalog-tests e2e-extra-column-tests


.PHONY: e2e-cli-lifecycle ## Execute CLI life cycle specific e2e tests
e2e-cli-lifecycle:
export TANZU_CLI_CEIP_OPT_IN_PROMPT_ANSWER="No" ; \
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/framework/cluster_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type ClusterOps interface {
GetKubeconfigPath() string
// ApplyConfig applies the given configFilePath on to the given contextName cluster context
ApplyConfig(contextName, configFilePath string) (stdOut, stdErr string, err error)
// WaitForCondition waits for certain condition on cluster to be true
WaitForCondition(contextName string, waitArgs []string) (err error)
}

// ClusterInfo holds the general cluster details
Expand Down
9 changes: 9 additions & 0 deletions test/e2e/framework/cluster_kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/pkg/errors"

Expand Down Expand Up @@ -72,6 +73,14 @@ func (kc *kindCluster) ApplyConfig(contextName, configFilePath string) (stdOut,
return stdOutBuff.String(), stdErrBuff.String(), err
}

// WaitForCondition waits for certain condition on cluster to be true or returns error otherwise
func (kc *kindCluster) WaitForCondition(contextName string, waitArgs []string) error {
waitString := strings.Join(waitArgs, " ")
waitCmd := fmt.Sprintf(KubectlWait, contextName, waitString)
_, _, err := kc.CmdOps.Exec(waitCmd)
return err
}

// GetClusterEndpoint returns given kind cluster control plane endpoint
func (kc *kindCluster) GetClusterEndpoint(kindClusterName string) (endpoint, stdOut, stdErr string, err error) {
stdOut, stdErr, err = kc.ContainerRuntimeStatus()
Expand Down
1 change: 1 addition & 0 deletions test/e2e/framework/framework_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const (
KindClusterGet = "kind get clusters "
KindClusterInfo = "kubectl cluster-info --context %s"
KubectlApply = "kubectl --context %s apply -f %s"
KubectlWait = "kubectl --context %s wait %s"

// specific plugin custom resource file name cr_<pluginName>_<target>_<versions>.yaml to apply on kind cluster
PluginCRFileName = "cr_%s_%s_%s.yaml"
Expand Down
Loading

0 comments on commit 96e0ba0

Please sign in to comment.