Skip to content

Write cluster operator status after successful startup (attempt #2) #652

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
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
1 change: 1 addition & 0 deletions Documentation/install/local-values.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
rbacApiVersion: rbac.authorization.k8s.io
namespace: local
writeStatusName: '""'
catalog_namespace: local
operator_namespace: local-operators
debug: true
Expand Down
111 changes: 109 additions & 2 deletions cmd/olm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,27 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1"

k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

configv1 "github.com/openshift/api/config/v1"
configv1client "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
clusteroperatorv1helpers "github.com/openshift/library-go/pkg/config/clusteroperator/v1helpers"
operatorv1helpers "github.com/openshift/library-go/pkg/operator/v1helpers"
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/olm"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
"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"
"k8s.io/client-go/tools/clientcmd"
)

const (
defaultWakeupInterval = 5 * time.Minute
defaultOperatorName = "operator-lifecycle-manager"
)

// config flags defined globally so that they appear on the test binary as well
Expand All @@ -38,6 +47,9 @@ var (
"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", defaultOperatorName, "ClusterOperator name in which to write status, set to \"\" to disable.")

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

Expand Down Expand Up @@ -89,6 +101,16 @@ func main() {

opClient := operatorclient.NewClientFromConfig(*kubeConfigPath, logger)

// create a config client for operator status
config, err := clientcmd.BuildConfigFromFlags("", *kubeConfigPath)
if err != nil {
log.Fatalf("error configuring client: %s", err.Error())
}
configClient, err := configv1client.NewForConfig(config)
if err != nil {
log.Fatalf("error configuring client: %s", err.Error())
}

// Create a new instance of the operator.
operator, err := olm.NewOperator(logger, crClient, opClient, &install.StrategyResolver{}, *wakeupInterval, namespaces)

Expand All @@ -105,6 +127,91 @@ func main() {
http.Handle("/metrics", promhttp.Handler())
go http.ListenAndServe(":8081", nil)

_, done := operator.Run(stopCh)
ready, done := operator.Run(stopCh)
<-ready

if *writeStatusName != "" {
existing, err := configClient.ClusterOperators().Get(*writeStatusName, metav1.GetOptions{})
if meta.IsNoMatchError(err) {
log.Infof("ClusterOperator api not present, skipping update")
} else if k8serrors.IsNotFound(err) {
log.Info("Existing cluster operator not found, creating")
created, err := configClient.ClusterOperators().Create(&configv1.ClusterOperator{
ObjectMeta: metav1.ObjectMeta{
Name: *writeStatusName,
},
})
if err != nil {
log.Fatalf("ClusterOperator create failed: %v\n", err)
}

created.Status = configv1.ClusterOperatorStatus{
Conditions: []configv1.ClusterOperatorStatusCondition{
configv1.ClusterOperatorStatusCondition{
Type: configv1.OperatorProgressing,
Status: configv1.ConditionFalse,
Message: fmt.Sprintf("Done deploying %s.", olmversion.OLMVersion),
LastTransitionTime: metav1.Now(),
},
configv1.ClusterOperatorStatusCondition{
Type: configv1.OperatorFailing,
Status: configv1.ConditionFalse,
Message: fmt.Sprintf("Done deploying %s.", olmversion.OLMVersion),
LastTransitionTime: metav1.Now(),
},
configv1.ClusterOperatorStatusCondition{
Type: configv1.OperatorAvailable,
Status: configv1.ConditionTrue,
Message: fmt.Sprintf("Done deploying %s.", olmversion.OLMVersion),
LastTransitionTime: metav1.Now(),
},
},
Versions: []configv1.OperandVersion{{
Name: "operator",
Version: olmversion.Full(),
}},
}
_, err = configClient.ClusterOperators().UpdateStatus(created)
if err != nil {
log.Fatalf("ClusterOperator update status failed: %v", err)
}
} else if err != nil {
log.Fatalf("ClusterOperators get failed: %v", err)
} else {
clusteroperatorv1helpers.SetStatusCondition(&existing.Status.Conditions, configv1.ClusterOperatorStatusCondition{
Type: configv1.OperatorProgressing,
Status: configv1.ConditionFalse,
Message: fmt.Sprintf("Done deploying %s.", olmversion.OLMVersion),
LastTransitionTime: metav1.Now(),
})
clusteroperatorv1helpers.SetStatusCondition(&existing.Status.Conditions, configv1.ClusterOperatorStatusCondition{
Type: configv1.OperatorFailing,
Status: configv1.ConditionFalse,
Message: fmt.Sprintf("Done deploying %s.", olmversion.OLMVersion),
LastTransitionTime: metav1.Now(),
})
clusteroperatorv1helpers.SetStatusCondition(&existing.Status.Conditions, configv1.ClusterOperatorStatusCondition{
Type: configv1.OperatorAvailable,
Status: configv1.ConditionTrue,
Message: fmt.Sprintf("Done deploying %s.", olmversion.OLMVersion),
LastTransitionTime: metav1.Now(),
})

olmOperandVersion := configv1.OperandVersion{Name: "operator", Version: olmversion.Full()}
// look for operator version, even though in OLM's case should only be one
for _, item := range existing.Status.Versions {
if item.Name == "operator" && item != olmOperandVersion {
// if a cluster wide upgrade has occurred, hopefully any existing operator statuses have been deleted
log.Infof("Updating version from %v to %v\n", item.Version, olmversion.Full())
}
}
operatorv1helpers.SetOperandVersion(&existing.Status.Versions, olmOperandVersion)
_, err = configClient.ClusterOperators().UpdateStatus(existing)
if err != nil {
log.Fatalf("ClusterOperator update status failed: %v", err)
}
}
}

<-done
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ spec:
{{- if .Values.debug }}
- -debug
{{- end }}
{{- if .Values.writeStatusName }}
- -writeStatusName
- {{ .Values.writeStatusName }}
{{- end }}
image: {{ .Values.olm.image.ref }}
imagePullPolicy: {{ .Values.olm.image.pullPolicy }}
ports:
Expand Down
1 change: 1 addition & 0 deletions deploy/chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace: operator-lifecycle-manager
catalog_namespace: operator-lifecycle-manager
operator_namespace: operators
minKubeVersion: 1.11.0
writeStatusName: '""'
imagestream: false
debug: false
olm:
Expand Down
1 change: 1 addition & 0 deletions deploy/upstream/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace: olm
catalog_namespace: olm
operator_namespace: operators
imagestream: false
writeStatusName: '""'
olm:
replicaCount: 1
image:
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ require (
github.com/maxbrunsfeld/counterfeiter v0.0.0-20181017030959-1aadac120687
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
github.com/openshift/api v3.9.1-0.20190129160438-bbc4289c54e0+incompatible
github.com/openshift/client-go v0.0.0-20190128154758-1540772775fa
github.com/openshift/library-go v0.0.0-20190125204812-22b2ba2f485f
github.com/operator-framework/operator-registry v1.0.4
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.8.0
Expand Down
9 changes: 6 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf h1:eg0MeVzs
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/coreos/bbolt v1.3.0 h1:HIgH5xUWXT914HCI671AxuTTqjj64UOFr7pHn48LUTI=
github.com/coreos/bbolt v1.3.0/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/bbolt v1.3.2 h1:wZwiHHUieZCquLkDL0B8UhzreNWsPHooDAG3q34zk0s=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
Expand Down Expand Up @@ -89,7 +87,6 @@ github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20180924190550-6f2cf27854a4/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20181024230925-c65c006176ff h1:kOkM9whyQYodu09SJ6W3NCsHG7crFaJILQ22Gozp3lg=
github.com/golang/groupcache v0.0.0-20181024230925-c65c006176ff/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef h1:veQD95Isof8w9/WXiA+pa3tz3fJXkt5B7QaRBrM62gk=
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -160,6 +157,12 @@ github.com/onsi/gomega v1.4.2-0.20180831124310-ae19f1b56d53 h1:W43ZAQzmBARaVM1Wr
github.com/onsi/gomega v1.4.2-0.20180831124310-ae19f1b56d53/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ=
github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
github.com/openshift/api v3.9.1-0.20190129160438-bbc4289c54e0+incompatible h1:ZEphfx4UJGELQZbqf3kcDkspEplsr/9IWXxRsof9wgY=
github.com/openshift/api v3.9.1-0.20190129160438-bbc4289c54e0+incompatible/go.mod h1:dh9o4Fs58gpFXGSYfnVxGR9PnV53I8TW84pQaJDdGiY=
github.com/openshift/client-go v0.0.0-20190128154758-1540772775fa h1:NG6c0KXa/9hBJmqyR6xwwGaEGJi1+79SOwXZWXse/Lw=
github.com/openshift/client-go v0.0.0-20190128154758-1540772775fa/go.mod h1:6rzn+JTr7+WYS2E1TExP4gByoABxMznR6y2SnUIkmxk=
github.com/openshift/library-go v0.0.0-20190125204812-22b2ba2f485f h1:C8nvPUscfprRIyUCgWN2HpLXwKT1L+5irSPb9odZJZ4=
github.com/openshift/library-go v0.0.0-20190125204812-22b2ba2f485f/go.mod h1:NBttNjZpWwup/nthuLbPAPSYC8Qyo+BBK5bCtFoyYjo=
github.com/operator-framework/operator-lifecycle-manager v0.0.0-20181023032605-e838f7fb2186/go.mod h1:Ma5ZXd4S1vmMyewWlF7aO8CZiokR7Sd8dhSfkGkNU4U=
github.com/operator-framework/operator-lifecycle-manager v0.0.0-20190105193533-81104ffdc4fb/go.mod h1:XMyE4n2opUK4N6L45YGQkXXi8F9fD7XDYFv/CsS6V5I=
github.com/operator-framework/operator-registry v1.0.1/go.mod h1:1xEdZjjUg2hPEd52LG3YQ0jtwiwEGdm98S1TH5P4RAA=
Expand Down
4 changes: 4 additions & 0 deletions manifests/0000_50_18-operatorstatus.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: config.openshift.io/v1
kind: ClusterOperator
metadata:
name: operator-lifecycle-manager
5 changes: 5 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ var GitCommit string
func String() string {
return fmt.Sprintf("OLM version: %s\ngit commit: %s\n", OLMVersion, GitCommit)
}

// Full returns a hypenated concatenation of just OLMVersion and GitCommit
func Full() string {
return fmt.Sprintf("%s-%s", OLMVersion, GitCommit)
}
1 change: 1 addition & 0 deletions test/e2e/e2e-bare-values.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
rbacApiVersion: rbac.authorization.k8s.io
namespace: operator-lifecycle-manager
catalog_namespace: operator-lifecycle-manager
writeStatusName: '""'
olm:
replicaCount: 1
image:
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/e2e-values.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
writeStatusName: '""'

olm:
replicaCount: 1
image:
Expand Down
Loading