Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Degraded condition to HCP #1560

Merged
merged 1 commit into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -2661,6 +2661,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