Skip to content

Commit 8bd1fdd

Browse files
authored
Merge pull request #24 from Gl4di4torRr/fix-service-status-update
Fix service status update
2 parents c65d794 + 3164306 commit 8bd1fdd

1 file changed

Lines changed: 24 additions & 18 deletions

File tree

pkg/stub/handler.go

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (h *Handler) handleRoute(route *v1.Route) error {
9191
routeCopy.ObjectMeta.Annotations[h.config.General.Annotations.Status] = "failed"
9292
routeCopy.ObjectMeta.Annotations[h.config.General.Annotations.StatusReason] = err.Error()
9393
} else {
94-
routeCopy.ObjectMeta.Annotations[h.config.General.Annotations.Status] = "no"
94+
routeCopy.ObjectMeta.Annotations[h.config.General.Annotations.Status] = "secured"
9595
}
9696
routeCopy.ObjectMeta.Annotations[h.config.General.Annotations.Expiry] = keyPair.Expiry.Format(timeFormat)
9797

@@ -109,7 +109,11 @@ func (h *Handler) handleRoute(route *v1.Route) error {
109109
routeCopy.Spec.TLS.Key = string(keyPair.Key)
110110
}
111111

112-
updateRoute(routeCopy)
112+
err = apply(routeCopy)
113+
114+
if err != nil {
115+
logrus.Errorf("Error handling route: %s", err.Error())
116+
}
113117

114118
logrus.Infof("Updated route %v/%v with new certificate",
115119
route.ObjectMeta.Namespace,
@@ -145,6 +149,8 @@ func (h *Handler) handleService(service *corev1.Service) error {
145149

146150
var svcCopy *corev1.Service
147151
svcCopy = service.DeepCopy()
152+
svcCopy.ObjectMeta.Annotations[h.config.General.Annotations.Status] = "secured"
153+
svcCopy.ObjectMeta.Annotations[h.config.General.Annotations.Expiry] = keyPair.Expiry.Format(timeFormat)
148154

149155
dm := make(map[string][]byte)
150156
dm["app.crt"] = keyPair.Cert
@@ -163,30 +169,26 @@ func (h *Handler) handleService(service *corev1.Service) error {
163169
Data: dm,
164170
}
165171

166-
err = sdk.Create(certSec)
172+
err = apply(certSec)
173+
167174
if err != nil {
168-
logrus.Errorf("Failed to create secret: " + err.Error())
169-
return err
175+
logrus.Errorf("Error handling secret: %s", err.Error())
170176
}
171177

172178
logrus.Infof("Provisioned new secret %s/%s containing certificate",
173179
certSec.ObjectMeta.Namespace,
174180
certSec.ObjectMeta.Name)
175181

176-
// Update service annotations
177-
svcCopy.ObjectMeta.Annotations[h.config.General.Annotations.Status] = "no"
178-
svcCopy.ObjectMeta.Annotations[h.config.General.Annotations.Expiry] = keyPair.Expiry.Format(timeFormat)
182+
err = apply(svcCopy)
179183

180-
err = sdk.Update(svcCopy)
181184
if err != nil {
182-
logrus.Errorf("Failed to update service: " + err.Error())
183-
return err
185+
logrus.Errorf("Error handling service: %s", err.Error())
184186
}
185187

186188
logrus.Infof("Updated service %v/%v with new certificate",
187189
service.ObjectMeta.Namespace,
188190
service.ObjectMeta.Name)
189-
}
191+
}
190192
return nil
191193
}
192194

@@ -226,10 +228,14 @@ func (h *Handler) getCert(host string) (certs.KeyPair, error) {
226228
return keyPair, nil
227229
}
228230

229-
// update route def
230-
func updateRoute(route *v1.Route) error {
231-
232-
err := sdk.Update(route)
233-
234-
return err
231+
func apply(object sdk.Object) error {
232+
err := sdk.Create(object)
233+
if(err != nil) {
234+
err = sdk.Update(object)
235+
if err != nil {
236+
return err
237+
}
238+
return nil;
239+
}
240+
return nil
235241
}

0 commit comments

Comments
 (0)