-
Notifications
You must be signed in to change notification settings - Fork 108
✨ Implement Init plugin subcommand #334
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
Conversation
/hold |
ee6eb9f
to
c596524
Compare
8a9044b
to
5839bb1
Compare
/test pull-cluster-api-operator-e2e-main |
2b4e873
to
706e246
Compare
/hold cancel |
16699b6
to
306b24e
Compare
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.
Looks good, some nits, suggestions
cmd/plugin/cmd/init.go
Outdated
bootstrapProviders []string | ||
controlPlaneProviders []string | ||
infrastructureProviders []string | ||
// ipamProviders []string |
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 be uncommented now.
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.
yes, I rebased this PR on master.
cmd/plugin/cmd/init.go
Outdated
|
||
func init() { | ||
initCmd.PersistentFlags().StringVar(&initOpts.kubeconfig, "kubeconfig", "", | ||
initCmd.PersistentFlags().StringVar(&initOpts.kubeconfig, "kubeconfig", filepath.Join(os.Getenv("HOME"), ".kube", "config"), |
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 that by default empty kubeconfig should already resolve to ~/.kube/config
, am I wrong?
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 checked the utils method, it is not entirely correct, as it does not pick $KUBECONFIG variable, think it is supposed to.
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.
Thank you for noticing this. Now we check KUBECONFIG env var as well.
cmd/plugin/cmd/init.go
Outdated
"Add-on providers and versions (e.g. helm:v0.1.0) to add to the management cluster.") | ||
initCmd.Flags().StringVarP(&initOpts.targetNamespace, "target-namespace", "n", "capi-operator-system", | ||
"The target namespace where the operator should be deployed. If unspecified, the 'capi-operator-system' namespace is used.") | ||
initCmd.Flags().StringVar(&initOpts.configSecretName, "config-secret-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.
Does it make sense to change configSecretName and configSeretNamespace to be a single flag for namespace/name, deserializing into reference, as it is in Provider spec? To be consistent with current api version.
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.
converted these two options into 1: --config-secret, that has <config_secret_name>:<config_secret_namespace> format
cmd/plugin/cmd/init.go
Outdated
"The config secret name to be used for the management cluster.") | ||
initCmd.Flags().StringVar(&initOpts.configSecretNamespace, "config-secret-namespace", "capi-operator-system", | ||
"The config secret namespace to be used for the management cluster.") | ||
initCmd.Flags().BoolVar(&initOpts.waitProviders, "wait-providers", false, |
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.
It seems to me that waiting by default is a better choose for a CLI tool, WDYT?
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.
done
cmd/plugin/cmd/init.go
Outdated
return nil | ||
} | ||
|
||
func newGenericProvider(providerType clusterctlv1.ProviderType) operatorv1.GenericProvider { |
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 have a similar (but opposite of that) method in utils. Does it make sense to move it there? Also maybe we can leverage GetType
on the provider wrapper to only store a list of providers
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.
Moved this method to utils.go
|
||
for _, genericProvider := range tt.wantedProviders { | ||
g.Eventually(func() (bool, error) { | ||
provider, err := getGenericProvider(ctx, env, string(util.ClusterctlProviderType(genericProvider)), genericProvider.GetName(), genericProvider.GetNamespace()) |
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.
BTW, you can define a custom interface deriving from client.Object and GenericProvider to get rid of the method and reduce it to a single client.Get
:
type GeneriProviderObject {
client.Object
genericprovider.GenericProvider
}
…
if err := client.Get(ctx, types.NamespacedName{Name: genericProvider.GetName(), Namespace: genericProvider.GetNamespace()}, provider); err != nil {
return nil, 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.
It says cannot use provider (variable of type GeneriProviderObject) as client.Object value in argument to env.Get: generiProviderObject does not implement client.Object (ambiguous selector generiProviderObject.DeepCopyObject)
. Maybe we can keep it for now?
755e726
to
b9b1bb7
Compare
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.
/approve
One nit, otherwise looks good
} | ||
|
||
// if the url is a GitHub repository | ||
if rURL.Host == githubDomain { |
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 these constants can be removed now
httpsScheme = "https"
githubDomain = "github.com"
gitlabHostPrefix = "gitlab."
gitlabPackagesAPIPrefix = "/api/v4/projects/"
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.
done!
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Danil-Grigorev The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
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.
/lgtm
LGTM label has been added. Git tree hash: 325afaf4b34156d2df72350397933c59bdc6fd94
|
What this PR does / why we need it:
This PR adds Init subcommand to the operator plugin.
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #