Skip to content
This repository was archived by the owner on Jan 25, 2019. It is now read-only.

Commit 5a7f6f8

Browse files
authored
Merge pull request #46 from joelanford/controller-runtime
helm-app-operator: transitioning to use controller-runtime
2 parents f904727 + fdf889d commit 5a7f6f8

File tree

19 files changed

+401
-220
lines changed

19 files changed

+401
-220
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ WORKDIR /go/src/github.com/operator-framework/helm-app-operator-kit/helm-app-ope
66
COPY helm-app-operator .
77
RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
88
RUN dep ensure -v
9-
RUN CGO_ENABLED=0 GOOS=linux go build -o bin/operator cmd/helm-app-operator/main.go
9+
RUN CGO_ENABLED=0 GOOS=linux go build -o bin/operator cmd/manager/main.go
1010
RUN chmod +x bin/operator
1111

1212
FROM alpine:3.6

ci.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ RUN ./gofmt.sh
66
RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
77
RUN dep ensure -v
88
RUN go test ./...
9-
RUN CGO_ENABLED=0 GOOS=linux go build -o bin/operator cmd/helm-app-operator/main.go
9+
RUN CGO_ENABLED=0 GOOS=linux go build -o bin/operator cmd/manager/main.go
1010
RUN chmod +x bin/operator

helm-app-operator/Gopkg.lock

Lines changed: 109 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

helm-app-operator/tmp/build/Dockerfile renamed to helm-app-operator/build/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ FROM alpine:3.6
33
RUN adduser -D helm-app-operator
44
USER helm-app-operator
55

6-
ADD tmp/_output/bin/helm-app-operator /usr/local/bin/operator
6+
ADD build/_output/bin/helm-app-operator /usr/local/bin/helm-app-operator

helm-app-operator/tmp/build/build.sh renamed to helm-app-operator/build/build.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ if ! which go > /dev/null; then
99
exit 1
1010
fi
1111

12-
BIN_DIR="$(pwd)/tmp/_output/bin"
12+
BIN_DIR="$(pwd)/build/_output/bin"
1313
mkdir -p ${BIN_DIR}
14-
PROJECT_NAME="helm-app-operator"
15-
REPO_PATH="github.com/operator-framework/helm-app-operator-kit/helm-app-operator"
16-
BUILD_PATH="${REPO_PATH}/cmd/${PROJECT_NAME}"
14+
PROJECT_NAME=helm-app-operator
15+
REPO_PATH=github.com/operator-framework/helm-app-operator-kit/helm-app-operator
16+
BUILD_PATH="${REPO_PATH}/cmd/manager"
1717
echo "building "${PROJECT_NAME}"..."
1818
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o ${BIN_DIR}/${PROJECT_NAME} $BUILD_PATH

helm-app-operator/cmd/helm-app-operator/main.go

Lines changed: 0 additions & 55 deletions
This file was deleted.

helm-app-operator/cmd/manager/main.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"runtime"
6+
"time"
7+
8+
k8sutil "github.com/operator-framework/operator-sdk/pkg/util/k8sutil"
9+
sdkVersion "github.com/operator-framework/operator-sdk/version"
10+
"github.com/sirupsen/logrus"
11+
"k8s.io/helm/pkg/storage"
12+
"k8s.io/helm/pkg/storage/driver"
13+
"sigs.k8s.io/controller-runtime/pkg/client/config"
14+
"sigs.k8s.io/controller-runtime/pkg/manager"
15+
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
16+
17+
"github.com/operator-framework/helm-app-operator-kit/helm-app-operator/pkg/helm"
18+
"github.com/operator-framework/helm-app-operator-kit/helm-app-operator/pkg/helm/controller"
19+
)
20+
21+
func printVersion() {
22+
logrus.Infof("Go Version: %s", runtime.Version())
23+
logrus.Infof("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH)
24+
logrus.Infof("operator-sdk Version: %v", sdkVersion.Version)
25+
}
26+
27+
func main() {
28+
printVersion()
29+
flag.Parse()
30+
31+
namespace, err := k8sutil.GetWatchNamespace()
32+
if err != nil {
33+
logrus.Fatalf("Failed to get watch namespace: %v", err)
34+
}
35+
36+
// TODO: Expose metrics port after SDK uses controller-runtime's dynamic client
37+
// sdk.ExposeMetricsPort()
38+
39+
cfg, err := config.GetConfig()
40+
if err != nil {
41+
logrus.Fatal(err)
42+
}
43+
44+
mgr, err := manager.New(cfg, manager.Options{Namespace: namespace})
45+
if err != nil {
46+
logrus.Fatal(err)
47+
}
48+
49+
logrus.Print("Registering Components.")
50+
51+
// Create Tiller's storage backend and kubernetes client
52+
storageBackend := storage.Init(driver.NewMemory())
53+
tillerKubeClient, err := helm.NewTillerClientFromManager(mgr)
54+
if err != nil {
55+
logrus.Fatal(err)
56+
}
57+
58+
// Dynamically load the helm installer based on the environment
59+
gvk, installer, err := helm.NewInstallerFromEnv(storageBackend, tillerKubeClient)
60+
if err != nil {
61+
logrus.Fatal(err)
62+
}
63+
64+
// Register the controller with the manager.
65+
controller.Add(mgr, controller.WatchOptions{
66+
Namespace: namespace,
67+
GVK: gvk,
68+
Installer: installer,
69+
ResyncPeriod: 5 * time.Second,
70+
})
71+
72+
logrus.Print("Starting the Cmd.")
73+
74+
// Start the Cmd
75+
logrus.Fatal(mgr.Start(signals.SetupSignalHandler()))
76+
}

0 commit comments

Comments
 (0)