@@ -24,6 +24,7 @@ import (
2424 operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
2525 operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
2626 validationerrors "github.com/operator-framework/api/pkg/validation/errors"
27+ appsv1 "k8s.io/api/apps/v1"
2728 corev1 "k8s.io/api/core/v1"
2829 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2930 apiruntime "k8s.io/apimachinery/pkg/runtime"
@@ -47,6 +48,7 @@ type operatorData struct {
4748 InstallModes map [operatorsv1alpha1.InstallModeType ]operatorsv1alpha1.InstallMode
4849 CsvNamespaces []string
4950 InstalledCsv string
51+ DeploymentNames []string
5052}
5153
5254type DeployableByOlmCheck struct {
@@ -70,6 +72,10 @@ func (p *DeployableByOlmCheck) initClient() error {
7072 return nil
7173 }
7274 scheme := apiruntime .NewScheme ()
75+ if err := appsv1 .AddToScheme (scheme ); err != nil {
76+ return fmt .Errorf ("could not add appsv1 scheme to scheme: %w" , err )
77+ }
78+
7379 if err := openshift .AddSchemes (scheme ); err != nil {
7480 return fmt .Errorf ("could not add new schemes to client: %w" , err )
7581 }
@@ -284,6 +290,11 @@ func (p *DeployableByOlmCheck) operatorMetadata(ctx context.Context, bundleRef i
284290 appName = "p-" + packageName
285291 }
286292
293+ deploymentNames := make ([]string , 0 , len (bundle .CSV .Spec .InstallStrategy .StrategySpec .DeploymentSpecs ))
294+ for _ , deployment := range bundle .CSV .Spec .InstallStrategy .StrategySpec .DeploymentSpecs {
295+ deploymentNames = append (deploymentNames , deployment .Name )
296+ }
297+
287298 return & operatorData {
288299 CatalogImage : catalogImage ,
289300 Channel : channel ,
@@ -292,6 +303,7 @@ func (p *DeployableByOlmCheck) operatorMetadata(ctx context.Context, bundleRef i
292303 InstallNamespace : appName ,
293304 TargetNamespace : appName + "-target" ,
294305 InstallModes : installModes ,
306+ DeploymentNames : deploymentNames ,
295307 }, nil
296308}
297309
@@ -625,6 +637,18 @@ func (p *DeployableByOlmCheck) cleanUp(ctx context.Context, operatorData operato
625637 }
626638 }
627639
640+ for _ , deploymentName := range operatorData .DeploymentNames {
641+ deployment , err := p .openshiftClient .GetDeployment (ctx , deploymentName , operatorData .InstallNamespace )
642+ if err != nil {
643+ logger .Info (fmt .Sprintf ("warning: unable to retrieve deployment: %s" , err ))
644+ continue
645+ }
646+
647+ if err := p .writeToFile (ctx , deployment ); err != nil {
648+ logger .Error (err , "could not write deployment to storage" )
649+ }
650+ }
651+
628652 logger .V (log .TRC ).Info ("deleting the resources created by DeployableByOLM Check" )
629653 _ = p .openshiftClient .DeleteSubscription (ctx , operatorData .App , operatorData .InstallNamespace )
630654 _ = p .openshiftClient .DeleteCatalogSource (ctx , operatorData .App , operatorData .InstallNamespace )
@@ -672,6 +696,10 @@ func (p *DeployableByOlmCheck) writeToFile(ctx context.Context, data interface{}
672696 group = ""
673697 version = "v1"
674698 kind = "Namespace"
699+ case * appsv1.Deployment :
700+ group = "apps"
701+ version = "v1"
702+ kind = "Deployment"
675703 default :
676704 return fmt .Errorf ("go type unsupported" )
677705 }
0 commit comments