|
1 | 1 | package controlplane |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "context" |
5 | | - "fmt" |
6 | | - "reflect" |
7 | | - |
8 | | - controlplanev1beta1 "github.com/appthrust/capt/api/controlplane/v1beta1" |
9 | | - infrastructurev1beta1 "github.com/appthrust/capt/api/v1beta1" |
10 | | - "github.com/appthrust/capt/internal/controller/controlplane/endpoint" |
11 | | - xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" |
12 | | - corev1 "k8s.io/api/core/v1" |
13 | | - apierrors "k8s.io/apimachinery/pkg/api/errors" |
14 | | - "k8s.io/apimachinery/pkg/api/meta" |
15 | | - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
16 | | - "k8s.io/apimachinery/pkg/types" |
17 | | - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" |
18 | | - "sigs.k8s.io/cluster-api/errors" |
19 | | - "sigs.k8s.io/cluster-api/util/conditions" |
20 | | - ctrl "sigs.k8s.io/controller-runtime" |
21 | | - "sigs.k8s.io/controller-runtime/pkg/client" |
22 | | - "sigs.k8s.io/controller-runtime/pkg/log" |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "reflect" |
| 7 | + |
| 8 | + controlplanev1beta1 "github.com/appthrust/capt/api/controlplane/v1beta1" |
| 9 | + infrastructurev1beta1 "github.com/appthrust/capt/api/v1beta1" |
| 10 | + "github.com/appthrust/capt/internal/controller/controlplane/endpoint" |
| 11 | + xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" |
| 12 | + corev1 "k8s.io/api/core/v1" |
| 13 | + apierrors "k8s.io/apimachinery/pkg/api/errors" |
| 14 | + "k8s.io/apimachinery/pkg/api/meta" |
| 15 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 16 | + "k8s.io/apimachinery/pkg/types" |
| 17 | + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" |
| 18 | + "sigs.k8s.io/cluster-api/errors" |
| 19 | + "sigs.k8s.io/cluster-api/util/conditions" |
| 20 | + ctrl "sigs.k8s.io/controller-runtime" |
| 21 | + "sigs.k8s.io/controller-runtime/pkg/client" |
| 22 | + "sigs.k8s.io/controller-runtime/pkg/log" |
23 | 23 | ) |
24 | 24 |
|
25 | 25 | const ( |
@@ -95,32 +95,32 @@ func (r *Reconciler) updateStatus( |
95 | 95 | "workspaceStatus", controlPlane.Status.WorkspaceStatus, |
96 | 96 | "workspaceTemplateStatus", controlPlane.Status.WorkspaceTemplateStatus) |
97 | 97 |
|
98 | | - // Decide readiness and which WorkspaceTemplateApply to use for endpoint based on |
99 | | - // either the main control plane workspace OR the kubeconfig workspace. |
100 | | - effectiveApply := workspaceApply |
101 | | - ready := isWorkspaceReady(effectiveApply) |
102 | | - errorMessage := getWorkspaceError(effectiveApply) |
103 | | - |
104 | | - // Prefer kubeconfig WorkspaceTemplateApply if it exists and is Ready. |
105 | | - // This allows marking the control plane Ready even when addon installation |
106 | | - // is pending, avoiding deadlocks (e.g., sveltos waiting on Cluster Ready). |
107 | | - kubeApplyName := fmt.Sprintf("%s-kubeconfig-apply", controlPlane.Name) |
108 | | - kubeApply := &infrastructurev1beta1.WorkspaceTemplateApply{} |
109 | | - if err := r.Client.Get(ctx, types.NamespacedName{Name: kubeApplyName, Namespace: controlPlane.Namespace}, kubeApply); err == nil { |
110 | | - if isWorkspaceReady(kubeApply) { |
111 | | - effectiveApply = kubeApply |
112 | | - ready = true |
113 | | - errorMessage = "" |
114 | | - } |
115 | | - } |
116 | | - |
117 | | - if !ready { |
118 | | - return r.handleNotReadyStatus(ctx, controlPlane, cluster, errorMessage) |
119 | | - } |
| 98 | + // Decide readiness and which WorkspaceTemplateApply to use for endpoint based on |
| 99 | + // either the main control plane workspace OR the kubeconfig workspace. |
| 100 | + effectiveApply := workspaceApply |
| 101 | + ready := isWorkspaceReady(effectiveApply) |
| 102 | + errorMessage := getWorkspaceError(effectiveApply) |
| 103 | + |
| 104 | + // Prefer kubeconfig WorkspaceTemplateApply if it exists and is Ready. |
| 105 | + // This allows marking the control plane Ready even when addon installation |
| 106 | + // is pending, avoiding deadlocks (e.g., sveltos waiting on Cluster Ready). |
| 107 | + kubeApplyName := fmt.Sprintf("%s-kubeconfig-apply", controlPlane.Name) |
| 108 | + kubeApply := &infrastructurev1beta1.WorkspaceTemplateApply{} |
| 109 | + if err := r.Client.Get(ctx, types.NamespacedName{Name: kubeApplyName, Namespace: controlPlane.Namespace}, kubeApply); err == nil { |
| 110 | + if isWorkspaceReady(kubeApply) { |
| 111 | + effectiveApply = kubeApply |
| 112 | + ready = true |
| 113 | + errorMessage = "" |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + if !ready { |
| 118 | + return r.handleNotReadyStatus(ctx, controlPlane, cluster, errorMessage) |
| 119 | + } |
120 | 120 |
|
121 | 121 | // Update endpoint from workspace first |
122 | | - if effectiveApply.Status.WorkspaceName != "" { |
123 | | - if apiEndpoint, err := endpoint.GetEndpointFromWorkspace(ctx, r.Client, effectiveApply.Status.WorkspaceName); err != nil { |
| 122 | + if effectiveApply.Status.WorkspaceName != "" { |
| 123 | + if apiEndpoint, err := endpoint.GetEndpointFromWorkspace(ctx, r.Client, effectiveApply.Status.WorkspaceName); err != nil { |
124 | 124 | errMsg := fmt.Sprintf("Failed to get endpoint from workspace: %v", err) |
125 | 125 | return r.setFailedStatus(ctx, controlPlane, cluster, ReasonEndpointUpdateFailed, errMsg) |
126 | 126 | } else if apiEndpoint != nil { |
@@ -187,12 +187,16 @@ func (r *Reconciler) updateStatus( |
187 | 187 | controlPlane.Status.Phase = controlplanev1beta1.ControlPlaneReadyCondition |
188 | 188 | controlPlane.Status.Ready = true |
189 | 189 | controlPlane.Status.Initialized = true |
| 190 | + // Ensure WorkspaceTemplateStatus is initialized before accessing its fields |
| 191 | + if controlPlane.Status.WorkspaceTemplateStatus == nil { |
| 192 | + controlPlane.Status.WorkspaceTemplateStatus = &controlplanev1beta1.WorkspaceTemplateStatus{} |
| 193 | + } |
190 | 194 | controlPlane.Status.WorkspaceTemplateStatus.Ready = true |
191 | 195 | controlPlane.Status.FailureReason = nil |
192 | 196 | controlPlane.Status.FailureMessage = nil |
193 | 197 | controlPlane.Status.WorkspaceTemplateStatus.LastFailureMessage = "" |
194 | 198 |
|
195 | | - if workspaceApply.Status.LastAppliedTime != nil { |
| 199 | + if workspaceApply != nil && workspaceApply.Status.LastAppliedTime != nil { |
196 | 200 | controlPlane.Status.WorkspaceTemplateStatus.LastAppliedRevision = workspaceApply.Status.LastAppliedTime.String() |
197 | 201 | } |
198 | 202 |
|
|
0 commit comments