Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ jobs:
name: Helm on Kubernetes
script: make test-e2e-helm

# Build and test helm
- <<: *test
name: Helm on Kubernetes (new)
script: make test-e2e-helm-new

## Image deploy/push stage jobs ##

# Build and deploy arm64 ansible-operator docker image
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,14 @@ test-subcommand-olm-install:
# E2E tests.
.PHONY: test-e2e test-e2e-go test-e2e-ansible test-e2e-ansible-molecule test-e2e-helm

test-e2e: test-e2e-go test-e2e-ansible test-e2e-ansible-molecule test-e2e-helm ## Run the e2e tests
test-e2e: test-e2e-go test-e2e-ansible test-e2e-ansible-molecule test-e2e-helm test-e2e-helm-new ## Run the e2e tests

test-e2e-go:
./hack/tests/e2e-go.sh

test-e2e-helm-new: image-build-helm
./hack/tests/e2e-helm-new.sh

test-e2e-ansible: image-build-ansible
./hack/tests/e2e-ansible.sh

Expand Down
2 changes: 2 additions & 0 deletions cmd/operator-sdk/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/version"
"github.com/operator-framework/operator-sdk/internal/flags"
golangv2 "github.com/operator-framework/operator-sdk/internal/plugins/golang/v2"
helmv1 "github.com/operator-framework/operator-sdk/internal/plugins/helm/v1"
"github.com/operator-framework/operator-sdk/internal/util/projutil"

