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 capi to supported providers #26

Merged
merged 14 commits into from
Dec 19, 2023
Merged

Add capi to supported providers #26

merged 14 commits into from
Dec 19, 2023

Conversation

ranatrk
Copy link
Contributor

@ranatrk ranatrk commented Dec 13, 2023

Issue weaveworks/weave-gitops-enterprise#3528

  • Add capi to providers
  • Add capi support to controller reconcile loop

@ranatrk ranatrk added the enhancement New feature or request label Dec 13, 2023
@ranatrk ranatrk marked this pull request as ready for review December 14, 2023 16:36
@ranatrk ranatrk requested a review from a team December 14, 2023 16:37
@@ -28,13 +28,17 @@ type AKS struct {
SubscriptionID string `json:"subscriptionID"`
}

// CAPI defines the desired state of CAPI, TBD
type CAPI struct {
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we let you filter by labels / namespace?

@@ -44,6 +48,8 @@ type AutomatedClusterDiscoverySpec struct {

AKS *AKS `json:"aks,omitempty"`

CAPI *CAPI `json:"capi,omitempty"`

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could document these?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this actually mean?

Also, maybe given that we don't use it, we don't actually need it?

@@ -52,6 +52,9 @@ spec:
required:
- subscriptionID
type: object
capi:
description: CAPI defines the desired state of CAPI, TBD
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right, or up-to-date?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bigkevmcd I removed the TBD, but for now CAPI struct is empty, I added it to be consistent and if we need to add something in the future to it.


logger.Info("creating secret", "name", secret.GetName())
if err := controllerutil.SetOwnerReference(gitopsCluster, secret, r.Scheme); err != nil {
return nil, fmt.Errorf("failed to set ownership on created Secret: %w", err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's logger.Error this?

secret.Data["value"] = value

return nil
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could simplify this to if _, err := ... ; err != nil { ...


var _ providers.Provider = (*CAPIProvider)(nil)

func NewCAPIProvider(client client.Client) *CAPIProvider {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exported...so, we should have a Doc comment.

ID: string(capiCluster.GetObjectMeta().GetUID()),
KubeConfig: nil,
})
// TODO: kubeconfig is in a secret in the namespace of the cluster called clustername-kubeconfig
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove this comment now?

return clusters, nil
}

func (p *CAPIProvider) ClusterID(ctx context.Context, kubeClient client.Reader) (string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about a comment in this to explain that the ProviderCluster has an ID and we can't find a Cluster ID in the cluster so these won't match so that later folks can understand this 😄


for _, capiCluster := range capiClusters.Items {
clusters = append(clusters, &providers.ProviderCluster{
Name: capiCluster.Name,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func (p *CAPIProvider) ListClusters(ctx context.Context) ([]*providers.ProviderCluster, error) {
kubeClient := p.Kubeclient
capiClusters := &capiclusterv1.ClusterList{}
err := kubeClient.List(ctx, capiClusters, &client.ListOptions{})
Copy link
Collaborator

@bigkevmcd bigkevmcd Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be restricted to the NS for the AutomatedClusterDiscovery.

ACD uses Ownership to handle removal and we can't have cross-NS ownership.

Update capi provider to take namespace from acd and list clusters in that namespace
@ranatrk ranatrk requested a review from bigkevmcd December 18, 2023 20:06
@@ -72,6 +75,9 @@ spec:
name:
description: Name is the name of the cluster
type: string
namespace:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can come out.

// AutomatedClusterDiscoverySpec defines the desired state of AutomatedClusterDiscovery
type AutomatedClusterDiscoverySpec struct {
// Name is the name of the cluster
Name string `json:"name,omitempty"`

// Namespace of the cluster
Namespace string `json:"namespace,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can rm this

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and use acd.metadata.namespace instead

AKS *AKS `json:"aks,omitempty"`

// CAPI defines the desired state of CAPI
CAPI *CAPI `json:"capi,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets rm this too -- @bigkevmcd

@ranatrk ranatrk requested review from foot and bigkevmcd December 19, 2023 11:50
Copy link
Collaborator

@bigkevmcd bigkevmcd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are couple of small things that can be tidied up if you want before merging, but otherwise 👍🏻

We will need to provide a way to exclude clusters in a separate branch.

_, err = controllerutil.CreateOrPatch(ctx, r.Client, secret, func() error {
if value, err := clientcmd.Write(*cluster.KubeConfig); err != nil {
return err
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need the else here, as you will have returned in the other branch.

https://go.dev/wiki/CodeReviewComments#indent-error-flow

@ranatrk ranatrk merged commit dfb060a into main Dec 19, 2023
3 checks passed
@ranatrk ranatrk deleted the capi branch December 19, 2023 15:40
@ranatrk ranatrk restored the capi branch December 19, 2023 15:45
@ranatrk ranatrk deleted the capi branch December 19, 2023 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants