Skip to content

Commit e3bd72e

Browse files
authored
Add test that hybrid helm plugin compiles + successfully scaffolds code (#103)
* Add build step for SDK to github action * Create APIs for hybrid plugin test
1 parent f47861f commit e3bd72e

File tree

3 files changed

+118
-1
lines changed

3 files changed

+118
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
/bin
33
/tools/bin
44
/dist
5+
/build
6+
/tmp
57

68
# Other IDE files
79
.idea

Makefile

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,37 @@ all: test lint build
3838
ENVTEST_VERSION = $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\+\)\.[[:digit:]]\+$$/1.\1.x/')
3939
TESTPKG ?= ./...
4040
# TODO: Modify this to use setup-envtest binary
41-
test:
41+
test: test-hybrid-plugin
4242
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
4343
source <(setup-envtest use -p env $(ENVTEST_VERSION)) && go test -race -covermode atomic -coverprofile cover.out $(TESTPKG)
4444

45+
test-hybrid-plugin: remove-tmp build/operator-sdk
46+
mkdir -p tmp/test-hybrid-operator
47+
(cd tmp/test-hybrid-operator && \
48+
../../build/operator-sdk init --plugins hybrid --domain example.com --repo example.com/example/example-operator && \
49+
../../build/operator-sdk create api --plugins go.kubebuilder.io/v3 --group apps --version v1alpha1 --kind=MemcachedBackup --resource --controller && \
50+
../../build/operator-sdk create api --plugins helm.sdk.operatorframework.io/v1 --helm-chart=memcached --helm-chart-repo=https://charts.bitnami.com/bitnami --group apps --version v1alpha1 --kind=Memcached && \
51+
make docker-build)
52+
4553
# Build manager binary
4654
.PHONY: build
4755
build:
4856
CGO_ENABLED=0 mkdir -p $(BUILD_DIR) && go build $(GO_BUILD_ARGS) -o $(BUILD_DIR) ./
4957

58+
# Incredibly fragile nad hopefully temporary build step for the SDK binary
59+
build/operator-sdk:
60+
mkdir -p tmp
61+
git clone https://github.com/operator-framework/operator-sdk.git tmp/operator-sdk-hybrid-patched
62+
cp hack/osdk.patch tmp/operator-sdk-hybrid-patched/
63+
(cd tmp/operator-sdk-hybrid-patched && git apply osdk.patch)
64+
sed -i".bak" "s|REPLACE_ME_WITH_PATH|$(shell pwd)|" tmp/operator-sdk-hybrid-patched/go.mod
65+
(cd tmp/operator-sdk-hybrid-patched && go mod tidy && make build/operator-sdk)
66+
mkdir -p build
67+
cp tmp/operator-sdk-hybrid-patched/build/operator-sdk ./build/operator-sdk
68+
69+
remove-tmp:
70+
rm -rf tmp/
71+
5072
# Run go fmt and go mod tidy, and check for clean git tree
5173
.PHONY: fix
5274
fix:

