Skip to content

(Rebased disc)^2 #1468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Apr 22, 2020
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
23 changes: 14 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ endif
SHELL := /bin/bash
ORG := github.com/operator-framework
PKG := $(ORG)/operator-lifecycle-manager
OS := $(shell go env GOOS)
ARCH := $(shell go env GOARCH)
MOD_FLAGS := $(shell (go version | grep -q -E "1\.1[1-9]") && echo -mod=vendor)
CMDS := $(shell go list $(MOD_FLAGS) ./cmd/...)
TCMDS := $(shell go list $(MOD_FLAGS) ./test/e2e/...)
Expand All @@ -25,6 +23,7 @@ LOCAL_NAMESPACE := "olm"
export GO111MODULE=on
CONTROLLER_GEN := go run $(MOD_FLAGS) ./vendor/sigs.k8s.io/controller-tools/cmd/controller-gen
YQ_INTERNAL := go run $(MOD_FLAGS) ./vendor/github.com/mikefarah/yq/v2/
KUBEBUILDER_ASSETS ?= /usr/local/kubebuilder/bin

# ART builds are performed in dist-git, with content (but not commits) copied
# from the source repo. Thus at build time if your code is inspecting the local
Expand All @@ -36,21 +35,27 @@ YQ_INTERNAL := go run $(MOD_FLAGS) ./vendor/github.com/mikefarah/yq/v2/
GIT_COMMIT := $(if $(SOURCE_GIT_COMMIT),$(SOURCE_GIT_COMMIT),$(shell git rev-parse HEAD))

.PHONY: build test run clean vendor schema-check \
vendor-update coverage coverage-html e2e .FORCE
vendor-update coverage coverage-html e2e \
kubebuilder .FORCE

all: test build

test: clean cover.out

unit: kubebuilder
$(KUBEBUILDER_ENV) go test $(MOD_FLAGS) $(SPECIFIC_UNIT_TEST) -v -race -count=1 ./pkg/...
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test $(MOD_FLAGS) $(SPECIFIC_UNIT_TEST) -v -race -count=1 ./pkg/...

