-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: CRS generated CA Deployment has extra quotes (#867)
**What problem does this PR solve?**: Fixes an issue with CRS genertated CA Deployment not working because of extra quotes. ``` I0815 20:12:58.376871 1 reflector.go:332] Listing and watching cluster.x-k8s.io/v1beta1, Resource=machines from k8s.io/client-go/dynamic/dynamicinformer/informer.go:108 W0815 20:12:58.379140 1 reflector.go:547] k8s.io/client-go/dynamic/dynamicinformer/informer.go:108: failed to list cluster.x-k8s.io/v1beta1, Resource=machines: machines.cluster.x-k8s.io is forbidden: User "system:serviceaccount:default:cluster-autoscaler-0191579a-2104-7ace-a5a2-ceae4590d7fe" cannot list resource "machines" in API group "cluster.x-k8s.io" in the namespace "'default'" E0815 20:12:58.379170 1 reflector.go:150] k8s.io/client-go/dynamic/dynamicinformer/informer.go:108: Failed to watch cluster.x-k8s.io/v1beta1, Resource=machines: failed to list cluster.x-k8s.io/v1beta1, Resource=machines: machines.cluster.x-k8s.io is forbidden: User "system:serviceaccount:default:cluster-autoscaler-0191579a-2104-7ace-a5a2-ceae4590d7fe" cannot list resource "machines" in API group "cluster.x-k8s.io" in the namespace "'default'" ``` The extra quotes are only an issue in `--node-group-auto-discovery=`, but the [same script](https://github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/blob/f632224257cb159b04abc2c6c6eb6874c503bb1c/hack/addons/update-cluster-autoscaler.sh#L28) replaces all occurrences. It should be safe to drop the single quotes everywhere though because the name and namespace will be strings and won't be interpreted as numbers by yaml. **Which issue(s) this PR fixes**: Fixes # **How Has This Been Tested?**: <!-- Please describe the tests that you ran to verify your changes. Provide output from the tests and any manual steps needed to replicate the tests. --> **Special notes for your reviewer**: <!-- Use this to provide any additional information to the reviewers. This may include: - Best way to review the PR. - Where the author wants the most review attention on. - etc. --> ~I think we can improve the e2e tests by checking that all Deployments are Ready on the self-managed clusters, but I did not do that as part of this PR.~ The tests already do that https://github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/blob/f632224257cb159b04abc2c6c6eb6874c503bb1c/test/e2e/clusterautoscaler_helpers.go#L115 Instead we can also wait for the status ConfigMap to be `Running` This is what the data will contain for a working Deployment: ``` data: status: |+ time: 2024-05-22 19:33:34.074058252 +0000 UTC autoscalerStatus: Running ``` And for non working: ``` data: status: |+ time: 2024-08-15 20:07:37.204175116 +0000 UTC autoscalerStatus: Initializing ```
- Loading branch information
Showing
4 changed files
with
114 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
//go:build e2e | ||
|
||
// Copyright 2024 Nutanix. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package e2e | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
"time" | ||
|
||
. "github.com/onsi/gomega" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/klog/v2" | ||
capie2e "sigs.k8s.io/cluster-api/test/e2e" | ||
"sigs.k8s.io/cluster-api/test/framework" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
type WaitForConfigMapDataInput struct { | ||
Getter framework.Getter | ||
ConfigMap *corev1.ConfigMap | ||
DataValidator func(data map[string]string) bool | ||
} | ||
|
||
func WaitForConfigMapData( | ||
ctx context.Context, | ||
input WaitForConfigMapDataInput, | ||
intervals ...interface{}, | ||
) { | ||
start := time.Now() | ||
key := client.ObjectKeyFromObject(input.ConfigMap) | ||
capie2e.Byf("waiting for ConfigMap %s to have expected data", key) | ||
Log("starting to wait for ConfigMap to have expected data") | ||
Eventually(func() bool { | ||
if err := input.Getter.Get(ctx, key, input.ConfigMap); err == nil { | ||
return input.DataValidator(input.ConfigMap.Data) | ||
} | ||
return false | ||
}, intervals...).Should(BeTrue(), func() string { | ||
return DescribeIncorrectConfigMapData(input, input.ConfigMap) | ||
}) | ||
Logf("ConfigMap %s has expected data, took %v", key, time.Since(start)) | ||
} | ||
|
||
// DescribeIncorrectConfigMapData returns detailed output to help debug a ConfigMap data validation failure in e2e. | ||
func DescribeIncorrectConfigMapData( | ||
input WaitForConfigMapDataInput, | ||
configMap *corev1.ConfigMap, | ||
) string { | ||
b := strings.Builder{} | ||
b.WriteString(fmt.Sprintf("ConfigMap %s failed to get expected data:\n", | ||
klog.KObj(input.ConfigMap))) | ||
if configMap == nil { | ||
b.WriteString("\nConfigMap: nil\n") | ||
} else { | ||
b.WriteString(fmt.Sprintf("\nConfigMap:\n%s\n", framework.PrettyPrint(configMap))) | ||
} | ||
return b.String() | ||
} |