hack/osdk.patch

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
diff --git a/go.mod b/go.mod
2+
index 12ba033a..2a1aeaa7 100644
3+
--- a/go.mod
4+
+++ b/go.mod
5+
@@ -7,13 +7,14 @@ require (
6+
github.com/fatih/structtag v1.1.0
7+
github.com/go-logr/logr v0.4.0
8+
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0
9+
- github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334
10+
+ github.com/iancoleman/strcase v0.1.2
11+
github.com/kr/text v0.2.0
12+
github.com/markbates/inflect v1.0.4
13+
github.com/maxbrunsfeld/counterfeiter/v6 v6.2.2
14+
github.com/onsi/ginkgo v1.16.4
15+
github.com/onsi/gomega v1.13.0
16+
github.com/operator-framework/api v0.10.5
17+
+ github.com/operator-framework/helm-operator-plugins v0.0.8-0.20210825183301-ae6656410e15
18+
github.com/operator-framework/java-operator-plugins v0.0.0-20210708174638-463fb91f3d5e
19+
github.com/operator-framework/operator-lib v0.6.0
20+
github.com/operator-framework/operator-registry v1.17.4
21+
@@ -54,6 +55,8 @@ replace (
22+
github.com/docker/distribution => github.com/docker/distribution v0.0.0-20191216044856-a8371794149d
23+
github.com/mattn/go-sqlite3 => github.com/mattn/go-sqlite3 v1.10.0
24+
golang.org/x/text => golang.org/x/text v0.3.3 // Required to fix CVE-2020-14040
25+
+
26+
+ github.com/operator-framework/helm-operator-plugins => REPLACE_ME_WITH_PATH
27+
)
28+
29+
exclude github.com/spf13/viper v1.3.2 // Required to fix CVE-2018-1098
30+
diff --git a/internal/cmd/operator-sdk/cli/cli.go b/internal/cmd/operator-sdk/cli/cli.go
31+
index 0f4e5f69..cce04188 100644
32+
--- a/internal/cmd/operator-sdk/cli/cli.go
33+
+++ b/internal/cmd/operator-sdk/cli/cli.go
34+
@@ -26,6 +26,7 @@ import (
35+
kustomizev1 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/common/kustomize/v1"
36+
declarativev1 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/declarative/v1"
37+
38+
+ "sigs.k8s.io/kubebuilder/v3/pkg/model/stage"
39+
"sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang"
40+
golangv2 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v2"
41+
golangv3 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v3"
42+
@@ -46,6 +47,8 @@ import (
43+
manifestsv2 "github.com/operator-framework/operator-sdk/internal/plugins/manifests/v2"
44+
scorecardv2 "github.com/operator-framework/operator-sdk/internal/plugins/scorecard/v2"
45+
"github.com/operator-framework/operator-sdk/internal/util/projutil"
46+
+
47+
+ hybrid "github.com/operator-framework/helm-operator-plugins/pkg/plugins/hybrid/v1alpha"
48+
)
49+
50+
var (
51+
@@ -98,6 +101,12 @@ func GetPluginsCLIAndRoot() (*cli.CLI, *cobra.Command) {
52+
manifestsv2.Plugin{},
53+
scorecardv2.Plugin{},
54+
)
55+
+ hybridHelmBundle, _ := plugin.NewBundle("hybrid.helm"+plugins.DefaultNameQualifier, plugin.Version{Number: 1, Stage: stage.Alpha},
56+
+ kustomizev1.Plugin{},
57+
+ hybrid.Plugin{},
58+
+ manifestsv2.Plugin{},
59+
+ scorecardv2.Plugin{},
60+
+ )
61+
c, err := cli.New(
62+
cli.WithCommandName("operator-sdk"),
63+
cli.WithVersion(makeVersionString()),
64+
@@ -106,6 +115,7 @@ func GetPluginsCLIAndRoot() (*cli.CLI, *cobra.Command) {
65+
gov2Bundle,
66+
gov3Bundle,
67+
helmBundle,
68+
+ hybridHelmBundle,
69+
kustomizev1.Plugin{},
70+
declarativev1.Plugin{},
71+
&quarkusv1.Plugin{},
72+
diff --git a/internal/util/projutil/project_util.go b/internal/util/projutil/project_util.go
73+
index af0db0e4..966afd35 100644
74+
--- a/internal/util/projutil/project_util.go
75+
+++ b/internal/util/projutil/project_util.go
76+
@@ -55,6 +55,8 @@ const (
77+
OperatorTypeAnsible OperatorType = "ansible"
78+
// OperatorTypeHelm - helm type of operator.
79+
OperatorTypeHelm OperatorType = "helm"
80+
+ // OperatorTypeHybridHelm - hybrid helm type of operator.
81+
+ OperatorTypeHybridHelm OperatorType = "hybrid.helm"
82+
// OperatorTypeUnknown - unknown type of operator.
83+
OperatorTypeUnknown OperatorType = "unknown"
84+
)
85+
@@ -103,6 +105,8 @@ func PluginChainToOperatorType(pluginKeys []string) OperatorType {
86+
return OperatorTypeGo
87+
case strings.HasPrefix(pluginKey, "helm"):
88+
return OperatorTypeHelm
89+
+ case strings.HasPrefix(pluginKey, "hybrid.helm"):
90+
+ return OperatorTypeHybridHelm
91+
case strings.HasPrefix(pluginKey, "ansible"):
92+
return OperatorTypeAnsible
93+
}

0 commit comments

Comments
 (0)