operator-framework / operator-lifecycle-manager

A management framework for extending Kubernetes with Operators
https://olm.operatorframework.io
Apache License 2.0
1.73k stars 545 forks source link

OLM generates duplicate service for webhooks if name does not match deployment #2233

Open amisevsk opened 3 years ago

amisevsk commented 3 years ago

Bug Report

What did you do? Deploy an operator with

What did you expect to see? OLM uses the existing service in the bundle to configure conversion webhooks on CRDs.

What did you see instead? Under which circumstances? OLM creates a duplicate service with the same configuration as the provided service to match the controller deployment name. E.g. in my case, I end up with

Environment

Not sure how to get this info; whatever ships with OpenShift 4.7.2

Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.4", GitCommit:"d360454c9bcd1634cf4cc52d1867af5491dc9c5f", GitTreeState:"clean", BuildDate:"2020-11-11T13:17:17Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.0+5fbfd19", GitCommit:"5fbfd197c16d3c5facbaa1d7b9f3ea58cf6b36e9", GitTreeState:"clean", BuildDate:"2021-02-17T15:21:33Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"linux/amd64"}

Additional context This is mostly a point of friction between Operator SDK and OLM. To generate a CSV with webhookDefinitions, the Operator SDK requires:

This gets converted to a CSV whose webhookDefinitions reference the deployment by name directly, skipping the deployment. When the CSV is processed, it results in a separate service being created, with name <deploymentName>-service, even if the service used by Operator SDK has a different name.

The only way to avoid a duplicate service is to look at what OLM does, and then name your service accordingly.

exdx commented 3 years ago

The reason the service is duplicated is because OLM generates APIServices and Webhooks in a very similar way - by providing a port on the CSV OLM generates a service. There's no clear way to change this behavior since other operator CSV's rely on OLM creating a service for their Webhooks and APIServices.

That being said the SDK <-> OLM behavior around webhooks should be consistent, should triage this further.

amisevsk commented 3 years ago

To further add to the confusion caused by this behaviour -- to avoid a duplicate service, I changed the name we use to match what's expected by OLM (i.e. devworkspace-controller-manager-service), but I also added another port to support metrics (rather than have two services that point at the same deployment). In this case, OLM overwrites the perfectly acceptable service's ports, removing my metrics port:

The file in bundle/manifests

apiVersion: v1
kind: Service
spec:
  ports:
  - name: https
    port: 443
    protocol: TCP
    targetPort: conversion
  - name: metrics
    port: 8443
    targetPort: metrics

The service created when installing the operator

apiVersion: v1
kind: Service
spec:
  ports:
  - name: https
    port: 443
    protocol: TCP
    targetPort: conversion