# Install kubebuilder if not found
KUBEBUILDER_DIR := /tmp/kubebuilder_2.3.1_$(OS)_$(ARCH)/bin
# Ensure kubebuilder is installed before continuing
KUBEBUILDER_ASSETS_ERR := not detected in $(KUBEBUILDER_ASSETS), to override the assets path set the KUBEBUILDER_ASSETS environment variable, for install instructions see https://book.kubebuilder.io/quick-start.html
kubebuilder:
ifeq (, $(shell which kubebuilder))
[ ! -d "$(KUBEBUILDER_DIR)" ] && (curl -sL https://go.kubebuilder.io/dl/2.3.1/$(OS)/$(ARCH) | tar -xz -C /tmp/)
KUBEBUILDER_ENV := KUBEBUILDER_ASSETS=$(KUBEBUILDER_DIR)
ifeq (, $(wildcard $(KUBEBUILDER_ASSETS)/kubebuilder))
$(error kubebuilder $(KUBEBUILDER_ASSETS_ERR))
endif
ifeq (, $(wildcard $(KUBEBUILDER_ASSETS)/etcd))
$(error etcd $(KUBEBUILDER_ASSETS_ERR))
endif
ifeq (, $(wildcard $(KUBEBUILDER_ASSETS)/kube-apiserver))
$(error kube-apiserver $(KUBEBUILDER_ASSETS_ERR))
endif

schema-check:
Expand Down
70 changes: 39 additions & 31 deletions cmd/olm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"crypto/tls"
"flag"
"fmt"
"net/http"
"os"
Expand All @@ -12,18 +11,19 @@ import (

configclientset "github.com/openshift/client-go/config/clientset/versioned"
configv1client "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/queueinformer"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
v1 "k8s.io/api/core/v1"
"k8s.io/client-go/tools/clientcmd"

"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client"
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/olm"
"github.com/operator-framework/operator-lifecycle-manager/pkg/feature"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/filemonitor"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorstatus"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/profile"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/queueinformer"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/signals"
"github.com/operator-framework/operator-lifecycle-manager/pkg/metrics"
olmversion "github.com/operator-framework/operator-lifecycle-manager/pkg/version"
Expand All @@ -37,53 +37,53 @@ const (

// config flags defined globally so that they appear on the test binary as well
var (
kubeConfigPath = flag.String(
"kubeconfig", "", "absolute path to the kubeconfig file")

wakeupInterval = flag.Duration(
wakeupInterval = pflag.Duration(
"interval", defaultWakeupInterval, "wake up interval")

watchedNamespaces = flag.String(
watchedNamespaces = pflag.String(
"watchedNamespaces", "", "comma separated list of namespaces for olm operator to watch. "+
"If not set, or set to the empty string (e.g. `-watchedNamespaces=\"\"`), "+
"olm operator will watch all namespaces in the cluster.")

writeStatusName = flag.String(
writeStatusName = pflag.String(
"writeStatusName", defaultOperatorName, "ClusterOperator name in which to write status, set to \"\" to disable.")

writePackageServerStatusName = flag.String(
writePackageServerStatusName = pflag.String(
"writePackageServerStatusName", defaultPackageServerStatusName, "ClusterOperator name in which to write status for package API server, set to \"\" to disable.")

debug = flag.Bool(
debug = pflag.Bool(
"debug", false, "use debug log level")

version = flag.Bool("version", false, "displays olm version")
version = pflag.Bool("version", false, "displays olm version")

tlsKeyPath = flag.String(
tlsKeyPath = pflag.String(
"tls-key", "", "Path to use for private key (requires tls-cert)")

tlsCertPath = flag.String(
tlsCertPath = pflag.String(
"tls-cert", "", "Path to use for certificate key (requires tls-key)")

profiling = flag.Bool(
profiling = pflag.Bool(
"profiling", false, "serve profiling data (on port 8080)")

namespace = flag.String(
namespace = pflag.String(
"namespace", "", "namespace where cleanup runs")
)

func init() {
metrics.RegisterOLM()

// Add feature gates before parsing
feature.AddFlag(pflag.CommandLine)
}

// main function - entrypoint to OLM operator
func main() {
// Get exit signal context
ctx, cancel := context.WithCancel(signals.Context())
defer cancel()
pflag.Parse()

// Parse the command-line flags.
flag.Parse()

// Check if version flag was set
if *version {
Expand All @@ -104,9 +104,9 @@ func main() {
}

// Set log level to debug if `debug` flag set
logger := log.New()
logger := logrus.New()
if *debug {
logger.SetLevel(log.DebugLevel)
logger.SetLevel(logrus.DebugLevel)
}
logger.Infof("log level %s", logger.Level)

Expand Down Expand Up @@ -169,24 +169,27 @@ func main() {
}()
}

// create a config client for operator status
config, err := clientcmd.BuildConfigFromFlags("", *kubeConfigPath)
mgr, err := Manager(ctx)
if err != nil {
log.Fatalf("error configuring client: %s", err.Error())
logger.WithError(err).Fatalf("error configuring controller manager")
}
config := mgr.GetConfig()

versionedConfigClient, err := configclientset.NewForConfig(config)
if err != nil {
err = fmt.Errorf("error configuring OpenShift Proxy client: %v", err)
return
logger.WithError(err).Fatal("error configuring openshift proxy client")
}
configClient, err := configv1client.NewForConfig(config)
if err != nil {
log.Fatalf("error configuring client: %s", err.Error())
logger.WithError(err).Fatal("error configuring config client")
}
opClient, err := operatorclient.NewClientFromRestConfig(config)
if err != nil {
logger.WithError(err).Fatal("error configuring operator client")
}
opClient := operatorclient.NewClientFromConfig(*kubeConfigPath, logger)
crClient, err := client.NewClient(*kubeConfigPath)
crClient, err := versioned.NewForConfig(config)
if err != nil {
log.Fatalf("error configuring client: %s", err.Error())
logger.WithError(err).Fatal("error configuring custom resource client")
}

cleanup(logger, opClient, crClient)
Expand All @@ -203,7 +206,7 @@ func main() {
olm.WithConfigClient(versionedConfigClient),
)
if err != nil {
log.WithError(err).Fatalf("error configuring operator")
logger.WithError(err).Fatalf("error configuring operator")
return
}

Expand All @@ -227,5 +230,10 @@ func main() {
go monitor.Run(op.Done())
}

// Start the controller manager
if err := mgr.Start(ctx.Done()); err != nil {
logger.WithError(err).Fatal("controller manager stopped")
}

<-op.Done()
}
76 changes: 76 additions & 0 deletions cmd/olm/manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package main

import (
"context"
"fmt"

"github.com/operator-framework/api/crds"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators"
"github.com/operator-framework/operator-lifecycle-manager/pkg/feature"
)

var log = ctrl.Log.WithName("manager")

func Manager(ctx context.Context) (ctrl.Manager, error) {
ctrl.SetLogger(zap.Logger(true))
setupLog := log.WithName("setup").V(4)

// Setup a Manager
setupLog.Info("configuring manager")
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{MetricsBindAddress: "0"}) // TODO(njhale): Enable metrics on non-conflicting port (not 8080)
if err != nil {
return nil, err
}

// Setup a new controller to reconcile Operators
setupLog.Info("configuring controller")
client, err := apiextensionsv1.NewForConfig(mgr.GetConfig())
if err != nil {
return nil, err
}

if feature.Gate.Enabled(feature.OperatorLifecycleManagerV2) {
setupLog.Info(fmt.Sprintf("feature enabled: %v", feature.OperatorLifecycleManagerV2))

reconciler, err := operators.NewOperatorReconciler(
mgr.GetClient(),
ctrl.Log.WithName("controllers").WithName("operator"),
mgr.GetScheme(),
)
if err != nil {
return nil, err
}

crd, err := client.CustomResourceDefinitions().Create(ctx, crds.Operator(), metav1.CreateOptions{})
if err != nil {
if !apierrors.IsAlreadyExists(err) {
return nil, err
}

// Already exists, try to update
if crd, err = client.CustomResourceDefinitions().Get(ctx, crds.Operator().GetName(), metav1.GetOptions{}); err != nil {
return nil, err
}

crd.Spec = crds.Operator().Spec
if _, err = client.CustomResourceDefinitions().Update(ctx, crd, metav1.UpdateOptions{}); err != nil {
return nil, err
}
}
setupLog.Info("v2alpha1 CRDs installed")

if err = reconciler.SetupWithManager(mgr); err != nil {
return nil, err
}
}

setupLog.Info("manager configured")

return mgr, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,32 @@ spec:
command:
- /bin/olm
args:
- -namespace
- --namespace
- $(OPERATOR_NAMESPACE)
{{- if .Values.watchedNamespaces }}
- -watchedNamespaces
- --watchedNamespaces
- {{ .Values.watchedNamespaces }}
{{- end }}
{{- if .Values.olm.commandArgs }}
- {{ .Values.olm.commandArgs }}
{{- end }}
{{- if .Values.debug }}
- -debug
- --debug
{{- end }}
{{- if .Values.writeStatusName }}
- -writeStatusName
- --writeStatusName
- {{ .Values.writeStatusName }}
{{- end }}
{{- if .Values.writePackageServerStatusName }}
- -writePackageServerStatusName
- --writePackageServerStatusName
- {{ .Values.writePackageServerStatusName }}
{{- end }}
{{- if .Values.olm.tlsCertPath }}
- -tls-cert
- --tls-cert
- {{ .Values.olm.tlsCertPath }}
{{- end }}
{{- if .Values.olm.tlsKeyPath }}
- -tls-key
- --tls-key
- {{ .Values.olm.tlsKeyPath }}
{{- end }}
image: {{ .Values.olm.image.ref }}
Expand Down
9 changes: 8 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ require (
github.com/fsnotify/fsnotify v1.4.7
github.com/ghodss/yaml v1.0.0
github.com/go-bindata/go-bindata/v3 v3.1.3
github.com/go-logr/logr v0.1.0
github.com/go-openapi/spec v0.19.4
github.com/golang/mock v1.3.1
github.com/google/go-cmp v0.4.0
github.com/irifrance/gini v1.0.1
github.com/maxbrunsfeld/counterfeiter/v6 v6.2.2
github.com/mikefarah/yq/v2 v2.4.1
github.com/mitchellh/hashstructure v1.0.0
github.com/mitchellh/mapstructure v1.1.2
github.com/onsi/ginkgo v1.12.0
github.com/onsi/gomega v1.9.0
github.com/openshift/api v0.0.0-20200331152225-585af27e34fd
Expand All @@ -27,7 +29,9 @@ require (
github.com/prometheus/client_golang v1.2.1
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.5.1
github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0
golang.org/x/time v0.0.0-20191024005414-555d28b269f0
google.golang.org/grpc v1.27.0
gopkg.in/yaml.v2 v2.2.8
Expand All @@ -43,6 +47,7 @@ require (
k8s.io/kube-aggregator v0.18.0
k8s.io/kube-openapi v0.0.0-20200121204235-bf4fb3bd569c
rsc.io/letsencrypt v0.0.3 // indirect
sigs.k8s.io/controller-runtime v0.5.2
sigs.k8s.io/controller-tools v0.2.8
sigs.k8s.io/kind v0.7.0
)
Expand All @@ -52,12 +57,14 @@ replace (
github.com/docker/docker => github.com/moby/moby v0.7.3-0.20190826074503-38ab9da00309 // Required by Helm
github.com/openshift/api => github.com/openshift/api v0.0.0-20200331152225-585af27e34fd // release-4.5
github.com/openshift/client-go => github.com/openshift/client-go v0.0.0-20200326155132-2a6cd50aedd0 // release-4.5

github.com/operator-framework/api => github.com/operator-framework/api v0.3.1
github.com/prometheus/client_golang => github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829
google.golang.org/grpc => google.golang.org/grpc v1.26.0 // https://github.com/etcd-io/etcd/issues/11563

// pinned because no tag supports 1.18 yet
helm.sh/helm/v3 => helm.sh/helm/v3 v3.1.0-rc.1.0.20200416205415-853ba2de16a0
// pinned because no tag supports 1.18 yet
// sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.5.1-0.20200414221803-bac7e8aaf90a
sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.5.1-0.20200414221803-bac7e8aaf90a
sigs.k8s.io/structured-merge-diff => sigs.k8s.io/structured-merge-diff v1.0.1-0.20191108220359-b1b620dd3f06
)
Loading