@@ -55,54 +55,62 @@ func (ca *capAudit) OperandInstall() error {
55
55
56
56
ca .getAlmExamples ()
57
57
58
- // TODO: we need a stratergy to select which CR to select from ALMExamplesList
59
- if len (ca .customResources ) > 0 {
60
- for _ , cr := range ca .customResources {
61
- obj := & unstructured.Unstructured {Object : cr }
62
- // using dynamic client to create Unstructured objests in k8s
63
- client , err := operator .NewDynamicClient ()
64
- if err != nil {
65
- return err
66
- }
58
+ if len (ca .customResources ) == 0 {
59
+ logger .Debug ("exiting OperandInstall since no ALM_Examples found in CSV" )
60
+ return nil
61
+ }
67
62
68
- // set the namespace of CR to the namespace of the subscription
69
- obj .SetNamespace (ca .namespace )
63
+ csv , _ := ca .client .GetCompletedCsvWithTimeout (ca .namespace , time .Minute )
70
64
71
- var crdList apiextensionsv1.CustomResourceDefinitionList
72
- err = ca .client .ListCRDs (context .TODO (), & crdList )
73
- if err != nil {
74
- return err
75
- }
65
+ if strings .ToLower (string (csv .Status .Phase )) != "succeeded" {
66
+ logger .Debug ("exiting OperandInstall since CSV has failed" )
67
+ return nil
68
+ }
76
69
77
- var Resource string
70
+ for _ , cr := range ca .customResources {
71
+ obj := & unstructured.Unstructured {Object : cr }
72
+ // using dynamic client to create Unstructured objects in k8s
73
+ client , err := operator .NewDynamicClient ()
74
+ if err != nil {
75
+ return err
76
+ }
78
77
79
- for _ , crd := range crdList .Items {
80
- if crd .Spec .Group == obj .GroupVersionKind ().Group && crd .Spec .Names .Kind == obj .GroupVersionKind ().Kind {
81
- Resource = crd .Spec .Names .Plural
82
- }
83
- }
78
+ // set the namespace of CR to the namespace of the subscription
79
+ obj .SetNamespace (ca .namespace )
84
80
85
- gvr := schema. GroupVersionResource {
86
- Group : obj . GroupVersionKind (). Group ,
87
- Version : obj . GroupVersionKind (). Version ,
88
- Resource : Resource ,
89
- }
81
+ var crdList apiextensionsv1. CustomResourceDefinitionList
82
+ err = ca . client . ListCRDs ( context . TODO (), & crdList )
83
+ if err != nil {
84
+ return err
85
+ }
90
86
91
- csv , _ := ca .client .GetCompletedCsvWithTimeout (ca .namespace , time .Minute )
92
- if strings .ToLower (string (csv .Status .Phase )) == "succeeded" {
93
- // create the resource using the dynamic client and log the error if it occurs in stdout.json
94
- unstructuredCR , err := client .Resource (gvr ).Namespace (ca .namespace ).Create (context .TODO (), obj , v1.CreateOptions {})
95
- if err != nil {
96
-
97
- return err
98
- }
99
- ca .operands = append (ca .operands , * unstructuredCR )
100
- } else {
101
- logger .Debug ("exiting OperandInstall since CSV has failed" )
87
+ var Resource string
88
+
89
+ for _ , crd := range crdList .Items {
90
+ if crd .Spec .Group == obj .GroupVersionKind ().Group && crd .Spec .Names .Kind == obj .GroupVersionKind ().Kind {
91
+ Resource = crd .Spec .Names .Plural
102
92
}
103
93
}
104
- } else {
105
- logger .Debug ("exiting OperandInstall since no ALM_Examples found in CSV" )
94
+
95
+ gvr := schema.GroupVersionResource {
96
+ Group : obj .GroupVersionKind ().Group ,
97
+ Version : obj .GroupVersionKind ().Version ,
98
+ Resource : Resource ,
99
+ }
100
+
101
+ csv , _ := ca .client .GetCompletedCsvWithTimeout (ca .namespace , time .Minute )
102
+
103
+ if strings .ToLower (string (csv .Status .Phase )) != "succeeded" {
104
+ logger .Debug ("exiting OperandInstall since CSV has failed" )
105
+ return nil
106
+ }
107
+
108
+ // create the resource using the dynamic client and log the error if it occurs in stdout.json
109
+ unstructuredCR , err := client .Resource (gvr ).Namespace (ca .namespace ).Create (context .TODO (), obj , v1.CreateOptions {})
110
+ if err != nil {
111
+ return err
112
+ }
113
+ ca .operands = append (ca .operands , * unstructuredCR )
106
114
}
107
115
108
116
file , err := os .OpenFile ("operand_install_report.json" , os .O_APPEND | os .O_CREATE | os .O_WRONLY , 0644 )
0 commit comments