Skip to content

Commit

Permalink
Merge pull request #5 from fahlmant/fix-#4
Browse files Browse the repository at this point in the history
Get current route on update, and use resourceVersions
  • Loading branch information
fahlmant authored Jul 19, 2019
2 parents b20490a + b95d683 commit d0d7d51
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions pkg/metrics/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,19 +215,26 @@ func createOrUpdateService(ctx context.Context, client client.Client, s *v1.Serv

//createOrUpdateRoute is a function which creates or updates the route for the service object.
func createOrUpdateRoute(ctx context.Context, client client.Client, r *routev1.Route) (*routev1.Route, error) {
err := client.Create(ctx, r)
if err != nil {
if k8serr.IsAlreadyExists(err) {
if err := client.Create(ctx, r); err != nil {
if err != nil {
if !k8serr.IsAlreadyExists(err) {
return nil, err
}

existingRoute := &routev1.Route{}
err := client.Get(ctx, types.NamespacedName{
Name: r.Name,
Namespace: r.Namespace,
}, existingRoute)
// update the Route
if rUpdateErr := client.Update(ctx, r); rUpdateErr != nil {
log.Info("Error creating metrics route", "Error", rUpdateErr.Error())
return nil, rUpdateErr
r.ResourceVersion = existingRoute.ResourceVersion
if err = client.Update(ctx, r); err != nil {
log.Info("Error creating metrics route", "Error", err.Error())
return nil, err
}
log.Info("Metrics route object updated", "Route.Name", r.Name, "Route.Namespace", r.Namespace)
return nil, nil
log.Info("Metrics Route object updated Route.Name %v and Route.Namespace %v", r.Name, r.Namespace)
return existingRoute, nil
}
log.Info("Error creating metrics route", "Error", err.Error())
return nil, err

}
log.Info("Metrics Route object Created", "Route.Name", r.Name, "Route.Namespace", r.Namespace)
Expand Down

0 comments on commit d0d7d51

Please sign in to comment.