@@ -59,6 +59,11 @@ func AutoMesh(svc *coreV1.Service) error {
59
59
return err
60
60
}
61
61
62
+ // Check service in sanity status
63
+ if err = sanityCheck (svc ); err != nil {
64
+ return err
65
+ }
66
+
62
67
// Create stuntman service
63
68
if err = createStuntmanService (svc , ports ); err != nil {
64
69
return err
@@ -125,6 +130,17 @@ func isNameUsable(name, meshVersion string, times int) error {
125
130
return nil
126
131
}
127
132
133
+ func sanityCheck (svc * coreV1.Service ) error {
134
+ if svc .Annotations != nil && svc .Annotations [util .KtSelector ] != "" {
135
+ return fmt .Errorf ("service %s should not have %s annotation, please try use 'ktctl recover %s' to restore it" ,
136
+ svc .Name , util .KtSelector , svc .Name )
137
+ } else if svc .Spec .Selector [util .KtRole ] != "" {
138
+ return fmt .Errorf ("service %s should not point to kt pods, please try use 'ktctl recover %s' to restore it" ,
139
+ svc .Name , svc .Name )
140
+ }
141
+ return nil
142
+ }
143
+
128
144
func createShadowService (shadowSvcName string , ports map [int ]int ,
129
145
selectors map [string ]string ) error {
130
146
if _ , err := cluster .Ins ().CreateService (& cluster.SvcMetaAndSpec {
@@ -205,15 +221,7 @@ func createStuntmanService(svc *coreV1.Service, ports map[int]int) error {
205
221
if stuntmanSvc , err := cluster .Ins ().GetService (stuntmanSvcName , namespace ); err != nil {
206
222
if ! k8sErrors .IsNotFound (err ) {
207
223
return err
208
- }
209
- if svc .Annotations != nil && svc .Annotations [util .KtSelector ] != "" {
210
- return fmt .Errorf ("service %s should not have %s annotation, please try use 'ktctl clean' to restore it" ,
211
- svc .Name , util .KtSelector )
212
- } else if svc .Spec .Selector [util .KtRole ] != "" {
213
- return fmt .Errorf ("service %s should not point to kt pods, please try use 'ktctl clean' to restore it" ,
214
- svc .Name )
215
- }
216
- if _ , err = cluster .Ins ().CreateService (& cluster.SvcMetaAndSpec {
224
+ } else if _ , err = cluster .Ins ().CreateService (& cluster.SvcMetaAndSpec {
217
225
Meta : & cluster.ResourceMeta {
218
226
Name : stuntmanSvcName ,
219
227
Namespace : namespace ,
0 commit comments