Skip to content

Commit ed17b12

Browse files
Merge pull request #1468 from njhale/op-disc
(Rebased disc)^2
2 parents 9f126de + 224add1 commit ed17b12

File tree

187 files changed

+21688
-347
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

187 files changed

+21688
-347
lines changed

Makefile

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ endif
1111
SHELL := /bin/bash
1212
ORG := github.com/operator-framework
1313
PKG := $(ORG)/operator-lifecycle-manager
14-
OS := $(shell go env GOOS)
15-
ARCH := $(shell go env GOARCH)
1614
MOD_FLAGS := $(shell (go version | grep -q -E "1\.1[1-9]") && echo -mod=vendor)
1715
CMDS := $(shell go list $(MOD_FLAGS) ./cmd/...)
1816
TCMDS := $(shell go list $(MOD_FLAGS) ./test/e2e/...)
@@ -25,6 +23,7 @@ LOCAL_NAMESPACE := "olm"
2523
export GO111MODULE=on
2624
CONTROLLER_GEN := go run $(MOD_FLAGS) ./vendor/sigs.k8s.io/controller-tools/cmd/controller-gen
2725
YQ_INTERNAL := go run $(MOD_FLAGS) ./vendor/github.com/mikefarah/yq/v2/
26+
KUBEBUILDER_ASSETS ?= /usr/local/kubebuilder/bin
2827

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

3837
.PHONY: build test run clean vendor schema-check \
39-
vendor-update coverage coverage-html e2e .FORCE
38+
vendor-update coverage coverage-html e2e \
39+
kubebuilder .FORCE
4040

4141
all: test build
4242

4343
test: clean cover.out
4444

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

