Skip to content

Commit

Permalink
feat: add helm plugin scaffolding new layout
Browse files Browse the repository at this point in the history
  • Loading branch information
camilamacedo86 committed Jul 3, 2020
1 parent 85663a9 commit 4c409fb
Show file tree
Hide file tree
Showing 78 changed files with 6,783 additions and 424 deletions.
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,25 @@ jobs:
name: Helm on Kubernetes
script: make test-e2e-helm

# Build and test helm for new project layouts
- name: Helm e2e tests for new project layouts
before_install:
# hack/ci/check-doc-only-update.sh needs to be sourced so
# that it can properly exit the test early with success
- source hack/ci/check-doc-only-update.sh
install:
- make install
script:
- make test-e2e-helm-new
after_success:
- echo "E2E tests passed"
after_failure:
- echo "E2E tests failed"
- kubectl get all --all-namespaces
- kubectl get events --all-namespaces --field-selector=type=Warning
services:
- docker

## Image deploy/push stage jobs ##

# Build and deploy arm64 ansible-operator docker image
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,19 @@ test-subcommand-olm-install:
./hack/tests/subcommand-olm-install.sh

# E2E tests.
.PHONY: test-e2e test-e2e-go test-e2e-go-new test-e2e-ansible test-e2e-ansible-molecule test-e2e-helm
.PHONY: test-e2e test-e2e-go test-e2e-go-new test-e2e-helm-new test-e2e-ansible test-e2e-ansible-molecule test-e2e-helm

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

test-e2e-go:
./hack/tests/e2e-go.sh $(ARGS)

test-e2e-go-new:
K8S_VERSION=$(K8S_VERSION) ./hack/tests/e2e-go-new.sh

test-e2e-helm-new:
K8S_VERSION=$(K8S_VERSION) ./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 @@ -30,6 +31,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 @@ -58,4 +60,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

)
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
2 changes: 1 addition & 1 deletion hack/check-license.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ echo "Checking for license header..."
allfiles=$(listFiles)
licRes=""
for file in $allfiles; do
if ! head -n3 "${file}" | grep -Eq "(Copyright|generated|GENERATED)" ; then
if ! head -n3 "${file}" | grep -Eq "(Copyright|generated|GENERATED|Licensed)" ; then
licRes="${licRes}\n"$(echo -e " ${file}")
fi
done
Expand Down
8 changes: 8 additions & 0 deletions hack/lib/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ function build_sdk {
mv ./build/operator-sdk "$1"/bin/operator-sdk
}

# Add kustomize to env
function setup_kustomize {
header_text "getting kustomize"
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
chmod u+x kustomize
mv kustomize "$1"/bin/kustomize
}

# Install the 'kind' binary at version $KIND_VERSION.
function install_kind {

Expand Down
58 changes: 58 additions & 0 deletions hack/tests/e2e-helm-new.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env bash

# remove running containers on exit
function cleanup() {
kind delete cluster
}

set -o errexit
set -o nounset
set -o pipefail

source ./hack/lib/common.sh
source ./hack/lib/test_lib.sh

test_dir=./test
tests=$test_dir/e2e-helm-new

export TRACE=1
export GO111MODULE=on

: ${K8S_VERSION:?"must be set"}

prepare_staging_dir $tmp_sdk_root
fetch_tools $tmp_sdk_root

header_text "###"
header_text "### These envtest environment variables are required for the default unit tests"
header_text "### scaffolded in the test operator project. No e2e tests currently use envtest."
header_text "###"

setup_envs $tmp_sdk_root
build_sdk $tmp_sdk_root
setup_kustomize $tmp_sdk_root

header_text "### Create a cluster of version $K8S_VERSION."

kind create cluster -v 4 --retain --wait=1m \
--config $test_dir/kind-config.yaml \
--image=kindest/node:$K8S_VERSION

kind export kubeconfig

kubectl cluster-info

header_text "###"
header_text "### Building Helm Image"
header_text "###"
make image-build-helm

header_text "###"
header_text "### Loading kubebuilder images"
header_text "###"
docker pull gcr.io/kubebuilder/kube-rbac-proxy:v0.5.0
kind load docker-image gcr.io/kubebuilder/kube-rbac-proxy:v0.5.0

trap_add cleanup EXIT

go test $tests -v -ginkgo.v
56 changes: 56 additions & 0 deletions internal/kubebuilder/cmdutil/cmdutil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
Copyright 2020 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cmdutil

import "sigs.k8s.io/kubebuilder/pkg/plugin/scaffold"

// RunOptions represent the types used to implement the different commands
type RunOptions interface {
// - Step 1: verify that the command can be run (e.g., go version, project version, arguments, ...)
Validate() error
// - Step 2: create the Scaffolder instance
GetScaffolder() (scaffold.Scaffolder, error)
// - Step 3: call the Scaffold method of the Scaffolder instance. Doesn't need any method
// - Step 4: finish the command execution
PostScaffold() error
}

// Run executes a command
func Run(options RunOptions) error {
// Step 1: validate
if err := options.Validate(); err != nil {
return err
}

// Step 2: get scaffolder
scaffolder, err := options.GetScaffolder()
if err != nil {
return err
}
// Step 3: scaffold
if scaffolder != nil {
if err := scaffolder.Scaffold(); err != nil {
return err
}
}
// Step 4: finish
if err := options.PostScaffold(); err != nil {
return err
}

return nil
}
Loading

0 comments on commit 4c409fb

Please sign in to comment.