Skip to content

Commit

Permalink
Merge pull request stolostron#375 from ldpliu/bma-reason
Browse files Browse the repository at this point in the history
create const to contain BMA status reason
  • Loading branch information
openshift-merge-robot authored Jun 22, 2021
2 parents 54a2874 + ae99a70 commit 4db33f7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
19 changes: 19 additions & 0 deletions pkg/apis/inventory/v1alpha1/baremetalasset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,25 @@ const (
ConditionAssetSyncCompleted string = "AssetSyncCompleted"
)

// Condition Reasons
const (
ConditionReasonSecretNotFound string = "SecretNotFound"
ConditionReasonSecretFound string = "SecretFound"
ConditionReasonNoneSpecified string = "NoneSpecified"
ConditionReasonClusterDeploymentNotFound string = "ClusterDeploymentNotFound"
ConditionReasonClusterDeploymentFound string = "ClusterDeploymentFound"
ConditionReasonSyncSetCreationFailed string = "SyncSetCreationFailed"
ConditionReasonSyncSetCreated string = "SyncSetCreated"
ConditionReasonSyncSetGetFailed string = "SyncSetGetFailed"
ConditionReasonSyncSetUpdateFailed string = "SyncSetUpdateFailed"
ConditionReasonSyncSetUpdated string = "SyncSetUpdated"
ConditionReasonSyncStatusNotFound string = "SyncStatusNotFound"
ConditionReasonSyncSetNotApplied string = "SyncSetNotApplied"
ConditionReasonSyncSetAppliedSuccessful string = "SyncSetAppliedSuccessful"
ConditionReasonSyncSetAppliedFailed string = "SyncSetAppliedFailed"
ConditionReasonUnexpectedResourceCount string = "UnexpectedResourceCount"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// BareMetalAsset is the Schema for the baremetalassets API
Expand Down
38 changes: 19 additions & 19 deletions pkg/controllers/inventory/inventory_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func (r *ReconcileBareMetalAsset) checkAssetSecret(ctx context.Context, instance
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
Type: inventoryv1alpha1.ConditionCredentialsFound,
Status: metav1.ConditionFalse,
Reason: "SecretNotFound",
Reason: inventoryv1alpha1.ConditionReasonSecretNotFound,
Message: err.Error(),
})
return bmaerrors.NewAssetSecretNotFoundError(secretName, instance.Namespace)
Expand All @@ -337,7 +337,7 @@ func (r *ReconcileBareMetalAsset) checkAssetSecret(ctx context.Context, instance
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
Type: inventoryv1alpha1.ConditionCredentialsFound,
Status: metav1.ConditionTrue,
Reason: "SecretFound",
Reason: inventoryv1alpha1.ConditionReasonSecretFound,
Message: fmt.Sprintf("A secret with the name %v in namespace %v was found", secretName, instance.Namespace),
})

Expand Down Expand Up @@ -378,7 +378,7 @@ func (r *ReconcileBareMetalAsset) checkClusterDeployment(ctx context.Context, in
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
Type: inventoryv1alpha1.ConditionClusterDeploymentFound,
Status: metav1.ConditionFalse,
Reason: "NoneSpecified",
Reason: inventoryv1alpha1.ConditionReasonNoneSpecified,
Message: "No cluster deployment specified",
})
meta.RemoveStatusCondition(&instance.Status.Conditions, inventoryv1alpha1.ConditionAssetSyncStarted)
Expand All @@ -397,7 +397,7 @@ func (r *ReconcileBareMetalAsset) checkClusterDeployment(ctx context.Context, in
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
Type: inventoryv1alpha1.ConditionClusterDeploymentFound,
Status: metav1.ConditionFalse,
Reason: "ClusterDeploymentNotFound",
Reason: inventoryv1alpha1.ConditionReasonClusterDeploymentNotFound,
Message: err.Error(),
})
return err
Expand All @@ -409,7 +409,7 @@ func (r *ReconcileBareMetalAsset) checkClusterDeployment(ctx context.Context, in
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
Type: inventoryv1alpha1.ConditionClusterDeploymentFound,
Status: metav1.ConditionTrue,
Reason: "ClusterDeploymentFound",
Reason: inventoryv1alpha1.ConditionReasonClusterDeploymentFound,
Message: fmt.Sprintf("A ClusterDeployment with the name %v in namespace %v was found", cd.Name, cd.Namespace),
})

