@@ -18,7 +18,8 @@ type K8sSetUp interface {
18
18
Initialize () error
19
19
InstallPostgresqlOperator () error
20
20
DatabaseCreation (fileName string ) error
21
- InstallKafkaOperator () error
21
+ CheckKudoInstallation () error
22
+ KafkaClusterCreation (fileName string ) error
22
23
}
23
24
24
25
type k8sSetUpImpl struct {
@@ -51,20 +52,13 @@ func (k k8sSetUpImpl) InstallPostgresqlOperator() error {
51
52
return nil
52
53
}
53
54
54
- func (k k8sSetUpImpl ) InstallKafkaOperator () error {
55
- log .Println ("Installing Kafka operator ..." )
55
+ func (k k8sSetUpImpl ) CheckKudoInstallation () error {
56
+ log .Println ("Checking kudo installation ..." )
56
57
57
- if installed := k .isKafkaOperatorInstalled (); ! installed {
58
- log .Println ("Kafka operator not installed ..." )
59
- if err := k .doKafkaOperatorInstallation (); err != nil {
60
- return fmt .Errorf ("error installing Kafka operator: %v" , err )
61
- }
62
- k .waiKafkaOperatorRunning ()
63
-
64
- } else {
65
- log .Println ("Kafka operator is installed ..." )
58
+ if _ , err := k .kubectl ("kudo" , "version" ); err != nil {
59
+ return fmt .Errorf ("kudo is not installed: %v" , err )
66
60
}
67
-
61
+ log . Println ( "Kudo is installed ..." )
68
62
return nil
69
63
}
70
64
@@ -77,16 +71,7 @@ func (k k8sSetUpImpl) waitPsqlOperatorRunning() {
77
71
log .Print ("Psql operator is running" )
78
72
}
79
73
80
- func (k k8sSetUpImpl ) waiKafkaOperatorRunning () {
81
- cnt := true
82
- for cnt {
83
- ready , err := k .isKafkaOperatorRunning ()
84
- cnt = ! (err == nil && ready )
85
- }
86
- log .Print ("Kafka operator is running" )
87
- }
88
-
89
- func (k k8sSetUpImpl ) isOperatorRunning (name , namespace string ) (running bool , err error ) {
74
+ func (k k8sSetUpImpl ) isPodRunning (name , namespace string ) (running bool , err error ) {
90
75
log .Printf ("Checking if %s operator is already running ..." , name )
91
76
92
77
var podNames , output string
@@ -105,11 +90,7 @@ func (k k8sSetUpImpl) isOperatorRunning(name, namespace string) (running bool, e
105
90
}
106
91
107
92
func (k k8sSetUpImpl ) isPsqlOperatorRunning () (bool , error ) {
108
- return k .isOperatorRunning ("postgres-operator" , "default" )
109
- }
110
-
111
- func (k k8sSetUpImpl ) isKafkaOperatorRunning () (bool , error ) {
112
- return k .isOperatorRunning ("strimzi-cluster-operator" , "kafka" )
93
+ return k .isPodRunning ("postgres-operator" , "default" )
113
94
}
114
95
115
96
func (k k8sSetUpImpl ) isPostgreSQLOperatorInstalled () bool {
@@ -121,15 +102,6 @@ func (k k8sSetUpImpl) isPostgreSQLOperatorInstalled() bool {
121
102
return true
122
103
}
123
104
124
- func (k k8sSetUpImpl ) isKafkaOperatorInstalled () bool {
125
- log .Println ("Checking if kafka operator is already installed ..." )
126
- if _ , err := k .kubectl ("describe" , "deployment.apps/strimzi-cluster-operator" , "-n" , "kafka" ); err != nil {
127
- return false
128
- }
129
-
130
- return true
131
- }
132
-
133
105
func (k * k8sSetUpImpl ) doPsqlOperatorInstallation () error {
134
106
log .Println ("Installing postgreSQL operator ..." )
135
107
dir , err := ioutil .TempDir ("" , "pets-go-infra" )
@@ -164,18 +136,6 @@ func (k *k8sSetUpImpl) doPsqlOperatorInstallation() error {
164
136
return nil
165
137
}
166
138
167
- func (k * k8sSetUpImpl ) doKafkaOperatorInstallation () error {
168
- log .Println ("Installing kafka operator ..." )
169
- if _ , err := k .kubectl ("create" , "namespace" , "kafka" ); err != nil {
170
- return fmt .Errorf ("error in kubectl create: %v" , err )
171
- }
172
- if _ , err := k .kubectl ("apply" , "-f" , "https://strimzi.io/install/latest?namespace=kafka" , "-n" , "kafka" ); err != nil {
173
- return fmt .Errorf ("error in kubectl apply: %v" , err )
174
- }
175
-
176
- return nil
177
- }
178
-
179
139
func (k k8sSetUpImpl ) kubectl (params ... string ) (output string , err error ) {
180
140
return k .executeCommand (k .kubectlPath , params ... )
181
141
}
@@ -200,6 +160,15 @@ func (k k8sSetUpImpl) defaultExecuteCommand(cmdName string, params ...string) (o
200
160
return
201
161
}
202
162
163
+ func (k k8sSetUpImpl ) isResourceCreated (rtype , name , namespace string ) (bool , error ) {
164
+ log .Printf ("Checking if resource %q name %q is already created ..." , rtype , name )
165
+ if _ , err := k .kubectl ("describe" , rtype + "/" + name , "-n" , namespace ); err != nil {
166
+ return false , err
167
+ }
168
+
169
+ return true , nil
170
+ }
171
+
203
172
// NewK8sSetUp returns a K8sSetUp interface
204
173
func NewK8sSetUp () K8sSetUp {
205
174
impl := & k8sSetUpImpl {
0 commit comments