Skip to content

Commit

Permalink
Add support for configuration changes under OLM (elastic#3639)
Browse files Browse the repository at this point in the history
* Add support for OLM config

* Fix error message
  • Loading branch information
charith-elastic authored Aug 24, 2020
1 parent 9e27c9e commit 7801dfb
Show file tree
Hide file tree
Showing 9 changed files with 572 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ monitoring-secrets.json
# generated from merging multiple files in the Makefile
config/all-in-one.yaml

# ignore generated configuration
config/eck.yaml

# ignore all generated docs HTML
docs/html/*

Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ LABEL name="Elastic Cloud on Kubernetes" \
RUN microdnf update --setopt=tsflags=nodocs && microdnf clean all

COPY --from=builder /go/src/github.com/elastic/cloud-on-k8s/elastic-operator .
COPY config/eck.yaml /conf/eck.yaml

# Copy NOTICE.txt and LICENSE.txt into the image
COPY *.txt /licenses/
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ dependencies:

# Generate code, CRDs and documentation
ALL_CRDS=config/crds/all-crds.yaml
generate: tidy generate-crds generate-api-docs generate-notice-file
generate: tidy generate-crds generate-config-file generate-api-docs generate-notice-file

tidy:
go mod tidy
Expand All @@ -104,6 +104,9 @@ generate-crds: go-generate controller-gen
# generate an all-in-one version including the operator manifests
$(MAKE) --no-print-directory generate-all-in-one

generate-config-file:
@hack/config-extractor/extract.sh

generate-api-docs:
@hack/api-docs/build.sh

Expand Down Expand Up @@ -333,7 +336,7 @@ switch-eks:
## -- Docker images -- ##
#################################

docker-build: go-generate
docker-build: go-generate generate-config-file
docker build . \
--build-arg GO_LDFLAGS='$(GO_LDFLAGS)' \
--build-arg GO_TAGS='$(GO_TAGS)' \
Expand Down
55 changes: 55 additions & 0 deletions docs/operating-eck/operator-config.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,58 @@ If you use a combination of all or some of the methods listed above, the descend
You can edit the `elastic-operator` ConfigMap to change the operator configuration. Unless the `--disable-config-watch` flag is set, the operator should restart automatically to apply the new changes. Alternatively, you can edit the `elastic-operator` StatefulSet and add flags to the `args` section -- which will trigger an automatic restart of the operator pod by the StatefulSet controller.

[float]
[id="{p}-{page_id}-olm"]
== Configure ECK under Operator Lifecycle Manager

If you use link:https://github.com/operator-framework/operator-lifecycle-manager[Operator Lifecycle Manager (OLM)] to install and run ECK, follow the steps below to configure the operator.

- Create a new ConfigMap in the same namespace as the operator. It should contain a key named `eck.yaml` pointing to the desired configuration values.
+
[source,yaml]
----
apiVersion: v1
kind: ConfigMap
metadata:
name: elastic-operator
namespace: openshift-operators
data:
eck.yaml: |-
log-verbosity: 0
metrics-port: 6060
container-registry: docker.elastic.co
max-concurrent-reconciles: 3
ca-cert-validity: 8760h
ca-cert-rotate-before: 24h
cert-validity: 8760h
cert-rotate-before: 24h
----

- Update your link:https://github.com/operator-framework/operator-lifecycle-manager/blob/master/doc/design/subscription-config.md[Subscription] to mount the ConfigMap under `/conf`.
+
[source,yaml,subs="attributes"]
----
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: elastic-cloud-eck
namespace: openshift-operators
spec:
channel: stable
installPlanApproval: Automatic
name: elastic-cloud-eck
source: elastic-operators
sourceNamespace: openshift-marketplace
startingCSV: elastic-cloud-eck.v{eck_version}
config:
volumes:
- name: config
configMap:
name: elastic-operator
volumeMounts:
- name: config
mountPath: /conf
readOnly: true
----

17 changes: 17 additions & 0 deletions hack/config-extractor/extract.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
# or more contributor license agreements. Licensed under the Elastic License;
# you may not use this file except in compliance with the Elastic License.

# Script to extract ECK configuration map contents from all-in-one.yaml

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
OUT_FILE="${SCRIPT_DIR}/../../config/eck.yaml"

(
cd "$SCRIPT_DIR"
"${SCRIPT_DIR}"/../manifest-gen/manifest-gen.sh -g --exclude-crds --set=config.webhook.enabled=false | go run main.go > "$OUT_FILE"
)
10 changes: 10 additions & 0 deletions hack/config-extractor/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module github.com/elastic/cloud-on-k8s/hack/config-extractor

go 1.15

require (
k8s.io/api v0.18.8
k8s.io/apiextensions-apiserver v0.18.8
k8s.io/apimachinery v0.18.8
k8s.io/kubectl v0.18.8
)
417 changes: 417 additions & 0 deletions hack/config-extractor/go.sum

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions hack/config-extractor/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package main

import (
"bufio"
"errors"
"fmt"
"io"
"os"

v1 "k8s.io/api/core/v1"
apiextv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
"k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/kubectl/pkg/scheme"
)

const (
configMapName = "elastic-operator"
keyName = "eck.yaml"
)

func main() {
conf, err := extractConfig(os.Stdin)
if err != nil {
fmt.Fprintf(os.Stderr, "Error extracting config: %v", err)
os.Exit(1)
}

fmt.Fprint(os.Stdout, conf)
}

func extractConfig(stream io.Reader) (string, error) {
if err := apiextv1beta1.AddToScheme(scheme.Scheme); err != nil {
return "", fmt.Errorf("failed to register api-extensions: %w", err)
}

decoder := scheme.Codecs.UniversalDeserializer()
yamlReader := yaml.NewYAMLReader(bufio.NewReader(stream))

for {
yamlBytes, err := yamlReader.Read()
if err != nil {
if errors.Is(err, io.EOF) {
return "", fmt.Errorf("failed to find ConfigMap named %s", configMapName)
}

return "", fmt.Errorf("failed to read YAML: %w", err)
}

runtimeObj, _, err := decoder.Decode(yamlBytes, nil, nil)
if err != nil {
return "", fmt.Errorf("failed to decode YAML: %w", err)
}

if cm, ok := runtimeObj.(*v1.ConfigMap); ok && cm.Name == configMapName {
return cm.Data[keyName], nil
}
}
}
4 changes: 2 additions & 2 deletions hack/operatorhub/templates/csv.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ spec:
version: {{ .Version }}
{{- end }}
description: 'Elastic Cloud on Kubernetes automates the deployment, provisioning,
management, and orchestration of Elasticsearch, Kibana, APM Server, Beats, and
management, and orchestration of Elasticsearch, Kibana, APM Server, Beats, and
Enterprise Search on Kubernetes.


Expand Down Expand Up @@ -196,7 +196,7 @@ spec:
containers:
- image: {{ .OperatorRepo }}:{{ .NewVersion }}
name: manager
args: ["manager", "--log-verbosity=0"]
args: ["manager", "--config=/conf/eck.yaml"]
env:
- name: NAMESPACES
valueFrom:
Expand Down

0 comments on commit 7801dfb

Please sign in to comment.