-
Notifications
You must be signed in to change notification settings - Fork 35
fix: skip access provider population in cluster profiles if no endpoint/CA data exists #849
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ import ( | |
| "k8s.io/apimachinery/pkg/api/meta" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| clientcmdv1 "k8s.io/client-go/tools/clientcmd/api/v1" | ||
| "k8s.io/client-go/util/workqueue" | ||
| "k8s.io/klog/v2" | ||
| clusterinventory "sigs.k8s.io/cluster-inventory-api/apis/v1alpha1" | ||
|
|
@@ -180,8 +181,8 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu | |
| return ctrl.Result{}, nil | ||
| } | ||
|
|
||
| // fillInClusterStatus fills in the ClusterProfile status fields from the MemberCluster status. | ||
| // Currently, it only fills in the Kubernetes version field. | ||
| // fillInClusterStatus fills in the ClusterProfile status fields from the MemberCluster status, | ||
| // including the Kubernetes version and, when available, the cluster access provider. | ||
| func (r *Reconciler) fillInClusterStatus(mc *clusterv1beta1.MemberCluster, cp *clusterinventory.ClusterProfile) { | ||
| clusterPropertyCondition := meta.FindStatusCondition(mc.Status.Conditions, string(clusterv1beta1.ConditionTypeClusterPropertyCollectionSucceeded)) | ||
| if !condition.IsConditionStatusTrue(clusterPropertyCondition, mc.Generation) { | ||
|
|
@@ -196,27 +197,26 @@ func (r *Reconciler) fillInClusterStatus(mc *clusterv1beta1.MemberCluster, cp *c | |
| Kubernetes: k8sversion.Value, | ||
| } | ||
| } | ||
| // Add the class access provider, we only have one so far | ||
| cp.Status.AccessProviders = []clusterinventory.AccessProvider{ | ||
| { | ||
| Name: controller.ClusterManagerName, | ||
| }, | ||
| } | ||
| // TODO throw and unexpected error if clusterEntryPoint is not found | ||
| // We don't have a way to get it yet | ||
| clusterEntry, exists := mc.Status.Properties[propertyprovider.ClusterEntryPointProperty] | ||
| if exists { | ||
| klog.V(3).InfoS("Get Kubernetes cluster entry point from member cluster status", "clusterEntryPoint", clusterEntry.Value, "clusterProfile", klog.KObj(cp)) | ||
| cp.Status.AccessProviders[0].Cluster.Server = clusterEntry.Value | ||
| } | ||
| // Get the CA Data | ||
| certificateAuthorityData, exists := mc.Status.Properties[propertyprovider.ClusterCertificateAuthorityProperty] | ||
| if exists { | ||
| klog.V(3).InfoS("Get Kubernetes cluster certificate authority data from member cluster status", "clusterProfile", klog.KObj(cp)) | ||
| cp.Status.AccessProviders[0].Cluster.CertificateAuthorityData = []byte(certificateAuthorityData.Value) | ||
|
|
||
| // Add cluster access provider, if and only if a cluster entry point and the CA data exist as part of the | ||
| // cluster properties. | ||
| clusterEntrypoint, entryPtExists := mc.Status.Properties[propertyprovider.ClusterEntryPointProperty] | ||
| caData, caDataExists := mc.Status.Properties[propertyprovider.ClusterCertificateAuthorityProperty] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question for this one too.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Yetkin! mc.Status is a struct (empty if not written yet, but never nil), and nil maps (.status.properties) can be read as empty maps with no panic errors, so we should be good. |
||
| if entryPtExists && caDataExists && len(clusterEntrypoint.Value) > 0 && len(caData.Value) > 0 { | ||
|
sjwaight marked this conversation as resolved.
|
||
| cp.Status.AccessProviders = []clusterinventory.AccessProvider{ | ||
| { | ||
| Name: controller.ClusterManagerName, | ||
| Cluster: clientcmdv1.Cluster{ | ||
| Server: clusterEntrypoint.Value, | ||
| CertificateAuthorityData: []byte(caData.Value), | ||
| }, | ||
| }, | ||
| } | ||
| } else { | ||
| // throw an alert | ||
| _ = controller.NewUnexpectedBehaviorError(fmt.Errorf("cluster certificate authority data not found in member cluster %s status", mc.Name)) | ||
| cp.Status.AccessProviders = nil | ||
| klog.V(2).InfoS("Cluster entry point and/or CA data is missing or empty; reset cluster access provider to cluster profile status", | ||
| "memberCluster", klog.KObj(mc), "clusterProfile", klog.KObj(cp), | ||
| "clusterEntryPointExists", entryPtExists, "caDataExists", caDataExists) | ||
| } | ||
|
michaelawyu marked this conversation as resolved.
|
||
| } | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,6 @@ import ( | |
| clusterv1beta1 "github.com/kubefleet-dev/kubefleet/apis/cluster/v1beta1" | ||
| placementv1beta1 "github.com/kubefleet-dev/kubefleet/apis/placement/v1beta1" | ||
| "github.com/kubefleet-dev/kubefleet/pkg/utils" | ||
| "github.com/kubefleet-dev/kubefleet/pkg/utils/controller" | ||
| ) | ||
|
|
||
| const ( | ||
|
|
@@ -462,14 +461,10 @@ var _ = Describe("Test member cluster join and leave with clusterProfile", Label | |
| if cp.Status.Version.Kubernetes == "" { | ||
| return fmt.Errorf("cluster profile %s Kubernetes version should not be empty", cp.Name) | ||
| } | ||
| if len(cp.Status.AccessProviders) != 1 { | ||
| return fmt.Errorf("cluster profile %s has no access providers %+v", cp.Name, cp.Status.AccessProviders) | ||
| } | ||
| if cp.Status.AccessProviders[0].Name != controller.ClusterManagerName { | ||
| return fmt.Errorf("cluster profile %s access provider name %s doesn't match expected %s", cp.Name, cp.Status.AccessProviders[0].Name, controller.ClusterManagerName) | ||
| } | ||
| if len(cp.Status.AccessProviders[0].Cluster.CertificateAuthorityData) == 0 { | ||
| return fmt.Errorf("cluster profile %s access provider certificate authority data should not be empty", allMemberClusterNames[idx]) | ||
| if len(cp.Status.AccessProviders) != 0 { | ||
| // Note: at this moment the Azure property provider does not expose cluster FQDNs, and | ||
| // as a result no access provider will be populated. | ||
|
Comment on lines
+465
to
+466
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If case checks if AccessProviders array has items, right? The comment sounds a bit off to me. Am I missing something?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Yetkin! Yeah, about this one: the access provider, as the issuer contributor mentioned, needs to have a valid cluster entrypoint (API server URL) set. However, at this moment, even though we do have the cluster entrypoint property listed, it is never written/used; as a result, all the cluster profiles we produce have invalid access providers with no entrypoints. With this PR we have added the check as requested, i.e., if there is no cluster entrypoint, we do not populate access providers; until we add support for the cluster entrypoint property, the expected behavior onwards is that all the cluster profiles hub agent produces will have no access providers, hence the updated check. |
||
| return fmt.Errorf("cluster profile %s has access providers %+v", cp.Name, cp.Status.AccessProviders) | ||
| } | ||
| } | ||
| return nil | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can
mc.Status.Properties[propertyprovider.ClusterEntryPointProperty]ever throw nil pointer exception?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Yetkin!
mc.Statusis a struct (empty if not written yet, but never nil), and nil maps (.status.properties) can be read as empty maps with no panic errors, so we should be good.