log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -64,6 +65,7 @@ func GetPluginsCLIAndRoot() (cli.CLI, *cobra.Command) {
cli.WithCommandName("operator-sdk"),
cli.WithPlugins(
&golangv2.Plugin{},
&helmv1.Plugin{},
),
cli.WithDefaultPlugins(
&golangv2.Plugin{},
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ require (
github.com/go-logr/logr v0.1.0
github.com/go-logr/zapr v0.1.1
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/iancoleman/strcase v0.0.0-20190422225806-e506e3ef7365
github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334
github.com/kr/text v0.1.0
github.com/markbates/inflect v1.0.4
github.com/mattn/go-isatty v0.0.12
github.com/mitchellh/go-homedir v1.1.0
Expand All @@ -28,6 +29,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.4.0
github.com/stretchr/testify v1.5.1
github.com/xenolf/lego v2.7.2+incompatible
go.uber.org/zap v1.14.1
golang.org/x/net v0.0.0-20200301022130-244492dfa37a
golang.org/x/tools v0.0.0-20200403190813-44a64ad78b9b
Expand Down Expand Up @@ -55,4 +57,5 @@ replace (
github.com/Azure/go-autorest => github.com/Azure/go-autorest v13.3.2+incompatible // Required by OLM
github.com/mattn/go-sqlite3 => github.com/mattn/go-sqlite3 v1.10.0
k8s.io/client-go => k8s.io/client-go v0.18.2

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you run make tidy before committing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make tidy do not remove the space. But I fixed that 👍 Tks.

)
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,8 @@ github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huandu/xstrings v1.3.1 h1:4jgBlKK6tLKFvO8u5pmYjG91cqytmDCDvGh7ECVFfFs=
github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/iancoleman/strcase v0.0.0-20190422225806-e506e3ef7365 h1:ECW73yc9MY7935nNYXUkK7Dz17YuSUI9yqRqYS8aBww=
github.com/iancoleman/strcase v0.0.0-20190422225806-e506e3ef7365/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE=
github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334 h1:VHgatEHNcBFEB7inlalqfNqw65aNkM1lGX2yt3NmbS8=
github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE=
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
Expand Down Expand Up @@ -927,6 +927,8 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:
github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs=
github.com/xeipuuv/gojsonschema v1.1.0 h1:ngVtJC9TY/lg0AA/1k48FYhBrhRoFlEmWzsehpNAaZg=
github.com/xeipuuv/gojsonschema v1.1.0/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs=
github.com/xenolf/lego v2.7.2+incompatible h1:aGxxYqhnQLQ71HsvEAjJVw6ao14APwPpRk0mpFroPXk=
github.com/xenolf/lego v2.7.2+incompatible/go.mod h1:fwiGnfsIjG7OHPfOvgK7Y/Qo6+2Ox0iozjNTkZICKbY=
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xlab/handysort v0.0.0-20150421192137-fb3537ed64a1/go.mod h1:QcJo0QPSfTONNIgpN5RA8prR7fF8nkF6cTWTcNerRO8=
Expand Down
156 changes: 156 additions & 0 deletions hack/tests/e2e-helm-new.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#!/usr/bin/env bash
Copy link
Member

@estroz estroz Jul 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC we want to add all new e2e tests as ginkgo/gomega suites. Perhaps that is too much extra code for this PR which is already large, so at least do this in a follow-up if that's how we want to proceed with e2e tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @estroz,

The first version was with the tests done in go like you wish 👍 . However, @joelanford asked for we keep here the same tests in the shell just for we ensure now that all is 100% then we can do a follow with the go tests as well.


set -eux

source hack/lib/test_lib.sh
source hack/lib/image_lib.sh

DEST_IMAGE="quay.io/example/nginx-operator:v0.0.2"
TMPDIR="$(mktemp -d)"
trap_add 'rm -rf $TMPDIR' EXIT

test_namespace="nginx-operator-system"

remove_operator() {
make undeploy
kubectl delete --ignore-not-found namespace ${test_namespace}
}

test_operator() {
# kind has an issue with certain image registries (ex. redhat's), so use a
# different test pod image.
local metrics_test_image="fedora:latest"

# wait for operator pod to run
if ! timeout 1m kubectl rollout status deployment.apps/nginx-operator-controller-manager -n ${test_namespace} ;
then
kubectl get events --namespace=${test_namespace}
kubectl logs deployment.apps/nginx-operator-controller-manager -c manager --namespace=${test_namespace}
exit 1
fi

# verify that metrics service was created
if ! timeout 60s bash -c -- "until kubectl get service/nginx-operator-metrics --namespace=${test_namespace} > /dev/null 2>&1; do sleep 1; done";
then
echo "Failed to get metrics service"
kubectl get events --namespace=${test_namespace}
kubectl logs deployment.apps/nginx-operator-controller-manager -c manager --namespace=${test_namespace}
exit 1
fi

# give permissions to reach the metrics endpoint
kubectl create clusterrolebinding nginx-operator-system-metrics-reader --clusterrole=nginx-operator-metrics-reader --serviceaccount=nginx-operator-system:default

# verify that the metrics endpoint exists
if ! timeout 1m bash -c -- "until kubectl run --attach --rm --restart=Never --namespace=${test_namespace} test-metrics --image=${metrics_test_image} -- curl -sfo /dev/null -v -s -k -H Authorization: Bearer `cat /var/run/secrets/kubernetes.io/serviceaccount/token` https://nginx-operator-controller-manager-metrics-service:8443/metrics; do sleep 1; done";
then
echo "Failed to verify that metrics endpoint exists"
kubectl get events --namespace=${test_namespace}
kubectl logs deployment.apps/nginx-operator-controller-manager -c manager --namespace=${test_namespace}
exit 1
fi

# create CR
kubectl create --namespace=${test_namespace} -f config/samples/example_v1alpha1_nginx.yaml
trap_add "kubectl delete --namespace=${test_namespace} --ignore-not-found -f ${OPERATORDIR}/config/samples/example_v1alpha1_nginx.yaml" EXIT
if ! timeout 1m bash -c -- "until kubectl get --namespace=${test_namespace} Nginx nginx-sample -o jsonpath='{..status.deployedRelease.name}' | grep 'nginx-sample'; do sleep 1; done";
then
kubectl get events --namespace=${test_namespace}
kubectl logs deployment.apps/nginx-operator-controller-manager -c manager --namespace=${test_namespace}
exit 1
fi

# verify that the custom resource metrics endpoint exists
if ! timeout 1m bash -c -- "until kubectl run --attach --rm --restart=Never test-cr-metrics --image=${metrics_test_image} -- curl -sfo /dev/null http://nginx-operator-metrics:8686/metrics; do sleep 1; done";
then
echo "Failed to verify that custom resource metrics endpoint exists"
kubectl logs deployment/nginx-operator
exit 1
fi

header_text "verify that the servicemonitor is created"
if ! timeout 1m bash -c -- "until kubectl get servicemonitors/nginx-operator-metrics --namespace=${test_namespace} > /dev/null 2>&1; do sleep 1; done";
then
error_text "FAIL: Failed to get service monitor"
kubectl get events --namespace=${test_namespace}
kubectl logs deployment.apps/nginx-operator-controller-manager -c manager --namespace=${test_namespace}
exit 1
fi

release_name=$(kubectl get --namespace=${test_namespace} Nginx nginx-sample -o jsonpath="{..status.deployedRelease.name}")
nginx_deployment=$(kubectl get --namespace=${test_namespace} deployments -l "app.kubernetes.io/instance=${release_name}" -o jsonpath="{..metadata.name}")

if ! timeout 1m kubectl rollout --namespace=${test_namespace} status deployment.apps/${nginx_deployment};
then
kubectl get events --namespace=${test_namespace}
kubectl describe --namespace=${test_namespace} pods -l "app.kubernetes.io/instance=${release_name}"
kubectl describe --namespace=${test_namespace} deployments ${nginx_deployment}
kubectl logs deployment.apps/nginx-operator-controller-manager -c manager
exit 1
fi

nginx_service=$(kubectl get --namespace=${test_namespace} service -l "app.kubernetes.io/instance=${release_name}" -o jsonpath="{..metadata.name}")
kubectl get --namespace=${test_namespace} service ${nginx_service}

# scale deployment replicas to 2 and verify the
# deployment automatically scales back down to 1.
kubectl scale --namespace=${test_namespace} deployment.apps/${nginx_deployment} --replicas=2
if ! timeout 1m bash -c -- "until test \$(kubectl get --namespace=${test_namespace} deployment/${nginx_deployment} -o jsonpath='{..spec.replicas}') -eq 1; do sleep 1; done";
then
kubectl get events --namespace=${test_namespace}
kubectl describe --namespace=${test_namespace} pods -l "app.kubernetes.io/instance=${release_name}"
kubectl describe --namespace=${test_namespace} deployments ${nginx_deployment}
kubectl logs deployment.apps/nginx-operator-controller-manager -c manager --namespace=${test_namespace}
exit 1
fi

# update CR to replicaCount=2 and verify the deployment
# automatically scales up to 2 replicas.
kubectl patch --namespace=${test_namespace} Nginx nginx-sample -p '[{"op":"replace","path":"/spec/replicaCount","value":2}]' --type=json
if ! timeout 1m bash -c -- "until test \$(kubectl get --namespace=${test_namespace} deployment/${nginx_deployment} -o jsonpath='{..spec.replicas}') -eq 2; do sleep 1; done";
then
kubectl get events --namespace=${test_namespace}
kubectl describe --namespace=${test_namespace} pods -l "app.kubernetes.io/instance=${release_name}"
kubectl describe --namespace=${test_namespace} deployments ${nginx_deployment}
kubectl logs deployment.apps/nginx-operator-controller-manager -c manager --namespace=${test_namespace}
exit 1
fi

kubectl delete --namespace=${test_namespace} -f config/samples/example_v1alpha1_nginx.yaml --wait=true
kubectl logs deployment.apps/nginx-operator-controller-manager -c manager --namespace=${test_namespace} | grep "Uninstalled release" | grep "${release_name}"
}

# create and build the operator

mkdir nginx-operator
cd nginx-operator
log=$(operator-sdk init --plugins=helm.operator-sdk.io/v1 \
--domain=com --group=example --version=v1alpha1 --kind=Nginx \
2>&1)
echo $log
if echo $log | grep -q "failed to generate RBAC rules"; then
echo FAIL expected successful generation of RBAC rules
exit 1
fi

install_service_monitor_crd

sed -i".bak" -E -e 's/(FROM quay.io\/operator-framework\/helm-operator)(:.*)?/\1:dev/g' Dockerfile; rm -f Dockerfile.bak
make docker-build IMG="$DEST_IMAGE"

# If using a kind cluster, load the image into all nodes.
load_image_if_kind "$DEST_IMAGE"

make install
make deploy IMG="$DEST_IMAGE"
OPERATORDIR="$(pwd)"

# kind has an issue with certain image registries (ex. redhat's), so use a
# different test pod image.
METRICS_TEST_IMAGE="fedora:latest"
docker pull "$METRICS_TEST_IMAGE"
# If using a kind cluster, load the metrics test image into all nodes.
load_image_if_kind "$METRICS_TEST_IMAGE"

trap_add 'remove_operator' EXIT
test_operator
111 changes: 0 additions & 111 deletions internal/plugins/helm/api.go

This file was deleted.

Loading