Skip to content

Commit b32bf5d

Browse files
author
Jeff McCormick
authored
Scorecard finalizer fix (#2597)
* remove hardcoded wait time in scorecard cleanup, instead using the initTimeout configuration setting * make linter happy by shortening a line * update changelog, update scorecard docs, replace hard coded timeout value with config init-timeout value
1 parent afc9c90 commit b32bf5d

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- The prepare/converge/verify tasks now make use of the new `k8s` `wait` option to simplify the deployment logic.
2222
- Operator user setup and entrypoint scripts no longer insert dynamic runtime user entries into `/etc/passwd`. To use dynamic runtime users, use a container runtime that supports it (e.g. CRI-O). ([#2469](https://github.com/operator-framework/operator-sdk/pull/2469))
2323
- Changed the scorecard basic test, `Writing into CRs has an effect`, to include the http.MethodPatch as part of its test criteria alongside http.MethodPut and http.MethodPost. ([#2509](https://github.com/operator-framework/operator-sdk/pull/2509))
24+
- Changed the scorecard to use the init-timeout configuration setting as a wait time when performing cleanup instead of a hard-coded time. ([#2597](https://github.com/operator-framework/operator-sdk/pull/2597))
2425

2526
### Deprecated
2627

doc/test-framework/scorecard.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ The `basic` and `olm` internal plugins have the same configuration fields:
125125
| `olm-deployed` | bool | indicates that the CSV and relevant CRD's have been deployed onto the cluster by the [Operator Lifecycle Manager (OLM)][olm] |
126126
| `kubeconfig` | string | path to kubeconfig. If both the global `kubeconfig` and this field are set, this field is used for the plugin |
127127
| `namespace` | string | namespace to run the plugins in. If not set, the default specified by the kubeconfig is used |
128-
| `init-timeout` | int | time in seconds until a timeout during initialization of the operator |
128+
| `init-timeout` | int | time in seconds until a timeout during initialization or cleanup of the operator |
129129
| `crds-dir` | string | path to directory containing CRDs that must be deployed to the cluster |
130130
| `namespaced-manifest` | string | manifest file with all resources that run within a namespace. By default, the scorecard will combine `service_account.yaml`, `role.yaml`, `role_binding.yaml`, and `operator.yaml` from the `deploy` directory into a temporary manifest to use as the namespaced manifest |
131131
| `global-manifest` | string | manifest containing required resources that run globally (not namespaced). By default, the scorecard will combine all CRDs in the `crds-dir` directory into a temporary manifest to use as the global manifest |

internal/scorecard/plugins/plugin_runner.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -392,35 +392,35 @@ func duplicateCRCheck(crs []string) error {
392392
return nil
393393
}
394394

395-
func runTests(csv *olmapiv1alpha1.ClusterServiceVersion, pluginType PluginType, config BasicAndOLMPluginConfig,
395+
func runTests(csv *olmapiv1alpha1.ClusterServiceVersion, pluginType PluginType, cfg BasicAndOLMPluginConfig,
396396
cr string, logFile io.Writer) ([]schelpers.TestResult, string, error) {
397397
testResults := make([]schelpers.TestResult, 0)
398398

399399
logReadWriter := &bytes.Buffer{}
400400
log.SetOutput(logReadWriter)
401401
log.Printf("Running for cr: %s", cr)
402402

403-
if !config.OLMDeployed {
404-
if err := createFromYAMLFile(config.Namespace, config.GlobalManifest, config.ProxyImage,
405-
config.ProxyPullPolicy); err != nil {
403+
if !cfg.OLMDeployed {
404+
if err := createFromYAMLFile(cfg.Namespace, cfg.GlobalManifest, cfg.ProxyImage,
405+
cfg.ProxyPullPolicy, cfg.InitTimeout); err != nil {
406406
return testResults, "", fmt.Errorf("failed to create global resources: %v", err)
407407
}
408-
if err := createFromYAMLFile(config.Namespace, config.NamespacedManifest, config.ProxyImage,
409-
config.ProxyPullPolicy); err != nil {
408+
if err := createFromYAMLFile(cfg.Namespace, cfg.NamespacedManifest, cfg.ProxyImage,
409+
cfg.ProxyPullPolicy, cfg.InitTimeout); err != nil {
410410
return testResults, "", fmt.Errorf("failed to create namespaced resources: %v", err)
411411
}
412412
}
413413

414-
if err := createFromYAMLFile(config.Namespace, cr, config.ProxyImage, config.ProxyPullPolicy); err != nil {
414+
if err := createFromYAMLFile(cfg.Namespace, cr, cfg.ProxyImage, cfg.ProxyPullPolicy, cfg.InitTimeout); err != nil {
415415
return testResults, "", fmt.Errorf("failed to create cr resource: %v", err)
416416
}
417417

418-
obj, err := yamlToUnstructured(config.Namespace, cr)
418+
obj, err := yamlToUnstructured(cfg.Namespace, cr)
419419
if err != nil {
420420
return testResults, "", fmt.Errorf("failed to decode custom resource manifest into object: %s", err)
421421
}
422422

423-
if err := waitUntilCRStatusExists(time.Second*time.Duration(config.InitTimeout), obj); err != nil {
423+
if err := waitUntilCRStatusExists(time.Second*time.Duration(cfg.InitTimeout), obj); err != nil {
424424
return testResults, "", fmt.Errorf("failed waiting to check if CR status exists: %v", err)
425425
}
426426

@@ -443,9 +443,9 @@ func runTests(csv *olmapiv1alpha1.ClusterServiceVersion, pluginType PluginType,
443443
Client: runtimeClient,
444444
CR: obj,
445445
CSV: csv,
446-
CRDsDir: config.CRDsDir,
446+
CRDsDir: cfg.CRDsDir,
447447
ProxyPod: proxyPodGlobal,
448-
Bundle: config.Bundle,
448+
Bundle: cfg.Bundle,
449449
}
450450

451451
tests = append(tests, NewBundleValidationTest(conf))
@@ -456,7 +456,7 @@ func runTests(csv *olmapiv1alpha1.ClusterServiceVersion, pluginType PluginType,
456456

457457
}
458458

459-
tests = applySelector(tests, config.Selector)
459+
tests = applySelector(tests, cfg.Selector)
460460

461461
for _, test := range tests {
462462
testResults = append(testResults, *test.Run(context.TODO()))

internal/scorecard/plugins/resource_handler.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func yamlToUnstructured(namespace, yamlPath string) (*unstructured.Unstructured,
8787

8888
// createFromYAMLFile will take a path to a YAML file and create the resource. If it finds a
8989
// deployment, it will add the scorecard proxy as a container in the deployments podspec.
90-
func createFromYAMLFile(namespace, yamlPath, proxyImage string, pullPolicy v1.PullPolicy) error {
90+
func createFromYAMLFile(namespace, yamlPath, proxyImage string, pullPolicy v1.PullPolicy, initTimeout int) error {
9191
yamlSpecs, err := ioutil.ReadFile(yamlPath)
9292
if err != nil {
9393
return fmt.Errorf("failed to read file %s: %v", yamlPath, err)
@@ -115,7 +115,7 @@ func createFromYAMLFile(namespace, yamlPath, proxyImage string, pullPolicy v1.Pu
115115
return fmt.Errorf("failed to convert object to deployment: %v", err)
116116
}
117117
deploymentName = dep.GetName()
118-
err = createKubeconfigSecret(namespace)
118+
err = createKubeconfigSecret(namespace, initTimeout)
119119
if err != nil {
120120
return fmt.Errorf("failed to create kubeconfig secret for scorecard-proxy: %v", err)
121121
}
@@ -148,7 +148,7 @@ func createFromYAMLFile(namespace, yamlPath, proxyImage string, pullPolicy v1.Pu
148148
return err
149149
}
150150
}
151-
addResourceCleanup(obj, types.NamespacedName{Namespace: obj.GetNamespace(), Name: obj.GetName()})
151+
addResourceCleanup(obj, types.NamespacedName{Namespace: obj.GetNamespace(), Name: obj.GetName()}, initTimeout)
152152
if obj.GetKind() == "Deployment" {
153153
proxyPodGlobal, err = getPodFromDeployment(deploymentName, namespace)
154154
if err != nil {
@@ -216,7 +216,7 @@ func getPodFromDeployment(depName, namespace string) (pod *v1.Pod, err error) {
216216

217217
// createKubeconfigSecret creates the secret that will be mounted in the operator's container and contains
218218
// the kubeconfig for communicating with the proxy
219-
func createKubeconfigSecret(namespace string) error {
219+
func createKubeconfigSecret(namespace string, initTimeout int) error {
220220
kubeconfigMap := make(map[string][]byte)
221221
kc, err := proxyConf.Create(metav1.OwnerReference{Name: "scorecard"}, "http://localhost:8889", namespace)
222222
if err != nil {
@@ -248,7 +248,7 @@ func createKubeconfigSecret(namespace string) error {
248248
return err
249249
}
250250
addResourceCleanup(kubeconfigSecret, types.NamespacedName{Namespace: kubeconfigSecret.GetNamespace(),
251-
Name: kubeconfigSecret.GetName()})
251+
Name: kubeconfigSecret.GetName()}, initTimeout)
252252
return nil
253253
}
254254

@@ -345,15 +345,15 @@ func cleanupScorecard() error {
345345
}
346346

347347
// addResourceCleanup adds a cleanup function for the specified runtime object
348-
func addResourceCleanup(obj runtime.Object, key types.NamespacedName) {
348+
func addResourceCleanup(obj runtime.Object, key types.NamespacedName, initTimeout int) {
349349
cleanupFns = append(cleanupFns, func() error {
350350
// make a copy of the object because the client changes it
351351
objCopy := obj.DeepCopyObject()
352352
err := runtimeClient.Delete(context.TODO(), obj)
353353
if err != nil && !apierrors.IsNotFound(err) {
354354
return err
355355
}
356-
err = wait.PollImmediate(time.Second*1, time.Second*10, func() (bool, error) {
356+
err = wait.PollImmediate(time.Second*1, time.Second*time.Duration(initTimeout), func() (bool, error) {
357357
err = runtimeClient.Get(context.TODO(), key, objCopy)
358358
if err != nil {
359359
if apierrors.IsNotFound(err) {

0 commit comments

Comments
 (0)