Expand All @@ -429,7 +429,7 @@ func (r *ReconcileBareMetalAsset) ensureHiveSyncSet(ctx context.Context, instanc
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
Type: inventoryv1alpha1.ConditionAssetSyncStarted,
Status: metav1.ConditionFalse,
Reason: "SyncSetCreationFailed",
Reason: inventoryv1alpha1.ConditionReasonSyncSetCreationFailed,
Message: "Failed to create SyncSet",
})
return err
Expand All @@ -438,7 +438,7 @@ func (r *ReconcileBareMetalAsset) ensureHiveSyncSet(ctx context.Context, instanc
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
Type: inventoryv1alpha1.ConditionAssetSyncStarted,
Status: metav1.ConditionTrue,
Reason: "SyncSetCreated",
Reason: inventoryv1alpha1.ConditionReasonSyncSetCreated,
Message: "SyncSet created successfully",
})
return nil
Expand All @@ -447,7 +447,7 @@ func (r *ReconcileBareMetalAsset) ensureHiveSyncSet(ctx context.Context, instanc
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
Type: inventoryv1alpha1.ConditionAssetSyncStarted,
Status: metav1.ConditionFalse,
Reason: "SyncSetGetFailed",
Reason: inventoryv1alpha1.ConditionReasonSyncSetGetFailed,
Message: "Failed to get SyncSet",
})
klog.Errorf("Failed to get Hive SyncSet (%s/%s), %v", hsc.Namespace, hsc.Name, err)
Expand Down Expand Up @@ -488,15 +488,15 @@ func (r *ReconcileBareMetalAsset) ensureHiveSyncSet(ctx context.Context, instanc
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
Type: inventoryv1alpha1.ConditionAssetSyncStarted,
Status: metav1.ConditionFalse,
Reason: "SyncSetUpdateFailed",
Reason: inventoryv1alpha1.ConditionReasonSyncSetUpdateFailed,
Message: "Failed to update SyncSet",
})
return err
}
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
Type: inventoryv1alpha1.ConditionAssetSyncStarted,
Status: metav1.ConditionTrue,
Reason: "SyncSetUpdated",
Reason: inventoryv1alpha1.ConditionReasonSyncSetUpdated,
Message: "SyncSet updated successfully",
})
}
Expand Down Expand Up @@ -620,7 +620,7 @@ func (r *ReconcileBareMetalAsset) checkHiveClusterSync(ctx context.Context, inst
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
Type: inventoryv1alpha1.ConditionAssetSyncCompleted,
Status: metav1.ConditionFalse,
Reason: "SyncStatusNotFound",
Reason: inventoryv1alpha1.ConditionReasonSyncStatusNotFound,
Message: fmt.Sprintf("Problem getting Hive SyncSet for Name %s in Namespace %s, %v",
syncSetNsN.Name, syncSetNsN.Namespace, err),
})
Expand All @@ -638,7 +638,7 @@ func (r *ReconcileBareMetalAsset) checkHiveClusterSync(ctx context.Context, inst
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
Type: inventoryv1alpha1.ConditionAssetSyncCompleted,
Status: metav1.ConditionFalse,
Reason: "SyncStatusNotFound",
Reason: inventoryv1alpha1.ConditionReasonSyncStatusNotFound,
Message: fmt.Sprintf("Problem getting Hive ClusterSync for ClusterDeployment.Name %s in Namespace %s, %v",
clusterSyncNsN.Name, clusterSyncNsN.Namespace, err),
})
Expand All @@ -658,7 +658,7 @@ func (r *ReconcileBareMetalAsset) checkHiveClusterSync(ctx context.Context, inst
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
Type: inventoryv1alpha1.ConditionAssetSyncCompleted,
Status: metav1.ConditionFalse,
Reason: "SyncStatusNotFound",
Reason: inventoryv1alpha1.ConditionReasonSyncStatusNotFound,
Message: err.Error(),
})
return false
Expand All @@ -670,7 +670,7 @@ func (r *ReconcileBareMetalAsset) checkHiveClusterSync(ctx context.Context, inst
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
Type: inventoryv1alpha1.ConditionAssetSyncStarted,
Status: metav1.ConditionFalse,
Reason: "SyncSetNotApplied",
Reason: inventoryv1alpha1.ConditionReasonSyncSetNotApplied,
Message: "SyncSet not yet been applied",
})
return false
Expand All @@ -692,7 +692,7 @@ func (r *ReconcileBareMetalAsset) checkHiveSyncStatus(ctx context.Context,
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
Type: inventoryv1alpha1.ConditionAssetSyncCompleted,
Status: metav1.ConditionTrue,
Reason: "SyncSetAppliedSuccessful",
Reason: inventoryv1alpha1.ConditionReasonSyncSetAppliedSuccessful,
Message: "Successfully applied SyncSet",
})
return true
Expand All @@ -701,7 +701,7 @@ func (r *ReconcileBareMetalAsset) checkHiveSyncStatus(ctx context.Context,
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
Type: inventoryv1alpha1.ConditionAssetSyncCompleted,
Status: metav1.ConditionFalse,
Reason: "SyncSetAppliedFailed",
Reason: inventoryv1alpha1.ConditionReasonSyncSetAppliedFailed,
Message: fmt.Sprintf("Failed to apply SyncSet with err %s", syncSetStatus.FailureMessage),
})
return false
Expand All @@ -712,7 +712,7 @@ func (r *ReconcileBareMetalAsset) checkHiveSyncStatus(ctx context.Context,
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
Type: inventoryv1alpha1.ConditionAssetSyncCompleted,
Status: metav1.ConditionTrue,
Reason: "SyncSetAppliedSuccessful",
Reason: inventoryv1alpha1.ConditionReasonSyncSetAppliedSuccessful,
Message: "Successfully applied SyncSet",
})
return true
Expand All @@ -721,7 +721,7 @@ func (r *ReconcileBareMetalAsset) checkHiveSyncStatus(ctx context.Context,
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
Type: inventoryv1alpha1.ConditionAssetSyncCompleted,
Status: metav1.ConditionFalse,
Reason: "SyncSetAppliedFailed",
Reason: inventoryv1alpha1.ConditionReasonSyncSetAppliedFailed,
Message: fmt.Sprintf("Failed to apply SyncSet with err %s", syncSetStatus.FailureMessage),
})

Expand All @@ -741,7 +741,7 @@ func (r *ReconcileBareMetalAsset) checkHiveSyncStatus(ctx context.Context,
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
Type: inventoryv1alpha1.ConditionAssetSyncCompleted,
Status: metav1.ConditionFalse,
Reason: "UnexpectedResourceCount",
Reason: inventoryv1alpha1.ConditionReasonUnexpectedResourceCount,
Message: err.Error(),
})

Expand Down

0 comments on commit 4db33f7

Please sign in to comment.