-
Notifications
You must be signed in to change notification settings - Fork 22
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
Initialize the cluster client cache from the kubeconfig in secrets #412
Initialize the cluster client cache from the kubeconfig in secrets #412
Conversation
and read the connection configuration from the kubeconfig stored in the secret.
…itialized and don't clear out other fields than the conditions in the healtchcheck from the status.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #412 +/- ##
==========================================
+ Coverage 78.54% 78.57% +0.03%
==========================================
Files 49 49
Lines 2023 2054 +31
==========================================
+ Hits 1589 1614 +25
- Misses 376 379 +3
- Partials 58 61 +3
|
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 probably know why you kept the support for the legacy config. There could be a problem as soon as you would merge a support for kubeconfig only. The reason is that we load the ToolchainCluster CRs and their configs inside main.go before we start the controllers. This means that the ToolchainCluster controller that does the migration wouldn't be started yet and it wouldn't be able to migrate the legacy fields in the secret to the kubeconfig one.
Anyway, at some point we need to make the switch, so I decided to not keep postponing this action and I updated the add-cluster.sh script so it populates the kubeconfig right away:
codeready-toolchain/toolchain-cicd#117
This means that we are ready to drop the migration logic from the ToolchainCluster controller and support kubeconfig only.
…n-creds-secret # Conflicts: # controllers/toolchaincluster/healthchecker.go # controllers/toolchaincluster/toolchaincluster_controller.go
…creating the client for the remote clusters.
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, but since the "kubeconfig` field is the preferred one now, could you please update the unit tests so they load the ToolchainCluster clients from kubeconfig instead of from the legacy fields?
I guess that it should be enough to update this helper function:
toolchain-common/pkg/test/cluster.go
Lines 19 to 34 in 14c41a9
func NewToolchainClusterWithEndpoint(name, tcNs, secName, apiEndpoint string, status toolchainv1alpha1.ToolchainClusterStatus, labels map[string]string) (*toolchainv1alpha1.ToolchainCluster, *corev1.Secret) { | |
gock.New(apiEndpoint). | |
Get("api"). | |
Persist(). | |
Reply(200). | |
BodyString("{}") | |
secret := &corev1.Secret{ | |
ObjectMeta: v1.ObjectMeta{ | |
Name: secName, | |
Namespace: tcNs, | |
}, | |
Type: corev1.SecretTypeOpaque, | |
Data: map[string][]byte{ | |
"token": []byte("mycooltoken"), | |
}, | |
} |
For this to make most sense, I guess we should also not use any legacy fields in the code as well as in the tests. When I do that, I get quite a substantial diff (on top of the changes in this PR). The main reason for that diff is that the function you mention now needs to contain more parameters (namely operator namespace and insecureTls) because those are now part of the kubeconfig and cannot be easily set as before when they were just part of the returned toolchain cluster spec.
I think it makes more sense to merge this PR as is and move the test updates and removal of the migration logic to a new PR.. 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.
Looks good !
I have one minor comment only.
}) | ||
|
||
t.Run("uses kubeconfig in precedence over legacy fields", func(t *testing.T) { | ||
tc := newFormTc() |
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.
do we need to add a test case that uses the legacyTc
?
basically:
tc := legacyTc()
// Combine the kubeconfig and the token in the same secret.
// We should see auth from the kubeconfig used...
secret := kubeconfigSecret(t)
secret.Data["token"] = []byte("not-the-token-we-want")
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 essentially checks that if we detect a kubeconfig
data field in the secret then we use that instead of the data in the ToolchainCluster
and the token in the secret.
So as soon as we see the data coming from the kubeconfig, we know that happened.
Now, you have a very good idea for a "defensive test" that would make sure any future changes wouldn't change that behavior. But we plan to completely remove the loading from the legacy fields in the upcoming PRs so I think we can afford to not have that and instead just make sure we use the new over the old.
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.
Right, I was asking since as soon as you push this PR to prod, the tc will still have the legacy
format, and later will have the new one. But I guess it's not a concern since the only thing that matters is the loading mechanism and not the tc format.
Quality Gate passedIssues Measures |
The e2e tests for this PR embedded in the host-operator are passing, so I'm merging this. See https://prow.ci.openshift.org/view/gs/test-platform-results/pr-logs/pull/codeready-toolchain_toolchain-e2e/1012/pull-ci-codeready-toolchain-toolchain-e2e-master-e2e/1828041777043476480 |
This changes the cluster cache to initialize the connections to the clusters from the kubeconfig stored in the toolchain cluster secret.
The information from the cluster cache is also used to populate the new informational fields in the ToolchainCluster status.
Related PRs: