Skip to content

Commit

Permalink
Merge pull request #1820 from dlom/hive-1935
Browse files Browse the repository at this point in the history
Generics: The Future
  • Loading branch information
openshift-merge-robot authored Jul 21, 2022
2 parents a59276b + 4ae1f97 commit 34a0d90
Show file tree
Hide file tree
Showing 53 changed files with 352 additions and 224 deletions.
10 changes: 10 additions & 0 deletions apis/hive/v1/clusterclaim_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ type ClusterClaimCondition struct {
// ClusterClaimConditionType is a valid value for ClusterClaimCondition.Type.
type ClusterClaimConditionType string

// ConditionType satisfies the conditions.Condition interface
func (c ClusterClaimCondition) ConditionType() ConditionType {
return c.Type
}

// String satisfies the conditions.ConditionType interface
func (t ClusterClaimConditionType) String() string {
return string(t)
}

const (
// ClusterClaimPendingCondition is set when a cluster has not yet been assigned and made ready to the claim.
ClusterClaimPendingCondition ClusterClaimConditionType = "Pending"
Expand Down
10 changes: 10 additions & 0 deletions apis/hive/v1/clusterdeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,16 @@ type ClusterDeploymentCondition struct {
// ClusterDeploymentConditionType is a valid value for ClusterDeploymentCondition.Type
type ClusterDeploymentConditionType string

// ConditionType satisfies the conditions.Condition interface
func (c ClusterDeploymentCondition) ConditionType() ConditionType {
return c.Type
}

// String satisfies the conditions.ConditionType interface
func (t ClusterDeploymentConditionType) String() string {
return string(t)
}

const (
// InstallerImageResolutionFailedCondition is a condition that indicates whether the job
// to determine the installer image based on a release image was successful.
Expand Down
10 changes: 10 additions & 0 deletions apis/hive/v1/clusterdeprovision_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ type ClusterDeprovisionCondition struct {
// ClusterDeprovisionConditionType is a valid value for ClusterDeprovisionCondition.Type
type ClusterDeprovisionConditionType string

// ConditionType satisfies the conditions.Condition interface
func (c ClusterDeprovisionCondition) ConditionType() ConditionType {
return c.Type
}

// String satisfies the conditions.ConditionType interface
func (t ClusterDeprovisionConditionType) String() string {
return string(t)
}

const (
// AuthenticationFailureClusterDeprovisionCondition is true when credentials cannot be used because of authentication failure
AuthenticationFailureClusterDeprovisionCondition ClusterDeprovisionConditionType = "AuthenticationFailure"
Expand Down
22 changes: 17 additions & 5 deletions apis/hive/v1/clusterinstall_conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// ClusterInstallCondition contains details for the current condition of a cluster install.
type ClusterInstallCondition struct {
// Type is the type of the condition.
Type string `json:"type"`
Type ClusterInstallConditionType `json:"type"`
// Status is the status of the condition.
Status corev1.ConditionStatus `json:"status"`
// LastProbeTime is the last time we probed the condition.
Expand All @@ -27,20 +27,32 @@ type ClusterInstallCondition struct {
Message string `json:"message,omitempty"`
}

type ClusterInstallConditionType string

// ConditionType satisfies the conditions.Condition interface
func (c ClusterInstallCondition) ConditionType() ConditionType {
return c.Type
}

// String satisfies the conditions.ConditionType interface
func (t ClusterInstallConditionType) String() string {
return string(t)
}

const (
// ClusterInstallRequirementsMet is True when all pre-install requirements have been met.
ClusterInstallRequirementsMet = "RequirementsMet"
ClusterInstallRequirementsMet ClusterInstallConditionType = "RequirementsMet"

// ClusterInstallCompleted is True when the requested install has been completed successfully.
ClusterInstallCompleted = "Completed"
ClusterInstallCompleted ClusterInstallConditionType = "Completed"

// ClusterInstallFailed is True when an attempt to install the cluster has failed.
// The ClusterInstall controllers may still be retrying if supported, and this condition will
// go back to False if a later attempt succeeds.
ClusterInstallFailed = "Failed"
ClusterInstallFailed ClusterInstallConditionType = "Failed"

// ClusterInstallStopped is True the controllers are no longer working on this
// ClusterInstall. Combine with Completed or Failed to know if the overall request was
// successful or not.
ClusterInstallStopped = "Stopped"
ClusterInstallStopped ClusterInstallConditionType = "Stopped"
)
10 changes: 10 additions & 0 deletions apis/hive/v1/clusterpool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@ type ClusterPoolCondition struct {
// ClusterPoolConditionType is a valid value for ClusterPoolCondition.Type
type ClusterPoolConditionType string

// ConditionType satisfies the conditions.Condition interface
func (c ClusterPoolCondition) ConditionType() ConditionType {
return c.Type
}

// String satisfies the conditions.ConditionType interface
func (t ClusterPoolConditionType) String() string {
return string(t)
}

const (
// ClusterPoolMissingDependenciesCondition is set when a cluster pool is missing dependencies required to create a
// cluster. Dependencies include resources such as the ClusterImageSet and the credentials Secret.
Expand Down
10 changes: 10 additions & 0 deletions apis/hive/v1/clusterprovision_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ type ClusterProvisionCondition struct {
// ClusterProvisionConditionType is a valid value for ClusterProvisionCondition.Type
type ClusterProvisionConditionType string

// ConditionType satisfies the conditions.Condition interface
func (c ClusterProvisionCondition) ConditionType() ConditionType {
return c.Type
}

// String satisfies the conditions.ConditionType interface
func (t ClusterProvisionConditionType) String() string {
return string(t)
}

const (
// ClusterProvisionInitializedCondition is set when a cluster provision has finished initialization.
ClusterProvisionInitializedCondition ClusterProvisionConditionType = "ClusterProvisionInitialized"
Expand Down
11 changes: 11 additions & 0 deletions apis/hive/v1/conditions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package v1

import "fmt"

type Condition interface {
ConditionType() ConditionType
}

type ConditionType interface {
fmt.Stringer
}
10 changes: 10 additions & 0 deletions apis/hive/v1/dnszone_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ type DNSZoneCondition struct {
// DNSZoneConditionType is a valid value for DNSZoneCondition.Type
type DNSZoneConditionType string

// ConditionType satisfies the conditions.Condition interface
func (c DNSZoneCondition) ConditionType() ConditionType {
return c.Type
}

// String satisfies the conditions.ConditionType interface
func (t DNSZoneConditionType) String() string {
return string(t)
}

const (
// ZoneAvailableDNSZoneCondition is true if the DNSZone is responding to DNS queries
ZoneAvailableDNSZoneCondition DNSZoneConditionType = "ZoneAvailable"
Expand Down
10 changes: 10 additions & 0 deletions apis/hive/v1/machinepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ type MachinePoolCondition struct {
// MachinePoolConditionType is a valid value for MachinePoolCondition.Type
type MachinePoolConditionType string

// ConditionType satisfies the conditions.Condition interface
func (c MachinePoolCondition) ConditionType() ConditionType {
return c.Type
}

// String satisfies the conditions.ConditionType interface
func (t MachinePoolConditionType) String() string {
return string(t)
}

const (
// NotEnoughReplicasMachinePoolCondition is true when the minReplicas field
// is set too low for the number of machinesets for the machine pool.
Expand Down
10 changes: 10 additions & 0 deletions apis/hive/v1/syncset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ type SecretMapping struct {
// SyncConditionType is a valid value for SyncCondition.Type
type SyncConditionType string

// ConditionType satisfies the conditions.Condition interface
func (c SyncCondition) ConditionType() ConditionType {
return c.Type
}

// String satisfies the conditions.ConditionType interface
func (t SyncConditionType) String() string {
return string(t)
}

const (
// ApplySuccessSyncCondition indicates whether the resource or patch has been applied.
ApplySuccessSyncCondition SyncConditionType = "ApplySuccess"
Expand Down
11 changes: 11 additions & 0 deletions apis/hiveinternal/v1alpha1/clustersync_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1

import (
hivev1 "github.com/openshift/hive/apis/hive/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -132,6 +133,16 @@ type ClusterSyncCondition struct {
// ClusterSyncConditionType is a valid value for ClusterSyncCondition.Type
type ClusterSyncConditionType string

// ConditionType satisfies the generics.Condition interface
func (c ClusterSyncCondition) ConditionType() hivev1.ConditionType {
return c.Type
}

// String satisfies the generics.ConditionType interface
func (t ClusterSyncConditionType) String() string {
return string(t)
}

const (
// ClusterSyncFailed is the type of condition used to indicate whether there are SyncSets or SelectorSyncSets which
// have not been applied due to an error.
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/awsprivatelink/awsprivatelink_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,12 @@ func shouldSync(desired *hivev1.ClusterDeployment) (bool, time.Duration) {
return true, 0 // We're in a deleting state, sync now.
}

failedCondition := controllerutils.FindClusterDeploymentCondition(desired.Status.Conditions, hivev1.AWSPrivateLinkFailedClusterDeploymentCondition)
failedCondition := controllerutils.FindCondition(desired.Status.Conditions, hivev1.AWSPrivateLinkFailedClusterDeploymentCondition)
if failedCondition != nil && failedCondition.Status == corev1.ConditionTrue {
return true, 0 // we have failed to reconcile and therefore should continue to retry for quick recovery
}

readyCondition := controllerutils.FindClusterDeploymentCondition(desired.Status.Conditions, hivev1.AWSPrivateLinkReadyClusterDeploymentCondition)
readyCondition := controllerutils.FindCondition(desired.Status.Conditions, hivev1.AWSPrivateLinkReadyClusterDeploymentCondition)
if readyCondition == nil || readyCondition.Status != corev1.ConditionTrue {
return true, 0 // we have not reached Ready level
}
Expand Down Expand Up @@ -403,7 +403,7 @@ func (r *ReconcileAWSPrivateLink) setReadyCondition(cd *hivev1.ClusterDeployment
}

var readyChanged bool
ready := controllerutils.FindClusterDeploymentCondition(conditions, hivev1.AWSPrivateLinkReadyClusterDeploymentCondition)
ready := controllerutils.FindCondition(conditions, hivev1.AWSPrivateLinkReadyClusterDeploymentCondition)
if ready == nil || ready.Status != corev1.ConditionTrue {
// we want to allow Ready condition to reach Ready level
conditions, readyChanged = controllerutils.SetClusterDeploymentConditionWithChangeCheck(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1786,7 +1786,7 @@ users:
}

for _, cond := range clusterDeploymentAWSPrivateLinkConditions {
if present := controllerutils.FindClusterDeploymentCondition(cd.Status.Conditions,
if present := controllerutils.FindCondition(cd.Status.Conditions,
cond); present == nil {
test.expectedConditions = append(test.expectedConditions, hivev1.ClusterDeploymentCondition{
Status: corev1.ConditionUnknown,
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/clusterclaim/clusterclaim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func (r *ReconcileClusterClaim) Reconcile(ctx context.Context, request reconcile
// Delete ClusterClaim after its lifetime elapses
if lifetime != nil {
logger.WithField("lifetime", lifetime).Debug("checking whether lifetime of ClusterClaim has elapsed")
pendingCond := controllerutils.FindClusterClaimCondition(claim.Status.Conditions, hivev1.ClusterClaimPendingCondition)
pendingCond := controllerutils.FindCondition(claim.Status.Conditions, hivev1.ClusterClaimPendingCondition)
if pendingCond.Status == corev1.ConditionFalse {
if timeSinceAssigned := time.Since(pendingCond.LastTransitionTime.Time); timeSinceAssigned >= lifetime.Duration {
logger.WithField("timeSinceAssigned", timeSinceAssigned).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ func TestReconcileClusterClaim(t *testing.T) {
}

for _, expectedCond := range test.expectedConditions {
cond := controllerutils.FindClusterClaimCondition(claim.Status.Conditions, expectedCond.Type)
cond := controllerutils.FindCondition(claim.Status.Conditions, expectedCond.Type)
if assert.NotNilf(t, cond, "did not find expected condition type: %v", expectedCond.Type) {
assert.Equal(t, expectedCond.Status, cond.Status, "condition found with unexpected status")
if expectedCond.Reason != "" {
Expand Down
24 changes: 12 additions & 12 deletions pkg/controller/clusterdeployment/clusterdeployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ func (r *ReconcileClusterDeployment) reconcile(request reconcile.Request, cd *hi
}

// If the platform credentials are no good, return error and go into backoff
authCondition := controllerutils.FindClusterDeploymentCondition(cd.Status.Conditions, hivev1.AuthenticationFailureClusterDeploymentCondition)
authCondition := controllerutils.FindCondition(cd.Status.Conditions, hivev1.AuthenticationFailureClusterDeploymentCondition)
if authCondition.Status == corev1.ConditionTrue {
authError := errors.New(authCondition.Message)
cdLog.WithError(authError).Error("cannot proceed with provision while platform credentials authentication is failing.")
Expand Down Expand Up @@ -840,7 +840,7 @@ func (r *ReconcileClusterDeployment) reconcileInstallingClusterInstall(cd *hivev
}

func dnsZoneNotReadyMaybeTimedOut(cd *hivev1.ClusterDeployment, logger log.FieldLogger) (string, string, time.Duration) {
cond := controllerutils.FindClusterDeploymentCondition(cd.Status.Conditions, hivev1.DNSNotReadyCondition)
cond := controllerutils.FindCondition(cd.Status.Conditions, hivev1.DNSNotReadyCondition)
if cond == nil || (cond.Reason != dnsNotReadyReason && cond.Reason != dnsNotReadyTimedoutReason) {
// First time we're setting the condition to "not ready".
// If the DNSZone becomes ready, it'll pop this controller right away.
Expand Down Expand Up @@ -1116,7 +1116,7 @@ func (r *ReconcileClusterDeployment) setReqsMetConditionImageSetNotFound(cd *hiv
controllerutils.UpdateConditionIfReasonOrMessageChange)
} else {
// Set the RequirementsMet condition status back to unknown if True and it's current reason matches
reqsCond := controllerutils.FindClusterDeploymentCondition(cd.Status.Conditions,
reqsCond := controllerutils.FindCondition(cd.Status.Conditions,
hivev1.RequirementsMetCondition)
if reqsCond.Status == corev1.ConditionFalse && reqsCond.Reason == clusterImageSetNotFoundReason {
conds, changed = controllerutils.SetClusterDeploymentConditionWithChangeCheck(
Expand All @@ -1132,7 +1132,7 @@ func (r *ReconcileClusterDeployment) setReqsMetConditionImageSetNotFound(cd *hiv
return nil
}
cd.Status.Conditions = conds
reqsCond := controllerutils.FindClusterDeploymentCondition(cd.Status.Conditions,
reqsCond := controllerutils.FindCondition(cd.Status.Conditions,
hivev1.RequirementsMetCondition)
cdLog.Infof("updating RequirementsMetCondition: status=%s reason=%s", reqsCond.Status, reqsCond.Reason)
err := r.Status().Update(context.TODO(), cd)
Expand Down Expand Up @@ -1288,7 +1288,7 @@ func (r *ReconcileClusterDeployment) ensureClusterDeprovisioned(cd *hivev1.Clust
return false, err
}

authenticationFailureCondition := controllerutils.FindClusterDeprovisionCondition(existingRequest.Status.Conditions, hivev1.AuthenticationFailureClusterDeprovisionCondition)
authenticationFailureCondition := controllerutils.FindCondition(existingRequest.Status.Conditions, hivev1.AuthenticationFailureClusterDeprovisionCondition)
if authenticationFailureCondition != nil {
var conds []hivev1.ClusterDeploymentCondition
var changed1, changed2, authFailure bool
Expand Down Expand Up @@ -1433,7 +1433,7 @@ func (r *ReconcileClusterDeployment) setDNSDelayMetric(cd *hivev1.ClusterDeploym
return false, nil
}

readyCondition := controllerutils.FindDNSZoneCondition(dnsZone.Status.Conditions, hivev1.ZoneAvailableDNSZoneCondition)
readyCondition := controllerutils.FindCondition(dnsZone.Status.Conditions, hivev1.ZoneAvailableDNSZoneCondition)

if readyCondition == nil || readyCondition.Status != corev1.ConditionTrue {
msg := "did not find timestamp for when dnszone became ready"
Expand Down Expand Up @@ -1530,11 +1530,11 @@ func (r *ReconcileClusterDeployment) ensureManagedDNSZone(cd *hivev1.ClusterDepl
return true, reconcile.Result{}, errors.New("Existing unowned DNS zone")
}

availableCondition := controllerutils.FindDNSZoneCondition(dnsZone.Status.Conditions, hivev1.ZoneAvailableDNSZoneCondition)
insufficientCredentialsCondition := controllerutils.FindDNSZoneCondition(dnsZone.Status.Conditions, hivev1.InsufficientCredentialsCondition)
authenticationFailureCondition := controllerutils.FindDNSZoneCondition(dnsZone.Status.Conditions, hivev1.AuthenticationFailureCondition)
apiOptInRequiredCondition := controllerutils.FindDNSZoneCondition(dnsZone.Status.Conditions, hivev1.APIOptInRequiredCondition)
dnsErrorCondition := controllerutils.FindDNSZoneCondition(dnsZone.Status.Conditions, hivev1.GenericDNSErrorsCondition)
availableCondition := controllerutils.FindCondition(dnsZone.Status.Conditions, hivev1.ZoneAvailableDNSZoneCondition)
insufficientCredentialsCondition := controllerutils.FindCondition(dnsZone.Status.Conditions, hivev1.InsufficientCredentialsCondition)
authenticationFailureCondition := controllerutils.FindCondition(dnsZone.Status.Conditions, hivev1.AuthenticationFailureCondition)
apiOptInRequiredCondition := controllerutils.FindCondition(dnsZone.Status.Conditions, hivev1.APIOptInRequiredCondition)
dnsErrorCondition := controllerutils.FindCondition(dnsZone.Status.Conditions, hivev1.GenericDNSErrorsCondition)
var (
status corev1.ConditionStatus
reason, message string
Expand Down Expand Up @@ -2034,7 +2034,7 @@ func (r *ReconcileClusterDeployment) validatePlatformCreds(cd *hivev1.ClusterDep

// checkForFailedSync returns true if it finds that the ClusterSync has the Failed condition set
func checkForFailedSync(clusterSync *hiveintv1alpha1.ClusterSync) bool {
cond := controllerutils.FindClusterSyncCondition(clusterSync.Status.Conditions, hiveintv1alpha1.ClusterSyncFailed)
cond := controllerutils.FindCondition(clusterSync.Status.Conditions, hiveintv1alpha1.ClusterSyncFailed)
if cond != nil {
return cond.Status == corev1.ConditionTrue
}
Expand Down
Loading

0 comments on commit 34a0d90

Please sign in to comment.