Skip to content

Commit

Permalink
Merge pull request openshift#1560 from sjenning/hcp-degraded-condition
Browse files Browse the repository at this point in the history
add Degraded condition to HCP
  • Loading branch information
openshift-ci[bot] authored Jul 15, 2022
2 parents 406c43d + c5978b1 commit cc0f5af
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions api/v1alpha1/hosted_controlplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ type ConditionType string

const (
HostedControlPlaneAvailable ConditionType = "Available"
HostedControlPlaneDegraded ConditionType = "Degraded"
EtcdAvailable ConditionType = "EtcdAvailable"
EtcdSnapshotRestored ConditionType = "EtcdSnapshotRestored"
KubeAPIServerAvailable ConditionType = "KubeAPIServerAvailable"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,37 @@ func (r *HostedControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.R
meta.SetStatusCondition(&hostedControlPlane.Status.Conditions, newCondition)
}

// Reconcile Degraded status
{
condition := metav1.Condition{
Type: string(hyperv1.HostedControlPlaneDegraded),
Status: metav1.ConditionFalse,
Reason: hyperv1.AsExpectedReason,
ObservedGeneration: hostedControlPlane.Generation,
}
cpoManagedDeploymentList := &appsv1.DeploymentList{}
if err := r.List(ctx, cpoManagedDeploymentList, client.MatchingLabels{
config.ManagedByLabel: "control-plane-operator",
}, client.InNamespace(hostedControlPlane.Namespace)); err != nil {
if !apierrors.IsNotFound(err) {
return ctrl.Result{}, fmt.Errorf("failed to list managed deployments in namespace %s: %w", hostedControlPlane.Namespace, err)
}
}
var errs []error
for _, deployment := range cpoManagedDeploymentList.Items {
if deployment.Status.UnavailableReplicas > 0 {
errs = append(errs, fmt.Errorf("%s deployment has %d unavailable replicas", deployment.Name, deployment.Status.UnavailableReplicas))
}
}
err := utilerrors.NewAggregate(errs)
if err != nil {
condition.Status = metav1.ConditionTrue
condition.Reason = "UnavailableReplicas"
condition.Message = err.Error()
}
meta.SetStatusCondition(&hostedControlPlane.Status.Conditions, condition)
}

// Reconcile infrastructure status
{
r.Log.Info("Reconciling infrastructure status")
Expand Down
2 changes: 2 additions & 0 deletions docs/content/reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2679,6 +2679,8 @@ an initial deployment or upgrade.</p>
</td>
</tr><tr><td><p>&#34;Available&#34;</p></td>
<td></td>
</tr><tr><td><p>&#34;Degraded&#34;</p></td>
<td></td>
</tr><tr><td><p>&#34;IgnitionEndpointAvailable&#34;</p></td>
<td><p>IgnitionEndpointAvailable indicates whether the ignition server for the
HostedCluster is available to handle ignition requests.</p>
Expand Down
6 changes: 3 additions & 3 deletions support/config/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"k8s.io/utils/pointer"
)

var (
managedByLabel = "hypershift.openshift.io/managed-by"
const (
ManagedByLabel = "hypershift.openshift.io/managed-by"
)

type DeploymentConfig struct {
Expand Down Expand Up @@ -208,7 +208,7 @@ func (c *DeploymentConfig) ApplyTo(deployment *appsv1.Deployment) {
if deployment.Labels == nil {
deployment.Labels = map[string]string{}
}
deployment.Labels[managedByLabel] = "control-plane-operator"
deployment.Labels[ManagedByLabel] = "control-plane-operator"

c.Scheduling.ApplyTo(&deployment.Spec.Template.Spec)
c.AdditionalLabels.ApplyTo(&deployment.Spec.Template.ObjectMeta)
Expand Down

0 comments on commit cc0f5af

Please sign in to comment.