-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
Add capi crd regenerate cluster discovery crds to include capi
Add condition to check for cluster kubeconfig before creating the secret
… existing clusters in reconcile loop
@@ -28,13 +28,17 @@ type AKS struct { | |||
SubscriptionID string `json:"subscriptionID"` | |||
} | |||
|
|||
// CAPI defines the desired state of CAPI, TBD | |||
type CAPI struct { | |||
} |
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.
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"` | |||
|
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.
We could document these?
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.
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 |
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.
This doesn't look right, or up-to-date?
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.
@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) |
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.
Let's logger.Error
this?
secret.Data["value"] = value | ||
|
||
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.
You could simplify this to if _, err := ... ; err != nil { ...
pkg/providers/capi/capi.go
Outdated
|
||
var _ providers.Provider = (*CAPIProvider)(nil) | ||
|
||
func NewCAPIProvider(client client.Client) *CAPIProvider { |
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.
Exported...so, we should have a Doc comment.
pkg/providers/capi/capi.go
Outdated
ID: string(capiCluster.GetObjectMeta().GetUID()), | ||
KubeConfig: nil, | ||
}) | ||
// TODO: kubeconfig is in a secret in the namespace of the cluster called clustername-kubeconfig |
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.
I think we can remove this comment now?
return clusters, nil | ||
} | ||
|
||
func (p *CAPIProvider) ClusterID(ctx context.Context, kubeClient client.Reader) (string, error) { |
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.
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, |
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.
Should we return the labels from the CAPI Cluster for https://github.com/weaveworks/cluster-reflector-controller/blob/main/pkg/providers/provider.go#L39?
pkg/providers/capi/capi.go
Outdated
func (p *CAPIProvider) ListClusters(ctx context.Context) ([]*providers.ProviderCluster, error) { | ||
kubeClient := p.Kubeclient | ||
capiClusters := &capiclusterv1.ClusterList{} | ||
err := kubeClient.List(ctx, capiClusters, &client.ListOptions{}) |
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.
This should be restricted to the NS for the AutomatedClusterDiscovery.
ACD uses Ownership to handle removal and we can't have cross-NS ownership.
Add doc comments
Add docstring comments
Update capi provider to take namespace from acd and list clusters in that namespace
@@ -72,6 +75,9 @@ spec: | |||
name: | |||
description: Name is the name of the cluster | |||
type: string | |||
namespace: |
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.
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"` |
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 rm this
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.
and use acd.metadata.namespace instead
AKS *AKS `json:"aks,omitempty"` | ||
|
||
// CAPI defines the desired state of CAPI | ||
CAPI *CAPI `json:"capi,omitempty"` |
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.
Lets rm this too -- @bigkevmcd
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.
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 { |
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.
Don't need the else
here, as you will have returned in the other branch.
Co-authored-by: Kevin McDermott <[email protected]>
…ion when creating the secret
Issue weaveworks/weave-gitops-enterprise#3528