Skip to content

Conversation

Fedosin
Copy link
Contributor

@Fedosin Fedosin commented Nov 22, 2023

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 #

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Nov 22, 2023
@Fedosin
Copy link
Contributor Author

Fedosin commented Nov 22, 2023

/hold

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 22, 2023
@Fedosin Fedosin force-pushed the plugin_init branch 3 times, most recently from ee6eb9f to c596524 Compare November 24, 2023 16:04
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 24, 2023
@Fedosin Fedosin force-pushed the plugin_init branch 2 times, most recently from 8a9044b to 5839bb1 Compare November 24, 2023 16:16
@Fedosin
Copy link
Contributor Author

Fedosin commented Nov 25, 2023

/test pull-cluster-api-operator-e2e-main

@Fedosin Fedosin force-pushed the plugin_init branch 5 times, most recently from 2b4e873 to 706e246 Compare November 30, 2023 11:40
@Fedosin
Copy link
Contributor Author

Fedosin commented Nov 30, 2023

/hold cancel

@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Nov 30, 2023
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 5, 2023
@Fedosin Fedosin force-pushed the plugin_init branch 2 times, most recently from 16699b6 to 306b24e Compare December 5, 2023 15:10
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 13, 2023
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 18, 2023
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 11, 2024
Copy link
Member

@Danil-Grigorev Danil-Grigorev left a 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

bootstrapProviders []string
controlPlaneProviders []string
infrastructureProviders []string
// ipamProviders []string
Copy link
Member

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.

Copy link
Contributor Author

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.


func init() {
initCmd.PersistentFlags().StringVar(&initOpts.kubeconfig, "kubeconfig", "",
initCmd.PersistentFlags().StringVar(&initOpts.kubeconfig, "kubeconfig", filepath.Join(os.Getenv("HOME"), ".kube", "config"),
Copy link
Member

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

"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", "",
Copy link
Member

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.

Copy link
Contributor Author

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

"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,
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return nil
}

func newGenericProvider(providerType clusterctlv1.ProviderType) operatorv1.GenericProvider {
Copy link
Member

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

Copy link
Contributor Author

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())
Copy link
Member

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
}

Copy link
Contributor Author

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?

@Fedosin Fedosin force-pushed the plugin_init branch 2 times, most recently from 755e726 to b9b1bb7 Compare January 22, 2024 15:30
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 23, 2024
Copy link
Member

@Danil-Grigorev Danil-Grigorev left a 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 {
Copy link
Member

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/"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 23, 2024
Copy link
Contributor

@alexander-demicev alexander-demicev left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 24, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 325afaf4b34156d2df72350397933c59bdc6fd94

@k8s-ci-robot k8s-ci-robot merged commit e3f4480 into kubernetes-sigs:main Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants