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

Warn if unsupported distribution #1228

Merged
merged 4 commits into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 17 additions & 0 deletions operators/pkg/controller/elasticsearch/driver/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
controller "sigs.k8s.io/controller-runtime/pkg/reconcile"

"github.com/elastic/cloud-on-k8s/operators/pkg/apis/elasticsearch/v1alpha1"
Expand Down Expand Up @@ -173,6 +174,8 @@ func (d *defaultDriver) Reconcile(
min = &d.Version
}

warnUnsupportedDistro(es, resourcesState.AllPods, d.Recorder)
thbkrkr marked this conversation as resolved.
Show resolved Hide resolved

observedState := d.observedStateResolver(
k8s.ExtractNamespacedName(&es),
certificateResources.TrustedHTTPCertificates,
Expand Down Expand Up @@ -545,3 +548,17 @@ func reconcileScriptsConfigMap(c k8s.Client, scheme *runtime.Scheme, es v1alpha1

return nil
}

// warnUnsupportedDistro sends an event of type warning if the Elasticsearch Docker image is not a supported
// distribution by looking at if the prepare fs init container terminated with the UnsupportedDistro exit code.
func warnUnsupportedDistro(es v1alpha1.Elasticsearch, pods []corev1.Pod, recorder record.EventRecorder) {
thbkrkr marked this conversation as resolved.
Show resolved Hide resolved
for _, p := range pods {
for _, s := range p.Status.InitContainerStatuses {
state := s.LastTerminationState.Terminated
if s.Name == initcontainer.PrepareFilesystemContainerName &&
state != nil && state.ExitCode == initcontainer.UnsupportedDistroExitCode {
recorder.Event(&es, corev1.EventTypeWarning, events.EventReasonUnexpected, "Unsupported distribution")
}
}
}
}
6 changes: 4 additions & 2 deletions operators/pkg/controller/elasticsearch/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/elastic/cloud-on-k8s/operators/pkg/controller/elasticsearch/version/version7"
"github.com/elastic/cloud-on-k8s/operators/pkg/utils/k8s"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/record"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
)
Expand All @@ -45,8 +46,9 @@ type Options struct {
// Version is the version of Elasticsearch we want to reconcile towards
Version version.Version
// Client is used to access the Kubernetes API
Client k8s.Client
Scheme *runtime.Scheme
Client k8s.Client
Scheme *runtime.Scheme
Recorder record.EventRecorder

// Observers that observe es clusters state
Observers *observer.Manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,9 @@ func (r *ReconcileElasticsearch) internalReconcile(
}

driver, err := driver.NewDriver(driver.Options{
Client: r.Client,
Scheme: r.scheme,
Client: r.Client,
Scheme: r.scheme,
Recorder: r.recorder,

Version: *ver,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const (
// osSettingsContainerName is the name of the container that tweaks os-level settings
osSettingsContainerName = "elastic-internal-init-os-settings"
// prepareFilesystemContainerName is the name of the container that prepares the filesystem
prepareFilesystemContainerName = "elastic-internal-init-filesystem"
PrepareFilesystemContainerName = "elastic-internal-init-filesystem"
)

// NewInitContainers creates init containers according to the given parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func NewPrepareFSInitContainer(
container := corev1.Container{
Image: imageName,
ImagePullPolicy: corev1.PullIfNotPresent,
Name: prepareFilesystemContainerName,
Name: PrepareFilesystemContainerName,
SecurityContext: &corev1.SecurityContext{
Privileged: &privileged,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package initcontainer

import (
"bytes"
"fmt"
"html/template"
)

Expand All @@ -30,7 +31,10 @@ func RenderScriptTemplate(params TemplateParams) (string, error) {
return tplBuffer.String(), nil
}

const PrepareFsScriptConfigKey = "prepare-fs.sh"
const (
PrepareFsScriptConfigKey = "prepare-fs.sh"
UnsupportedDistroExitCode = 42
)

// scriptTemplate is the main script to be run
// in the prepare-fs init container before ES starts
Expand All @@ -39,6 +43,13 @@ var scriptTemplate = template.Must(template.New("").Parse(

set -eu

# the operator only works with the default ES distribution
license=/usr/share/elasticsearch/modules/x-pack-core/LICENSE.txt
thbkrkr marked this conversation as resolved.
Show resolved Hide resolved
if [[ ! -f $license || $(grep -Fxc "ELASTIC LICENSE AGREEMENT" $license) -ne 1 ]]; then
>&2 echo "unsupported_distro"
thbkrkr marked this conversation as resolved.
Show resolved Hide resolved
exit ` + fmt.Sprintf("%d", UnsupportedDistroExitCode) + `
fi

# compute time in seconds since the given start time
function duration() {
local start=$1
Expand Down