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

helm-app-operator: transitioning to use controller-runtime #46

Merged
merged 4 commits into from
Oct 11, 2018
Merged
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ WORKDIR /go/src/github.com/operator-framework/helm-app-operator-kit/helm-app-ope
COPY helm-app-operator .
RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
RUN dep ensure -v
RUN CGO_ENABLED=0 GOOS=linux go build -o bin/operator cmd/helm-app-operator/main.go
RUN CGO_ENABLED=0 GOOS=linux go build -o bin/operator cmd/manager/main.go
RUN chmod +x bin/operator

FROM alpine:3.6
Expand Down
2 changes: 1 addition & 1 deletion ci.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ RUN ./gofmt.sh
RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
RUN dep ensure -v
RUN go test ./...
RUN CGO_ENABLED=0 GOOS=linux go build -o bin/operator cmd/helm-app-operator/main.go
RUN CGO_ENABLED=0 GOOS=linux go build -o bin/operator cmd/manager/main.go
RUN chmod +x bin/operator
119 changes: 109 additions & 10 deletions helm-app-operator/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ FROM alpine:3.6
RUN adduser -D helm-app-operator
USER helm-app-operator

ADD tmp/_output/bin/helm-app-operator /usr/local/bin/operator
ADD build/_output/bin/helm-app-operator /usr/local/bin/helm-app-operator
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ if ! which go > /dev/null; then
exit 1
fi

BIN_DIR="$(pwd)/tmp/_output/bin"
BIN_DIR="$(pwd)/build/_output/bin"
mkdir -p ${BIN_DIR}
PROJECT_NAME="helm-app-operator"
REPO_PATH="github.com/operator-framework/helm-app-operator-kit/helm-app-operator"
BUILD_PATH="${REPO_PATH}/cmd/${PROJECT_NAME}"
PROJECT_NAME=helm-app-operator
REPO_PATH=github.com/operator-framework/helm-app-operator-kit/helm-app-operator
BUILD_PATH="${REPO_PATH}/cmd/manager"
echo "building "${PROJECT_NAME}"..."
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o ${BIN_DIR}/${PROJECT_NAME} $BUILD_PATH
55 changes: 0 additions & 55 deletions helm-app-operator/cmd/helm-app-operator/main.go

This file was deleted.

76 changes: 76 additions & 0 deletions helm-app-operator/cmd/manager/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package main

import (
"flag"
"runtime"
"time"

k8sutil "github.com/operator-framework/operator-sdk/pkg/util/k8sutil"
sdkVersion "github.com/operator-framework/operator-sdk/version"
"github.com/sirupsen/logrus"
"k8s.io/helm/pkg/storage"
"k8s.io/helm/pkg/storage/driver"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"

"github.com/operator-framework/helm-app-operator-kit/helm-app-operator/pkg/helm"
"github.com/operator-framework/helm-app-operator-kit/helm-app-operator/pkg/helm/controller"
)

func printVersion() {
logrus.Infof("Go Version: %s", runtime.Version())
logrus.Infof("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH)
logrus.Infof("operator-sdk Version: %v", sdkVersion.Version)
}

func main() {
printVersion()
flag.Parse()

namespace, err := k8sutil.GetWatchNamespace()
if err != nil {
logrus.Fatalf("Failed to get watch namespace: %v", err)
}

// TODO: Expose metrics port after SDK uses controller-runtime's dynamic client
// sdk.ExposeMetricsPort()

cfg, err := config.GetConfig()
if err != nil {
logrus.Fatal(err)
}

mgr, err := manager.New(cfg, manager.Options{Namespace: namespace})
if err != nil {
logrus.Fatal(err)
}

logrus.Print("Registering Components.")

// Create Tiller's storage backend and kubernetes client
storageBackend := storage.Init(driver.NewMemory())
tillerKubeClient, err := helm.NewTillerClientFromManager(mgr)
if err != nil {
logrus.Fatal(err)
}

// Dynamically load the helm installer based on the environment
gvk, installer, err := helm.NewInstallerFromEnv(storageBackend, tillerKubeClient)
if err != nil {
logrus.Fatal(err)
}

// Register the controller with the manager.
controller.Add(mgr, controller.WatchOptions{
Namespace: namespace,
GVK: gvk,
Installer: installer,
ResyncPeriod: 5 * time.Second,
})

logrus.Print("Starting the Cmd.")

// Start the Cmd
logrus.Fatal(mgr.Start(signals.SetupSignalHandler()))
}
Loading