Skip to content
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

Scorecard finalizer fix #2597

Merged
merged 3 commits into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions internal/scorecard/plugins/plugin_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,35 +392,35 @@ func duplicateCRCheck(crs []string) error {
return nil
}

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

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

if !config.OLMDeployed {
if err := createFromYAMLFile(config.Namespace, config.GlobalManifest, config.ProxyImage,
config.ProxyPullPolicy); err != nil {
if !cfg.OLMDeployed {
if err := createFromYAMLFile(cfg.Namespace, cfg.GlobalManifest, cfg.ProxyImage,
cfg.ProxyPullPolicy, cfg.InitTimeout); err != nil {
return testResults, "", fmt.Errorf("failed to create global resources: %v", err)
}
if err := createFromYAMLFile(config.Namespace, config.NamespacedManifest, config.ProxyImage,
config.ProxyPullPolicy); err != nil {
if err := createFromYAMLFile(cfg.Namespace, cfg.NamespacedManifest, cfg.ProxyImage,
cfg.ProxyPullPolicy, cfg.InitTimeout); err != nil {
return testResults, "", fmt.Errorf("failed to create namespaced resources: %v", err)
}
}

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

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

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

Expand All @@ -443,9 +443,9 @@ func runTests(csv *olmapiv1alpha1.ClusterServiceVersion, pluginType PluginType,
Client: runtimeClient,
CR: obj,
CSV: csv,
CRDsDir: config.CRDsDir,
CRDsDir: cfg.CRDsDir,
ProxyPod: proxyPodGlobal,
Bundle: config.Bundle,
Bundle: cfg.Bundle,
}

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

}

tests = applySelector(tests, config.Selector)
tests = applySelector(tests, cfg.Selector)

for _, test := range tests {
testResults = append(testResults, *test.Run(context.TODO()))
Expand Down
10 changes: 5 additions & 5 deletions internal/scorecard/plugins/resource_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func yamlToUnstructured(namespace, yamlPath string) (*unstructured.Unstructured,

// createFromYAMLFile will take a path to a YAML file and create the resource. If it finds a
// deployment, it will add the scorecard proxy as a container in the deployments podspec.
func createFromYAMLFile(namespace, yamlPath, proxyImage string, pullPolicy v1.PullPolicy) error {
func createFromYAMLFile(namespace, yamlPath, proxyImage string, pullPolicy v1.PullPolicy, initTimeout int) error {
yamlSpecs, err := ioutil.ReadFile(yamlPath)
if err != nil {
return fmt.Errorf("failed to read file %s: %v", yamlPath, err)
Expand Down Expand Up @@ -148,7 +148,7 @@ func createFromYAMLFile(namespace, yamlPath, proxyImage string, pullPolicy v1.Pu
return err
}
}
addResourceCleanup(obj, types.NamespacedName{Namespace: obj.GetNamespace(), Name: obj.GetName()})
addResourceCleanup(obj, types.NamespacedName{Namespace: obj.GetNamespace(), Name: obj.GetName()}, initTimeout)
if obj.GetKind() == "Deployment" {
proxyPodGlobal, err = getPodFromDeployment(deploymentName, namespace)
if err != nil {
Expand Down Expand Up @@ -248,7 +248,7 @@ func createKubeconfigSecret(namespace string) error {
return err
}
addResourceCleanup(kubeconfigSecret, types.NamespacedName{Namespace: kubeconfigSecret.GetNamespace(),
Name: kubeconfigSecret.GetName()})
Name: kubeconfigSecret.GetName()}, 60)
return nil
}

Expand Down Expand Up @@ -345,15 +345,15 @@ func cleanupScorecard() error {
}

// addResourceCleanup adds a cleanup function for the specified runtime object
func addResourceCleanup(obj runtime.Object, key types.NamespacedName) {
func addResourceCleanup(obj runtime.Object, key types.NamespacedName, initTimeout int) {
cleanupFns = append(cleanupFns, func() error {
// make a copy of the object because the client changes it
objCopy := obj.DeepCopyObject()
err := runtimeClient.Delete(context.TODO(), obj)
if err != nil && !apierrors.IsNotFound(err) {
return err
}
err = wait.PollImmediate(time.Second*1, time.Second*10, func() (bool, error) {
err = wait.PollImmediate(time.Second*1, time.Second*time.Duration(initTimeout), func() (bool, error) {
err = runtimeClient.Get(context.TODO(), key, objCopy)
if err != nil {
if apierrors.IsNotFound(err) {
Expand Down