Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: recreate gateway service to make it headless #1222

Merged
merged 3 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions autoscaler/controllers/gateway/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ func syncGateway(dests *odigosv1.DestinationList, processors *odigosv1.Processor
return err
}

err = deletePreviousServices(ctx, c, gateway.Namespace)
if err != nil {
logger.Error(err, "Failed to delete previous services")
return err
}

_, err = syncService(gateway, ctx, c, scheme)
if err != nil {
logger.Error(err, "Failed to sync service")
Expand Down
22 changes: 22 additions & 0 deletions autoscaler/controllers/gateway/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,28 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log"
)

func deletePreviousServices(ctx context.Context, c client.Client, ns string) error {
// to support multiple gateways, odigos service changed it's ClusterIP to None
// this change is not automatically applied to existing installations, we need to delete the service
// so that it can be recreated with the new ClusterIP value
logger := log.FromContext(ctx)
svc := &v1.Service{}
err := c.Get(ctx, client.ObjectKey{Name: kubeObjectName, Namespace: ns}, svc)
if err != nil || svc == nil {
return client.IgnoreNotFound(err)
}

if svc.Spec.ClusterIP != "None" {
logger.Info("Deleting the Odigos gateway service to support multiple gateways.")
err = c.Delete(ctx, svc, &client.DeleteOptions{})
if err != nil {
return err
}
}

return nil
}

func syncService(gateway *odigosv1.CollectorsGroup, ctx context.Context, c client.Client, scheme *runtime.Scheme) (*v1.Service, error) {
logger := log.FromContext(ctx)
gatewaySvc := &v1.Service{
Expand Down
Loading