Skip to content

Commit

Permalink
Create serving certs for headless services on OpenShift (#818) (#824)
Browse files Browse the repository at this point in the history
Add annotation to create serving cerfificates for services on OpenShift.

Resolves: #818

Signed-off-by: Robert Kukura <[email protected]>
  • Loading branch information
Bob Kukura authored Apr 26, 2022
1 parent 6273de6 commit 480f357
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ The `config` node holds the `YAML` that should be passed down as-is to the under

At this point, the Operator does *not* validate the contents of the configuration file: if the configuration is invalid, the instance will still be created but the underlying OpenTelemetry Collector might crash.

The Operator does examine the configuration file to discover configured receivers and their ports. If it finds receivers with ports, it creates a pair of kubernetes services, one headless, exposing those ports within the cluster. The headless service contains a `service.beta.openshift.io/serving-cert-secret-name` annotation that will cause OpenShift to create a secret containing a certificate and key. This secret can be mounted as a volume and the certificate and key used in those receivers' TLS configurations.


### Upgrades

Expand Down
10 changes: 10 additions & 0 deletions pkg/collector/reconcile/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ func headless(ctx context.Context, params Params) *corev1.Service {
}

h.Name = naming.HeadlessService(params.Instance)

// copy to avoid modifying params.Instance.Annotations
annotations := map[string]string{
"service.beta.openshift.io/serving-cert-secret-name": fmt.Sprintf("%s-tls", h.Name),
}
for k, v := range h.Annotations {
annotations[k] = v
}
h.Annotations = annotations

h.Spec.ClusterIP = "None"
return h
}
Expand Down
1 change: 1 addition & 0 deletions pkg/collector/reconcile/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ func TestDeleteServices(t *testing.T) {
func TestHeadlessService(t *testing.T) {
t.Run("should return headless service", func(t *testing.T) {
actual := headless(context.Background(), params())
assert.Equal(t, actual.Annotations["service.beta.openshift.io/serving-cert-secret-name"], "test-collector-headless-tls")
assert.Equal(t, actual.Spec.ClusterIP, "None")
})
}
Expand Down

0 comments on commit 480f357

Please sign in to comment.