@@ -12,7 +12,6 @@ import (
12
12
log "github.com/sirupsen/logrus"
13
13
v1 "k8s.io/api/core/v1"
14
14
k8serrors "k8s.io/apimachinery/pkg/api/errors"
15
- "k8s.io/apimachinery/pkg/api/meta"
16
15
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
17
16
18
17
configv1 "github.com/openshift/api/config/v1"
@@ -26,12 +25,14 @@ import (
26
25
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/signals"
27
26
"github.com/operator-framework/operator-lifecycle-manager/pkg/metrics"
28
27
olmversion "github.com/operator-framework/operator-lifecycle-manager/pkg/version"
28
+ "k8s.io/apimachinery/pkg/runtime/schema"
29
+ "k8s.io/client-go/discovery"
29
30
"k8s.io/client-go/tools/clientcmd"
30
31
)
31
32
32
33
const (
33
34
defaultWakeupInterval = 5 * time .Minute
34
- defaultOperatorName = "operator-lifecycle-manager "
35
+ defaultOperatorName = ""
35
36
)
36
37
37
38
// config flags defined globally so that they appear on the test binary as well
@@ -131,84 +132,91 @@ func main() {
131
132
<- ready
132
133
133
134
if * writeStatusName != "" {
134
- existing , err := configClient .ClusterOperators ().Get (* writeStatusName , metav1.GetOptions {})
135
- if meta .IsNoMatchError (err ) {
136
- log .Infof ("ClusterOperator api not present, skipping update" )
137
- } else if k8serrors .IsNotFound (err ) {
138
- log .Info ("Existing cluster operator not found, creating" )
139
- created , err := configClient .ClusterOperators ().Create (& configv1.ClusterOperator {
140
- ObjectMeta : metav1.ObjectMeta {
141
- Name : * writeStatusName ,
142
- },
143
- })
144
- if err != nil {
145
- log .Fatalf ("ClusterOperator create failed: %v\n " , err )
146
- }
147
-
148
- created .Status = configv1.ClusterOperatorStatus {
149
- Conditions : []configv1.ClusterOperatorStatusCondition {
150
- configv1.ClusterOperatorStatusCondition {
151
- Type : configv1 .OperatorProgressing ,
152
- Status : configv1 .ConditionFalse ,
153
- Message : fmt .Sprintf ("Done deploying %s." , olmversion .OLMVersion ),
154
- LastTransitionTime : metav1 .Now (),
155
- },
156
- configv1.ClusterOperatorStatusCondition {
157
- Type : configv1 .OperatorFailing ,
158
- Status : configv1 .ConditionFalse ,
159
- Message : fmt .Sprintf ("Done deploying %s." , olmversion .OLMVersion ),
160
- LastTransitionTime : metav1 .Now (),
135
+ opStatusGV := schema.GroupVersion {
136
+ Group : "config.openshift.io" ,
137
+ Version : "v1" ,
138
+ }
139
+ err := discovery .ServerSupportsVersion (opClient .KubernetesInterface ().Discovery (), opStatusGV )
140
+ if err != nil {
141
+ log .Infof ("ClusterOperator api not present, skipping update (%v)" , err )
142
+ } else {
143
+ existing , err := configClient .ClusterOperators ().Get (* writeStatusName , metav1.GetOptions {})
144
+ if k8serrors .IsNotFound (err ) {
145
+ log .Info ("Existing operator status not found, creating" )
146
+ created , err := configClient .ClusterOperators ().Create (& configv1.ClusterOperator {
147
+ ObjectMeta : metav1.ObjectMeta {
148
+ Name : * writeStatusName ,
161
149
},
162
- configv1.ClusterOperatorStatusCondition {
163
- Type : configv1 .OperatorAvailable ,
164
- Status : configv1 .ConditionTrue ,
165
- Message : fmt .Sprintf ("Done deploying %s." , olmversion .OLMVersion ),
166
- LastTransitionTime : metav1 .Now (),
150
+ })
151
+ if err != nil {
152
+ log .Fatalf ("ClusterOperator create failed: %v\n " , err )
153
+ }
154
+
155
+ created .Status = configv1.ClusterOperatorStatus {
156
+ Conditions : []configv1.ClusterOperatorStatusCondition {
157
+ configv1.ClusterOperatorStatusCondition {
158
+ Type : configv1 .OperatorProgressing ,
159
+ Status : configv1 .ConditionFalse ,
160
+ Message : fmt .Sprintf ("Done deploying %s." , olmversion .OLMVersion ),
161
+ LastTransitionTime : metav1 .Now (),
162
+ },
163
+ configv1.ClusterOperatorStatusCondition {
164
+ Type : configv1 .OperatorFailing ,
165
+ Status : configv1 .ConditionFalse ,
166
+ Message : fmt .Sprintf ("Done deploying %s." , olmversion .OLMVersion ),
167
+ LastTransitionTime : metav1 .Now (),
168
+ },
169
+ configv1.ClusterOperatorStatusCondition {
170
+ Type : configv1 .OperatorAvailable ,
171
+ Status : configv1 .ConditionTrue ,
172
+ Message : fmt .Sprintf ("Done deploying %s." , olmversion .OLMVersion ),
173
+ LastTransitionTime : metav1 .Now (),
174
+ },
167
175
},
168
- },
169
- Versions : []configv1.OperandVersion {{
170
- Name : "operator" ,
171
- Version : olmversion .Full (),
172
- }},
173
- }
174
- _ , err = configClient .ClusterOperators ().UpdateStatus (created )
175
- if err != nil {
176
- log .Fatalf ("ClusterOperator update status failed: %v" , err )
177
- }
178
- } else if err != nil {
179
- log .Fatalf ("ClusterOperators get failed: %v" , err )
180
- } else {
181
- clusteroperatorv1helpers .SetStatusCondition (& existing .Status .Conditions , configv1.ClusterOperatorStatusCondition {
182
- Type : configv1 .OperatorProgressing ,
183
- Status : configv1 .ConditionFalse ,
184
- Message : fmt .Sprintf ("Done deploying %s." , olmversion .OLMVersion ),
185
- LastTransitionTime : metav1 .Now (),
186
- })
187
- clusteroperatorv1helpers .SetStatusCondition (& existing .Status .Conditions , configv1.ClusterOperatorStatusCondition {
188
- Type : configv1 .OperatorFailing ,
189
- Status : configv1 .ConditionFalse ,
190
- Message : fmt .Sprintf ("Done deploying %s." , olmversion .OLMVersion ),
191
- LastTransitionTime : metav1 .Now (),
192
- })
193
- clusteroperatorv1helpers .SetStatusCondition (& existing .Status .Conditions , configv1.ClusterOperatorStatusCondition {
194
- Type : configv1 .OperatorAvailable ,
195
- Status : configv1 .ConditionTrue ,
196
- Message : fmt .Sprintf ("Done deploying %s." , olmversion .OLMVersion ),
197
- LastTransitionTime : metav1 .Now (),
198
- })
199
-
200
- olmOperandVersion := configv1.OperandVersion {Name : "operator" , Version : olmversion .Full ()}
201
- // look for operator version, even though in OLM's case should only be one
202
- for _ , item := range existing .Status .Versions {
203
- if item .Name == "operator" && item != olmOperandVersion {
204
- // if a cluster wide upgrade has occurred, hopefully any existing operator statuses have been deleted
205
- log .Infof ("Updating version from %v to %v\n " , item .Version , olmversion .Full ())
176
+ Versions : []configv1.OperandVersion {{
177
+ Name : "operator" ,
178
+ Version : olmversion .Full (),
179
+ }},
180
+ }
181
+ _ , err = configClient .ClusterOperators ().UpdateStatus (created )
182
+ if err != nil {
183
+ log .Fatalf ("ClusterOperator update status failed: %v" , err )
184
+ }
185
+ } else if err != nil {
186
+ log .Fatalf ("ClusterOperators get failed: %v" , err )
187
+ } else {
188
+ clusteroperatorv1helpers .SetStatusCondition (& existing .Status .Conditions , configv1.ClusterOperatorStatusCondition {
189
+ Type : configv1 .OperatorProgressing ,
190
+ Status : configv1 .ConditionFalse ,
191
+ Message : fmt .Sprintf ("Done deploying %s." , olmversion .OLMVersion ),
192
+ LastTransitionTime : metav1 .Now (),
193
+ })
194
+ clusteroperatorv1helpers .SetStatusCondition (& existing .Status .Conditions , configv1.ClusterOperatorStatusCondition {
195
+ Type : configv1 .OperatorFailing ,
196
+ Status : configv1 .ConditionFalse ,
197
+ Message : fmt .Sprintf ("Done deploying %s." , olmversion .OLMVersion ),
198
+ LastTransitionTime : metav1 .Now (),
199
+ })
200
+ clusteroperatorv1helpers .SetStatusCondition (& existing .Status .Conditions , configv1.ClusterOperatorStatusCondition {
201
+ Type : configv1 .OperatorAvailable ,
202
+ Status : configv1 .ConditionTrue ,
203
+ Message : fmt .Sprintf ("Done deploying %s." , olmversion .OLMVersion ),
204
+ LastTransitionTime : metav1 .Now (),
205
+ })
206
+
207
+ olmOperandVersion := configv1.OperandVersion {Name : "operator" , Version : olmversion .Full ()}
208
+ // look for operator version, even though in OLM's case should only be one
209
+ for _ , item := range existing .Status .Versions {
210
+ if item .Name == "operator" && item != olmOperandVersion {
211
+ // if a cluster wide upgrade has occurred, hopefully any existing operator statuses have been deleted
212
+ log .Infof ("Updating version from %v to %v\n " , item .Version , olmversion .Full ())
213
+ }
214
+ }
215
+ operatorv1helpers .SetOperandVersion (& existing .Status .Versions , olmOperandVersion )
216
+ _ , err = configClient .ClusterOperators ().UpdateStatus (existing )
217
+ if err != nil {
218
+ log .Fatalf ("ClusterOperator update status failed: %v" , err )
206
219
}
207
- }
208
- operatorv1helpers .SetOperandVersion (& existing .Status .Versions , olmOperandVersion )
209
- _ , err = configClient .ClusterOperators ().UpdateStatus (existing )
210
- if err != nil {
211
- log .Fatalf ("ClusterOperator update status failed: %v" , err )
212
220
}
213
221
}
214
222
}
0 commit comments