48-
# Install kubebuilder if not found
49-
KUBEBUILDER_DIR := /tmp/kubebuilder_2.3.1_$(OS)_$(ARCH)/bin
48+
# Ensure kubebuilder is installed before continuing
49+
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
5050
kubebuilder:
51-
ifeq (, $(shell which kubebuilder))
52-
[ ! -d "$(KUBEBUILDER_DIR)" ] && (curl -sL https://go.kubebuilder.io/dl/2.3.1/$(OS)/$(ARCH) | tar -xz -C /tmp/)
53-
KUBEBUILDER_ENV := KUBEBUILDER_ASSETS=$(KUBEBUILDER_DIR)
51+
ifeq (, $(wildcard $(KUBEBUILDER_ASSETS)/kubebuilder))
52+
$(error kubebuilder $(KUBEBUILDER_ASSETS_ERR))
53+
endif
54+
ifeq (, $(wildcard $(KUBEBUILDER_ASSETS)/etcd))
55+
$(error etcd $(KUBEBUILDER_ASSETS_ERR))
56+
endif
57+
ifeq (, $(wildcard $(KUBEBUILDER_ASSETS)/kube-apiserver))
58+
$(error kube-apiserver $(KUBEBUILDER_ASSETS_ERR))
5459
endif
5560

5661
schema-check:

cmd/olm/main.go

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"context"
55
"crypto/tls"
6-
"flag"
76
"fmt"
87
"net/http"
98
"os"
@@ -12,18 +11,19 @@ import (
1211

1312
configclientset "github.com/openshift/client-go/config/clientset/versioned"
1413
configv1client "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
15-
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/queueinformer"
1614
"github.com/prometheus/client_golang/prometheus/promhttp"
17-
log "github.com/sirupsen/logrus"
15+
"github.com/sirupsen/logrus"
16+
"github.com/spf13/pflag"
1817
v1 "k8s.io/api/core/v1"
19-
"k8s.io/client-go/tools/clientcmd"
2018

21-
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client"
19+
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
2220
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/olm"
21+
"github.com/operator-framework/operator-lifecycle-manager/pkg/feature"
2322
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/filemonitor"
2423
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
2524
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorstatus"
2625
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/profile"
26+
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/queueinformer"
2727
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/signals"
2828
"github.com/operator-framework/operator-lifecycle-manager/pkg/metrics"
2929
olmversion "github.com/operator-framework/operator-lifecycle-manager/pkg/version"
@@ -37,53 +37,53 @@ const (
3737

3838
// config flags defined globally so that they appear on the test binary as well
3939
var (
40-
kubeConfigPath = flag.String(
41-
"kubeconfig", "", "absolute path to the kubeconfig file")
42-
43-
wakeupInterval = flag.Duration(
40+
wakeupInterval = pflag.Duration(
4441
"interval", defaultWakeupInterval, "wake up interval")
4542

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

51-
writeStatusName = flag.String(
48+
writeStatusName = pflag.String(
5249
"writeStatusName", defaultOperatorName, "ClusterOperator name in which to write status, set to \"\" to disable.")
5350

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

57-
debug = flag.Bool(
54+
debug = pflag.Bool(
5855
"debug", false, "use debug log level")
5956

60-
version = flag.Bool("version", false, "displays olm version")
57+
version = pflag.Bool("version", false, "displays olm version")
6158

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

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

68-
profiling = flag.Bool(
65+
profiling = pflag.Bool(
6966
"profiling", false, "serve profiling data (on port 8080)")
7067

71-
namespace = flag.String(
68+
namespace = pflag.String(
7269
"namespace", "", "namespace where cleanup runs")
7370
)
7471

7572
func init() {
7673
metrics.RegisterOLM()
74+
75+
// Add feature gates before parsing
76+
feature.AddFlag(pflag.CommandLine)
7777
}
7878

7979
// main function - entrypoint to OLM operator
8080
func main() {
8181
// Get exit signal context
8282
ctx, cancel := context.WithCancel(signals.Context())
8383
defer cancel()
84+
pflag.Parse()
8485

8586
// Parse the command-line flags.
86-
flag.Parse()
8787

8888
// Check if version flag was set
8989
if *version {
@@ -104,9 +104,9 @@ func main() {
104104
}
105105

106106
// Set log level to debug if `debug` flag set
107-
logger := log.New()
107+
logger := logrus.New()
108108
if *debug {
109-
logger.SetLevel(log.DebugLevel)
109+
logger.SetLevel(logrus.DebugLevel)
110110
}
111111
logger.Infof("log level %s", logger.Level)
112112

@@ -169,24 +169,27 @@ func main() {
169169
}()
170170
}
171171

172-
// create a config client for operator status
173-
config, err := clientcmd.BuildConfigFromFlags("", *kubeConfigPath)
172+
mgr, err := Manager(ctx)
174173
if err != nil {
175-
log.Fatalf("error configuring client: %s", err.Error())
174+
logger.WithError(err).Fatalf("error configuring controller manager")
176175
}
176+
config := mgr.GetConfig()
177+
177178
versionedConfigClient, err := configclientset.NewForConfig(config)
178179
if err != nil {
179-
err = fmt.Errorf("error configuring OpenShift Proxy client: %v", err)
180-
return
180+
logger.WithError(err).Fatal("error configuring openshift proxy client")
181181
}
182182
configClient, err := configv1client.NewForConfig(config)
183183
if err != nil {
184-
log.Fatalf("error configuring client: %s", err.Error())
184+
logger.WithError(err).Fatal("error configuring config client")
185+
}
186+
opClient, err := operatorclient.NewClientFromRestConfig(config)
187+
if err != nil {
188+
logger.WithError(err).Fatal("error configuring operator client")
185189
}
186-
opClient := operatorclient.NewClientFromConfig(*kubeConfigPath, logger)
187-
crClient, err := client.NewClient(*kubeConfigPath)
190+
crClient, err := versioned.NewForConfig(config)
188191
if err != nil {
189-
log.Fatalf("error configuring client: %s", err.Error())
192+
logger.WithError(err).Fatal("error configuring custom resource client")
190193
}
191194

192195
cleanup(logger, opClient, crClient)
@@ -203,7 +206,7 @@ func main() {
203206
olm.WithConfigClient(versionedConfigClient),
204207
)
205208
if err != nil {
206-
log.WithError(err).Fatalf("error configuring operator")
209+
logger.WithError(err).Fatalf("error configuring operator")
207210
return
208211
}
209212

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

233+
// Start the controller manager
234+
if err := mgr.Start(ctx.Done()); err != nil {
235+
logger.WithError(err).Fatal("controller manager stopped")
236+
}
237+
230238
<-op.Done()
231239
}

cmd/olm/manager.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+
"context"
5+
"fmt"
6+
7+
"github.com/operator-framework/api/crds"
8+
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1"
9+
apierrors "k8s.io/apimachinery/pkg/api/errors"
10+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11+
ctrl "sigs.k8s.io/controller-runtime"
12+
"sigs.k8s.io/controller-runtime/pkg/log/zap"
13+
14+
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators"
15+
"github.com/operator-framework/operator-lifecycle-manager/pkg/feature"
16+
)
17+
18+
var log = ctrl.Log.WithName("manager")
19+
20+
func Manager(ctx context.Context) (ctrl.Manager, error) {
21+
ctrl.SetLogger(zap.Logger(true))
22+
setupLog := log.WithName("setup").V(4)
23+
24+
// Setup a Manager
25+
setupLog.Info("configuring manager")
26+
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{MetricsBindAddress: "0"}) // TODO(njhale): Enable metrics on non-conflicting port (not 8080)
27+
if err != nil {
28+
return nil, err
29+
}
30+
31+
// Setup a new controller to reconcile Operators
32+
setupLog.Info("configuring controller")
33+
client, err := apiextensionsv1.NewForConfig(mgr.GetConfig())
34+
if err != nil {
35+
return nil, err
36+
}
37+
38+
if feature.Gate.Enabled(feature.OperatorLifecycleManagerV2) {
39+
setupLog.Info(fmt.Sprintf("feature enabled: %v", feature.OperatorLifecycleManagerV2))
40+
41+
reconciler, err := operators.NewOperatorReconciler(
42+
mgr.GetClient(),
43+
ctrl.Log.WithName("controllers").WithName("operator"),
44+
mgr.GetScheme(),
45+
)
46+
if err != nil {
47+
return nil, err
48+
}
49+
50+
crd, err := client.CustomResourceDefinitions().Create(ctx, crds.Operator(), metav1.CreateOptions{})
51+
if err != nil {
52+
if !apierrors.IsAlreadyExists(err) {
53+
return nil, err
54+
}
55+
56+
// Already exists, try to update
57+
if crd, err = client.CustomResourceDefinitions().Get(ctx, crds.Operator().GetName(), metav1.GetOptions{}); err != nil {
58+
return nil, err
59+
}
60+
61+
crd.Spec = crds.Operator().Spec
62+
if _, err = client.CustomResourceDefinitions().Update(ctx, crd, metav1.UpdateOptions{}); err != nil {
63+
return nil, err
64+
}
65+
}
66+
setupLog.Info("v2alpha1 CRDs installed")
67+
68+
if err = reconciler.SetupWithManager(mgr); err != nil {
69+
return nil, err
70+
}
71+
}
72+
73+
setupLog.Info("manager configured")
74+
75+
return mgr, nil
76+
}

deploy/chart/templates/0000_50_olm_07-olm-operator.deployment.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,32 @@ spec:
2626
command:
2727
- /bin/olm
2828
args:
29-
- -namespace
29+
- --namespace
3030
- $(OPERATOR_NAMESPACE)
3131
{{- if .Values.watchedNamespaces }}
32-
- -watchedNamespaces
32+
- --watchedNamespaces
3333
- {{ .Values.watchedNamespaces }}
3434
{{- end }}
3535
{{- if .Values.olm.commandArgs }}
3636
- {{ .Values.olm.commandArgs }}
3737
{{- end }}
3838
{{- if .Values.debug }}
39-
- -debug
39+
- --debug
4040
{{- end }}
4141
{{- if .Values.writeStatusName }}
42-
- -writeStatusName
42+
- --writeStatusName
4343
- {{ .Values.writeStatusName }}
4444
{{- end }}
4545
{{- if .Values.writePackageServerStatusName }}
46-
- -writePackageServerStatusName
46+
- --writePackageServerStatusName
4747
- {{ .Values.writePackageServerStatusName }}
4848
{{- end }}
4949
{{- if .Values.olm.tlsCertPath }}
50-
- -tls-cert
50+
- --tls-cert
5151
- {{ .Values.olm.tlsCertPath }}
5252
{{- end }}
5353
{{- if .Values.olm.tlsKeyPath }}
54-
- -tls-key
54+
- --tls-key
5555
- {{ .Values.olm.tlsKeyPath }}
5656
{{- end }}
5757
image: {{ .Values.olm.image.ref }}

go.mod

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ require (
99
github.com/fsnotify/fsnotify v1.4.7
1010
github.com/ghodss/yaml v1.0.0
1111
github.com/go-bindata/go-bindata/v3 v3.1.3
12+
github.com/go-logr/logr v0.1.0
1213
github.com/go-openapi/spec v0.19.4
1314
github.com/golang/mock v1.3.1
1415
github.com/google/go-cmp v0.4.0
1516
github.com/irifrance/gini v1.0.1
1617
github.com/maxbrunsfeld/counterfeiter/v6 v6.2.2
1718
github.com/mikefarah/yq/v2 v2.4.1
1819
github.com/mitchellh/hashstructure v1.0.0
20+
github.com/mitchellh/mapstructure v1.1.2
1921
github.com/onsi/ginkgo v1.12.0
2022
github.com/onsi/gomega v1.9.0
2123
github.com/openshift/api v0.0.0-20200331152225-585af27e34fd
@@ -27,7 +29,9 @@ require (
2729
github.com/prometheus/client_golang v1.2.1
2830
github.com/sirupsen/logrus v1.4.2
2931
github.com/spf13/cobra v1.0.0
32+
github.com/spf13/pflag v1.0.5
3033
github.com/stretchr/testify v1.5.1
34+
github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0
3135
golang.org/x/time v0.0.0-20191024005414-555d28b269f0
3236
google.golang.org/grpc v1.27.0
3337
gopkg.in/yaml.v2 v2.2.8
@@ -43,6 +47,7 @@ require (
4347
k8s.io/kube-aggregator v0.18.0
4448
k8s.io/kube-openapi v0.0.0-20200121204235-bf4fb3bd569c
4549
rsc.io/letsencrypt v0.0.3 // indirect
50+
sigs.k8s.io/controller-runtime v0.5.2
4651
sigs.k8s.io/controller-tools v0.2.8
4752
sigs.k8s.io/kind v0.7.0
4853
)
@@ -52,12 +57,14 @@ replace (
5257
github.com/docker/docker => github.com/moby/moby v0.7.3-0.20190826074503-38ab9da00309 // Required by Helm
5358
github.com/openshift/api => github.com/openshift/api v0.0.0-20200331152225-585af27e34fd // release-4.5
5459
github.com/openshift/client-go => github.com/openshift/client-go v0.0.0-20200326155132-2a6cd50aedd0 // release-4.5
60+
61+
github.com/operator-framework/api => github.com/operator-framework/api v0.3.1
5562
github.com/prometheus/client_golang => github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829
5663
google.golang.org/grpc => google.golang.org/grpc v1.26.0 // https://github.com/etcd-io/etcd/issues/11563
5764

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

0 commit comments

Comments
 (0)