@@ -11,6 +11,7 @@ import (
1111 "github.com/kubesaw/ksctl/pkg/configuration"
1212 clicontext "github.com/kubesaw/ksctl/pkg/context"
1313 "github.com/kubesaw/ksctl/pkg/ioutils"
14+ "github.com/kubesaw/ksctl/pkg/utils"
1415 olmv1 "github.com/operator-framework/api/pkg/operators/v1"
1516 olmv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
1617 v1 "k8s.io/api/core/v1"
@@ -43,7 +44,7 @@ func NewInstallOperatorCmd() *cobra.Command {
4344 return err
4445 }
4546
46- cl := commonclient .NewApplyClient (kubeClient )
47+ cl := commonclient .NewSSAApplyClient (kubeClient , utils . KsctlFieldManager )
4748 ctx := clicontext .NewTerminalContext (term )
4849 return installOperator (ctx , commandArgs , args [0 ], cl )
4950 },
@@ -56,7 +57,7 @@ func NewInstallOperatorCmd() *cobra.Command {
5657 return cmd
5758}
5859
59- func installOperator (ctx * clicontext.TerminalContext , args installArgs , operator string , applyClient * commonclient.ApplyClient ) error {
60+ func installOperator (ctx * clicontext.TerminalContext , args installArgs , operator string , applyClient * commonclient.SSAApplyClient ) error {
6061 // validate cluster type
6162 if operator != string (configuration .Host ) && operator != string (configuration .Member ) {
6263 return fmt .Errorf ("invalid operator type provided: %s. Valid ones are %s|%s" , operator , configuration .Host , configuration .Member )
@@ -80,26 +81,26 @@ func installOperator(ctx *clicontext.TerminalContext, args installArgs, operator
8081 }
8182
8283 // check that we don't install both host and member in the same namespace
83- if err := checkOneOperatorPerNamespace (ctx , applyClient , namespace , operator ); err != nil {
84+ if err := checkOneOperatorPerNamespace (ctx , applyClient . Client , namespace , operator ); err != nil {
8485 return err
8586 }
8687
8788 // install the catalog source
8889 namespacedName := types.NamespacedName {Name : operatorResourceName (operator ), Namespace : namespace }
8990 catalogSource := newCatalogSource (namespacedName , operator )
9091 ctx .Println (fmt .Sprintf ("Creating CatalogSource %s in namespace %s." , catalogSource .Name , catalogSource .Namespace ))
91- if _ , err := applyClient .ApplyObject (ctx .Context , catalogSource , commonclient . SaveConfiguration ( false ) ); err != nil {
92+ if err := applyClient .ApplyObject (ctx .Context , catalogSource ); err != nil {
9293 return err
9394 }
9495 ctx .Println (fmt .Sprintf ("CatalogSource %s created." , catalogSource .Name ))
95- if err := waitUntilCatalogSourceIsReady (ctx , applyClient , namespacedName , args .waitForReadyTimeout ); err != nil {
96+ if err := waitUntilCatalogSourceIsReady (ctx , applyClient . Client , namespacedName , args .waitForReadyTimeout ); err != nil {
9697 return err
9798 }
9899 ctx .Printlnf ("CatalogSource %s is ready" , namespacedName )
99100
100101 // check if operator group is already there
101102 ogs := olmv1.OperatorGroupList {}
102- if err := applyClient .List (ctx , & ogs , runtimeclient .InNamespace (namespace )); err != nil {
103+ if err := applyClient .Client . List (ctx , & ogs , runtimeclient .InNamespace (namespace )); err != nil {
103104 return err
104105 }
105106 if len (ogs .Items ) > 0 {
@@ -108,7 +109,7 @@ func installOperator(ctx *clicontext.TerminalContext, args installArgs, operator
108109 // install operator group
109110 operatorGroup := newOperatorGroup (namespacedName )
110111 ctx .Println (fmt .Sprintf ("Creating new operator group %s in namespace %s." , operatorGroup .Name , operatorGroup .Namespace ))
111- if _ , err := applyClient .ApplyObject (ctx , operatorGroup , commonclient . SaveConfiguration ( false ) ); err != nil {
112+ if err := applyClient .ApplyObject (ctx , operatorGroup ); err != nil {
112113 return err
113114 }
114115 ctx .Println (fmt .Sprintf ("OperatorGroup %s created." , operatorGroup .Name ))
@@ -118,11 +119,11 @@ func installOperator(ctx *clicontext.TerminalContext, args installArgs, operator
118119 operatorName := getOperatorName (operator )
119120 subscription := newSubscription (namespacedName , operatorName , namespacedName .Name )
120121 ctx .Println (fmt .Sprintf ("Creating Subscription %s in namespace %s." , subscription .Name , subscription .Namespace ))
121- if _ , err := applyClient .ApplyObject (ctx , subscription , commonclient . SaveConfiguration ( false ) ); err != nil {
122+ if err := applyClient .ApplyObject (ctx , subscription ); err != nil {
122123 return err
123124 }
124125 ctx .Println (fmt .Sprintf ("Subcription %s created." , subscription .Name ))
125- if err := waitUntilInstallPlanIsComplete (ctx , applyClient , operatorName , namespace , args .waitForReadyTimeout ); err != nil {
126+ if err := waitUntilInstallPlanIsComplete (ctx , applyClient . Client , operatorName , namespace , args .waitForReadyTimeout ); err != nil {
126127 return err
127128 }
128129 ctx .Println (fmt .Sprintf ("InstallPlan for the %s operator has been completed" , operator ))
@@ -135,20 +136,16 @@ func getOperatorName(operator string) string {
135136 return fmt .Sprintf ("toolchain-%s-operator" , operator )
136137}
137138
138- func createNamespaceIfNotFound (ctx * clicontext.TerminalContext , applyClient * commonclient.ApplyClient , namespace string ) error {
139- ns := & v1.Namespace {}
140- if err := applyClient .Get (ctx .Context , types.NamespacedName {Name : namespace }, ns ); err != nil {
141- if errors .IsNotFound (err ) {
142- ctx .Println (fmt .Sprintf ("Creating namespace %s." , namespace ))
143- ns .Name = namespace
144- if errNs := applyClient .Create (ctx .Context , ns ); errNs != nil {
145- return errNs
146- }
147- } else {
148- return err
149- }
139+ func createNamespaceIfNotFound (ctx * clicontext.TerminalContext , applyClient * commonclient.SSAApplyClient , namespace string ) error {
140+ ns := & v1.Namespace {
141+ ObjectMeta : metav1.ObjectMeta {
142+ Name : namespace ,
143+ },
144+ }
145+ if err := applyClient .ApplyObject (ctx .Context , ns ); err != nil {
146+ return err
150147 }
151- ctx .Println (fmt .Sprintf ("Namespace %s created ." , namespace ))
148+ ctx .Println (fmt .Sprintf ("Ensured namespace %s ." , namespace ))
152149 return nil
153150}
154151
@@ -209,12 +206,12 @@ func newSubscription(name types.NamespacedName, operatorName, catalogSourceName
209206 }
210207}
211208
212- func waitUntilCatalogSourceIsReady (ctx * clicontext.TerminalContext , applyClient * commonclient. ApplyClient , catalogSourceKey runtimeclient.ObjectKey , waitForReadyTimeout time.Duration ) error {
209+ func waitUntilCatalogSourceIsReady (ctx * clicontext.TerminalContext , cl runtimeclient. Client , catalogSourceKey runtimeclient.ObjectKey , waitForReadyTimeout time.Duration ) error {
213210 cs := & olmv1alpha1.CatalogSource {}
214211 if err := wait .PollUntilContextTimeout (context .TODO (), 2 * time .Second , waitForReadyTimeout , true , func (ctx2 context.Context ) (bool , error ) {
215212 ctx .Printlnf ("waiting for CatalogSource %s to become ready" , catalogSourceKey )
216213 cs = & olmv1alpha1.CatalogSource {}
217- if err := applyClient .Get (ctx , catalogSourceKey , cs ); err != nil {
214+ if err := cl .Get (ctx , catalogSourceKey , cs ); err != nil {
218215 return false , err
219216 }
220217
@@ -253,13 +250,13 @@ func waitUntilInstallPlanIsComplete(ctx *clicontext.TerminalContext, cl runtimec
253250
254251// checkOneOperatorPerNamespace returns an error in case the namespace contains the other operator installed.
255252// So for host namespace member operator should not be installed in there and vice-versa.
256- func checkOneOperatorPerNamespace (ctx * clicontext.TerminalContext , applyClient * commonclient. ApplyClient , namespace , operator string ) error {
253+ func checkOneOperatorPerNamespace (ctx * clicontext.TerminalContext , cl runtimeclient. Client , namespace , operator string ) error {
257254 namespacedName := types.NamespacedName {
258255 Namespace : namespace ,
259256 Name : configuration .ClusterType (operator ).TheOtherType ().String (),
260257 }
261258 subscription := olmv1alpha1.Subscription {}
262- if err := applyClient .Get (ctx .Context , namespacedName , & subscription ); err != nil {
259+ if err := cl .Get (ctx .Context , namespacedName , & subscription ); err != nil {
263260 if errors .IsNotFound (err ) {
264261 return nil
265262 }
0 commit comments