Skip to content

Commit 10e93ab

Browse files
committed
status: extract API types to a package
We are temporarily using API types that will eventually come via importing openshift/api => under a package. Extract the current API types to a subpackage, so everything we use from it is used through a package (e.g. `updatestatus.THING` instead of just `THING`). This will make an eventual switch to the proper API easier.
1 parent 11ca71a commit 10e93ab

10 files changed

+293
-285
lines changed

pkg/updatestatus/controlplaneinformer.go

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/openshift/library-go/pkg/operator/events"
2323

2424
"github.com/openshift/cluster-version-operator/lib/resourcemerge"
25+
updatestatus "github.com/openshift/cluster-version-operator/pkg/updatestatus/api"
2526
)
2627

2728
// controlPlaneInformerController is the controller that monitors health of the control plane-related resources
@@ -176,23 +177,23 @@ func (c *controlPlaneInformerController) sync(ctx context.Context, syncCtx facto
176177
return nil
177178
}
178179

179-
func makeInsightMsgForClusterOperator(coInsight *ClusterOperatorStatusInsight, acquiredAt metav1.Time) (informerMsg, error) {
180-
insight := ControlPlaneInsight{
180+
func makeInsightMsgForClusterOperator(coInsight *updatestatus.ClusterOperatorStatusInsight, acquiredAt metav1.Time) (informerMsg, error) {
181+
insight := updatestatus.ControlPlaneInsight{
181182
UID: fmt.Sprintf("co-%s", coInsight.Name),
182183
AcquiredAt: acquiredAt,
183-
ControlPlaneInsightUnion: ControlPlaneInsightUnion{
184-
Type: ClusterOperatorStatusInsightType,
184+
ControlPlaneInsightUnion: updatestatus.ControlPlaneInsightUnion{
185+
Type: updatestatus.ClusterOperatorStatusInsightType,
185186
ClusterOperatorStatusInsight: coInsight,
186187
},
187188
}
188189
return makeControlPlaneInsightMsg(insight, controlPlaneInformerName)
189190
}
190191

191-
func assessClusterOperator(ctx context.Context, operator *configv1.ClusterOperator, targetVersion string, appsClient appsv1client.AppsV1Interface, now metav1.Time) (*ClusterOperatorStatusInsight, error) {
192+
func assessClusterOperator(ctx context.Context, operator *configv1.ClusterOperator, targetVersion string, appsClient appsv1client.AppsV1Interface, now metav1.Time) (*updatestatus.ClusterOperatorStatusInsight, error) {
192193
updating := metav1.Condition{
193-
Type: string(ClusterOperatorStatusInsightUpdating),
194+
Type: string(updatestatus.ClusterOperatorStatusInsightUpdating),
194195
Status: metav1.ConditionUnknown,
195-
Reason: string(ClusterOperatorUpdatingCannotDetermine),
196+
Reason: string(updatestatus.ClusterOperatorUpdatingCannotDetermine),
196197
LastTransitionTime: now,
197198
}
198199

@@ -219,7 +220,7 @@ func assessClusterOperator(ctx context.Context, operator *configv1.ClusterOperat
219220
updated := (noOperatorImageVersion || operatorImageUpdated) && versionUpdated
220221
if updated {
221222
updating.Status = metav1.ConditionFalse
222-
updating.Reason = string(ClusterOperatorUpdatingReasonUpdated)
223+
updating.Reason = string(updatestatus.ClusterOperatorUpdatingReasonUpdated)
223224
}
224225

225226
var available *configv1.ClusterOperatorStatusCondition
@@ -241,40 +242,40 @@ func assessClusterOperator(ctx context.Context, operator *configv1.ClusterOperat
241242
if !updated && progressing != nil {
242243
if progressing.Status == configv1.ConditionTrue {
243244
updating.Status = metav1.ConditionTrue
244-
updating.Reason = string(ClusterOperatorUpdatingReasonProgressing)
245+
updating.Reason = string(updatestatus.ClusterOperatorUpdatingReasonProgressing)
245246
updating.Message = progressing.Message
246247
}
247248
if progressing.Status == configv1.ConditionFalse {
248249
updating.Status = metav1.ConditionFalse
249-
updating.Reason = string(ClusterOperatorUpdatingReasonPending)
250+
updating.Reason = string(updatestatus.ClusterOperatorUpdatingReasonPending)
250251
updating.Message = progressing.Message
251252
}
252253
}
253254

254255
health := metav1.Condition{
255-
Type: string(ClusterOperatorStatusInsightHealthy),
256+
Type: string(updatestatus.ClusterOperatorStatusInsightHealthy),
256257
Status: metav1.ConditionTrue,
257-
Reason: string(ClusterOperatorHealthyReasonAsExpected),
258+
Reason: string(updatestatus.ClusterOperatorHealthyReasonAsExpected),
258259
LastTransitionTime: now,
259260
}
260261

261262
if available == nil {
262263
health.Status = metav1.ConditionUnknown
263-
health.Reason = string(ClusterOperatorHealthyReasonUnavailable)
264+
health.Reason = string(updatestatus.ClusterOperatorHealthyReasonUnavailable)
264265
health.Message = "The cluster operator is unavailable because the available condition is not found in the cluster operator's status"
265266
} else if available.Status != configv1.ConditionTrue {
266267
health.Status = metav1.ConditionFalse
267-
health.Reason = string(ClusterOperatorHealthyReasonUnavailable)
268+
health.Reason = string(updatestatus.ClusterOperatorHealthyReasonUnavailable)
268269
health.Message = available.Message
269270
} else if degraded != nil && degraded.Status == configv1.ConditionTrue {
270271
health.Status = metav1.ConditionFalse
271-
health.Reason = string(ClusterOperatorHealthyReasonDegraded)
272+
health.Reason = string(updatestatus.ClusterOperatorHealthyReasonDegraded)
272273
health.Message = degraded.Message
273274
}
274275

275-
return &ClusterOperatorStatusInsight{
276+
return &updatestatus.ClusterOperatorStatusInsight{
276277
Name: operator.Name,
277-
Resource: ResourceRef{
278+
Resource: updatestatus.ResourceRef{
278279
Resource: "clusteroperators",
279280
Group: configv1.GroupName,
280281
Name: operator.Name,
@@ -309,19 +310,19 @@ func getImagePullSpec(ctx context.Context, name string, appsClient appsv1client.
309310
// makeInsightMsgForClusterVersion creates an informerMsg for the given ClusterVersionStatusInsight. It defines an uid
310311
// name and serializes the insight as YAML. Serialization is convenient because it prevents any data sharing issues
311312
// between controllers.
312-
func makeInsightMsgForClusterVersion(cvInsight *ClusterVersionStatusInsight, acquiredAt metav1.Time) (informerMsg, error) {
313-
insight := ControlPlaneInsight{
313+
func makeInsightMsgForClusterVersion(cvInsight *updatestatus.ClusterVersionStatusInsight, acquiredAt metav1.Time) (informerMsg, error) {
314+
insight := updatestatus.ControlPlaneInsight{
314315
UID: fmt.Sprintf("cv-%s", cvInsight.Resource.Name),
315316
AcquiredAt: acquiredAt,
316-
ControlPlaneInsightUnion: ControlPlaneInsightUnion{
317-
Type: ClusterVersionStatusInsightType,
317+
ControlPlaneInsightUnion: updatestatus.ControlPlaneInsightUnion{
318+
Type: updatestatus.ClusterVersionStatusInsightType,
318319
ClusterVersionStatusInsight: cvInsight,
319320
},
320321
}
321322
return makeControlPlaneInsightMsg(insight, controlPlaneInformerName)
322323
}
323324

324-
func uidForHealthInsight(healthInsight *HealthInsight) string {
325+
func uidForHealthInsight(healthInsight *updatestatus.HealthInsight) string {
325326
hasher := md5.New()
326327
hasher.Write([]byte(healthInsight.Impact.Summary))
327328
for i := range healthInsight.Scope.Resources {
@@ -338,12 +339,12 @@ func uidForHealthInsight(healthInsight *HealthInsight) string {
338339
return encoded
339340
}
340341

341-
func makeInsightMsgForHealthInsight(healthInsight *HealthInsight, acquiredAt metav1.Time) (informerMsg, error) {
342-
insight := ControlPlaneInsight{
342+
func makeInsightMsgForHealthInsight(healthInsight *updatestatus.HealthInsight, acquiredAt metav1.Time) (informerMsg, error) {
343+
insight := updatestatus.ControlPlaneInsight{
343344
UID: uidForHealthInsight(healthInsight),
344345
AcquiredAt: acquiredAt,
345-
ControlPlaneInsightUnion: ControlPlaneInsightUnion{
346-
Type: HealthInsightType,
346+
ControlPlaneInsightUnion: updatestatus.ControlPlaneInsightUnion{
347+
Type: updatestatus.HealthInsightType,
347348
HealthInsight: healthInsight,
348349
},
349350
}
@@ -354,7 +355,7 @@ func makeInsightMsgForHealthInsight(healthInsight *HealthInsight, acquiredAt met
354355
// It does not take previous status insight into account. Many fields of the status insights (such as completion) cannot
355356
// be properly calculated without also watching and processing ClusterOperators, so that functionality will need to be
356357
// added later.
357-
func assessClusterVersion(cv *configv1.ClusterVersion, now metav1.Time) (*ClusterVersionStatusInsight, []*HealthInsight) {
358+
func assessClusterVersion(cv *configv1.ClusterVersion, now metav1.Time) (*updatestatus.ClusterVersionStatusInsight, []*updatestatus.HealthInsight) {
358359

359360
var lastHistoryItem *configv1.UpdateHistory
360361
if len(cv.Status.History) > 0 {
@@ -367,24 +368,24 @@ func assessClusterVersion(cv *configv1.ClusterVersion, now metav1.Time) (*Cluste
367368

368369
klog.V(2).Infof("CPI :: CV/%s :: Updating=%s Started=%s Completed=%s", cv.Name, updating.Status, startedAt, completedAt)
369370

370-
var assessment ControlPlaneAssessment
371+
var assessment updatestatus.ControlPlaneAssessment
371372
var completion int32
372373
switch updating.Status {
373374
case metav1.ConditionTrue:
374-
assessment = ControlPlaneAssessmentProgressing
375+
assessment = updatestatus.ControlPlaneAssessmentProgressing
375376
case metav1.ConditionFalse:
376-
assessment = ControlPlaneAssessmentCompleted
377+
assessment = updatestatus.ControlPlaneAssessmentCompleted
377378
completion = 100
378379
case metav1.ConditionUnknown:
379-
assessment = ControlPlaneAssessmentUnknown
380+
assessment = updatestatus.ControlPlaneAssessmentUnknown
380381
default:
381-
assessment = ControlPlaneAssessmentUnknown
382+
assessment = updatestatus.ControlPlaneAssessmentUnknown
382383
}
383384

384385
klog.V(2).Infof("CPI :: CV/%s :: Assessment=%s", cv.Name, assessment)
385386

386-
insight := &ClusterVersionStatusInsight{
387-
Resource: ResourceRef{
387+
insight := &updatestatus.ClusterVersionStatusInsight{
388+
Resource: updatestatus.ResourceRef{
388389
Resource: "clusterversions",
389390
Group: configv1.GroupName,
390391
Name: cv.Name,
@@ -404,7 +405,7 @@ func assessClusterVersion(cv *configv1.ClusterVersion, now metav1.Time) (*Cluste
404405
insight.EstimatedCompletedAt = &metav1.Time{Time: est}
405406
}
406407

407-
var healthInsights []*HealthInsight
408+
var healthInsights []*updatestatus.HealthInsight
408409
if forcedHealthInsight := forcedHealthInsight(cv, now); forcedHealthInsight != nil {
409410
healthInsights = append(healthInsights, forcedHealthInsight)
410411
}
@@ -416,24 +417,24 @@ const (
416417
uscForceHealthInsightAnnotation = "usc.openshift.io/force-health-insight"
417418
)
418419

419-
func forcedHealthInsight(cv *configv1.ClusterVersion, now metav1.Time) *HealthInsight {
420+
func forcedHealthInsight(cv *configv1.ClusterVersion, now metav1.Time) *updatestatus.HealthInsight {
420421
if _, ok := cv.Annotations[uscForceHealthInsightAnnotation]; !ok {
421422
return nil
422423
}
423424

424-
return &HealthInsight{
425+
return &updatestatus.HealthInsight{
425426
StartedAt: now,
426-
Scope: InsightScope{
427-
Type: ControlPlaneScope,
428-
Resources: []ResourceRef{{Resource: "clusterversions", Group: configv1.GroupName, Name: cv.Name}},
427+
Scope: updatestatus.InsightScope{
428+
Type: updatestatus.ControlPlaneScope,
429+
Resources: []updatestatus.ResourceRef{{Resource: "clusterversions", Group: configv1.GroupName, Name: cv.Name}},
429430
},
430-
Impact: InsightImpact{
431-
Level: InfoImpactLevel,
432-
Type: NoneImpactType,
431+
Impact: updatestatus.InsightImpact{
432+
Level: updatestatus.InfoImpactLevel,
433+
Type: updatestatus.NoneImpactType,
433434
Summary: fmt.Sprintf("Forced health insight for ClusterVersion %s", cv.Name),
434435
Description: fmt.Sprintf("The resource has a %q annotation which forces USC to generate this health insight for testing purposes.", uscForceHealthInsightAnnotation),
435436
},
436-
Remediation: InsightRemediation{
437+
Remediation: updatestatus.InsightRemediation{
437438
Reference: "https://issues.redhat.com/browse/OTA-1418",
438439
},
439440
}
@@ -451,7 +452,7 @@ func estimateCompletion(started time.Time) time.Time {
451452
// Reason and Message fields will explain why.
452453
func isControlPlaneUpdating(cvProgressing *configv1.ClusterOperatorStatusCondition, lastHistoryItem *configv1.UpdateHistory) (metav1.Condition, metav1.Time, metav1.Time) {
453454
updating := metav1.Condition{
454-
Type: string(ClusterVersionStatusInsightUpdating),
455+
Type: string(updatestatus.ClusterVersionStatusInsightUpdating),
455456
}
456457

457458
if cvProgressing == nil {
@@ -495,7 +496,7 @@ func isControlPlaneUpdating(cvProgressing *configv1.ClusterOperatorStatusConditi
495496

496497
func setCannotDetermineUpdating(cond *metav1.Condition, message string) {
497498
cond.Status = metav1.ConditionUnknown
498-
cond.Reason = string(ClusterVersionCannotDetermineUpdating)
499+
cond.Reason = string(updatestatus.ClusterVersionCannotDetermineUpdating)
499500
cond.Message = message
500501
}
501502

@@ -506,13 +507,13 @@ func cvProgressingToUpdating(cvProgressing configv1.ClusterOperatorStatusConditi
506507
var reason string
507508
switch status {
508509
case metav1.ConditionTrue:
509-
reason = string(ClusterVersionProgressing)
510+
reason = string(updatestatus.ClusterVersionProgressing)
510511
case metav1.ConditionFalse:
511-
reason = string(ClusterVersionNotProgressing)
512+
reason = string(updatestatus.ClusterVersionNotProgressing)
512513
case metav1.ConditionUnknown:
513-
reason = string(ClusterVersionCannotDetermineUpdating)
514+
reason = string(updatestatus.ClusterVersionCannotDetermineUpdating)
514515
default:
515-
reason = string(ClusterVersionCannotDetermineUpdating)
516+
reason = string(updatestatus.ClusterVersionCannotDetermineUpdating)
516517
}
517518

518519
message := fmt.Sprintf("ClusterVersion has Progressing=%s(Reason=%s) | Message='%s'", cvProgressing.Status, cvProgressing.Reason, cvProgressing.Message)
@@ -521,8 +522,8 @@ func cvProgressingToUpdating(cvProgressing configv1.ClusterOperatorStatusConditi
521522

522523
// versionsFromHistory returns a ControlPlaneUpdateVersions struct with the target version and metadata from the given
523524
// history.
524-
func versionsFromHistory(history []configv1.UpdateHistory) ControlPlaneUpdateVersions {
525-
var versions ControlPlaneUpdateVersions
525+
func versionsFromHistory(history []configv1.UpdateHistory) updatestatus.ControlPlaneUpdateVersions {
526+
var versions updatestatus.ControlPlaneUpdateVersions
526527

527528
if len(history) == 0 {
528529
return versions
@@ -531,12 +532,12 @@ func versionsFromHistory(history []configv1.UpdateHistory) ControlPlaneUpdateVer
531532
versions.Target.Version = history[0].Version
532533

533534
if len(history) == 1 {
534-
versions.Target.Metadata = []VersionMetadata{{Key: InstallationMetadata}}
535+
versions.Target.Metadata = []updatestatus.VersionMetadata{{Key: updatestatus.InstallationMetadata}}
535536
}
536537
if len(history) > 1 {
537538
versions.Previous.Version = history[1].Version
538539
if history[1].State == configv1.PartialUpdate {
539-
versions.Previous.Metadata = []VersionMetadata{{Key: PartialMetadata}}
540+
versions.Previous.Metadata = []updatestatus.VersionMetadata{{Key: updatestatus.PartialMetadata}}
540541
}
541542
}
542543
return versions

0 commit comments

Comments
 (0)