Skip to content

fix empty client in action config #226

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

Merged
merged 1 commit into from
Mar 13, 2025

Conversation

ankitathomas
Copy link
Contributor

@ankitathomas ankitathomas commented Mar 7, 2025

Fixing the panic because of the empty client in action config

$ kubectl operator olmv1 create catalog operatorhub quay.io/operatorhubio/catalog:latest
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x184c59c]

goroutine 1 [running]:
github.com/operator-framework/kubectl-operator/internal/pkg/v1/action.(*CatalogCreate).Run(0xc0001126c0, {0x1f6f468, 0xc0002b19d0})
	kubectl-operator/internal/pkg/v1/action/catalog_create.go:41 +0x1dc
github.com/operator-framework/kubectl-operator/internal/cmd/internal/olmv1.NewCatalogCreateCmd.func1(0xc000374c08?, {0xc00030ed60?, 0x4?, 0x1c59745?})
	kubectl-operator/internal/cmd/internal/olmv1/catalog_create.go:28 +0xaf
github.com/spf13/cobra.(*Command).execute(0xc000374c08, {0xc00030ed20, 0x2, 0x2})
	/home/lmohanty/go/pkg/mod/github.com/spf13/[email protected]/command.go:989 +0xa91
github.com/spf13/cobra.(*Command).ExecuteC(0xc00040e908)
	/home/lmohanty/go/pkg/mod/github.com/spf13/[email protected]/command.go:1117 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
	/home/lmohanty/go/pkg/mod/github.com/spf13/[email protected]/command.go:1041
github.com/operator-framework/kubectl-operator/internal/cmd.Execute()
	kubectl-operator/internal/cmd/root.go:14 +0x18
main.main()
	kubectl-operator/main.go:8 +0xf

Also adding some nil value checks for printing clusterCatalogs and clusterExtensions.

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 7, 2025
@openshift-ci openshift-ci bot requested review from jmrodri and joelanford March 7, 2025 19:32
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 7, 2025
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 8, 2025
@ankitathomas ankitathomas changed the title WIP: fix empty client in action config fix empty client in action config Mar 8, 2025
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 8, 2025
@ankitathomas
Copy link
Contributor Author

/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 8, 2025
@ankitathomas
Copy link
Contributor Author

hold till #225 merges

@ankitathomas ankitathomas force-pushed the nilptr-fix branch 3 times, most recently from 9f031a0 to 36c08db Compare March 8, 2025 00:26
@azych
Copy link
Contributor

azych commented Mar 10, 2025

@ankitathomas could you explain what the issue with the client is and how it can be reproduced?

Can cfg *action.Configuration somehow be nil when it's passed to NewCatalogCreateCmd, which would make attempting to pass .Client panic?

If not and if the Client can be nil, how do the changes in this PR fix the situation?
We're still not validating if the i.config.Client is nil before calling it, just like we didin't validate if i.client was nil before.

Can the cfg.Client be modified/replaced during cmd.Execute?

@ankitathomas
Copy link
Contributor Author

ankitathomas commented Mar 10, 2025

Can cfg *action.Configuration somehow be nil when it's passed to NewCatalogCreateCmd, which would make attempting to pass .Client panic?

what happened was that when v1action.NewCatalogCreate(cfg.Client) gets called within NewCatalogCreateCmd, we pass it into CatalogCreate{}.

	return &CatalogCreate{
		client: client,
		Logf:   func(string, ...interface{}) {},
	}

This would be ok if the actionConfig client is initialized beforehand, but that happens in the PersistentPreRunE for the root command and until that runs, actionConfig.client is nil.

Since command registration happens before PersistentPreRunE gets called, we end up passing the value of cfg.Client (nil) rather than the pointer to cfg.Client, setting CatalogCreate.client = cfg.Client or CatalogCreate.client = nil.

A workaround was to pass the entire actionConfig so by the time we end up using the client in CatalogCreate.Run, PersistentPreRunE gets called and CatalogCreate.cfg.client is initialized.

Copy link
Member

@LalatenduMohanty LalatenduMohanty left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Mar 10, 2025
@LalatenduMohanty
Copy link
Member

hold till #225 merges

@ankitathomas Can you please clarify why we need to wait for #225?

@LalatenduMohanty
Copy link
Member

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 12, 2025
@LalatenduMohanty
Copy link
Member

@ankitathomas Looks like lint test is failing with below errors

Run make lint
(re)installing /home/runner/go/bin/golangci-lint-v1.63.4
/home/runner/go/bin/golangci-lint-v1.63.4 --timeout 3m run
internal/pkg/v1/action/catalog_create_test.go:43:24   errcheck  Error return value of `mockClient.Initialize` is not checked
internal/pkg/v1/action/catalog_create_test.go:125:24  errcheck  Error return value of `mockClient.Client.Get` is not checked
internal/pkg/v1/action/catalog_create.go:13:6         unused    type `createClient` is unused
internal/pkg/v1/action/interfaces.go:9:6              unused    type `creator` is unused
internal/pkg/v1/action/catalog_create.go:7:1          gci       File is not properly formatted
internal/pkg/v1/action/catalog_create.go:10:1         gci       File is not properly formatted
internal/pkg/v1/action/action_suite_test.go:10:1      gci       File is not properly formatted
make: *** [Makefile:61: lint] Error 1
Error: Process completed with exit code 2.

@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Mar 12, 2025
Copy link
Member

@LalatenduMohanty LalatenduMohanty left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Mar 13, 2025
@LalatenduMohanty
Copy link
Member

/lgtm cancel

@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Mar 13, 2025
@LalatenduMohanty
Copy link
Member

LalatenduMohanty commented Mar 13, 2025

@ankitathomas Looks like the code for fixing the empty client in action config is missing now. I am wondering how the tests are passing now.

I was trying out a different solution.

I tried moving the *actionConfig.Load() out of PersistentPrerun to the root command declaration - that works to initialize the actionConfig client before it gets passed to the catalog create client, but looking further into it we may run into issues with how we're loading the config if we don't parse the subcommand flags before loading the actionConfig client - mostly because it makes use of config overrides from specific flags (auth, namespace, context etc) that we may support in future.

I didn't want this to be a potential bug in future so I switched the implementation back, it's now what it used to be.

Also adding some nil value checks for printing clusterCatalogs and clusterExtensions.

Signed-off-by: Ankita Thomas <[email protected]>
Copy link
Member

@LalatenduMohanty LalatenduMohanty left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Mar 13, 2025
@LalatenduMohanty LalatenduMohanty added this pull request to the merge queue Mar 13, 2025
Merged via the queue into operator-framework:main with commit 4ddebe0 Mar 13, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants