From 6553082f4e7b22360379c777155445cf8f38a0ca Mon Sep 17 00:00:00 2001 From: Sebastien Guilloux Date: Mon, 9 Dec 2019 17:23:12 +0100 Subject: [PATCH] (not ready to merge) Create CRDs V1 (#2184) Bump the current v1beta1 CRD to a separate v1 CRD with the exact same content. As such, it's fine to rely on the OpenAPI validation schema of the v1 version to validate the v1beta1 resources. I tried to make sure every single reference we had to the v1beta1 API is updated to use the v1 API now. Along with that change I tried to homogenize the imports so we always import esv1, kbv1, etc. instead of using a mix of estype, esv1beta1, elasticsearchv1beta1, v1beta1, etc. * Add v1 API codebase * Unset storage version for v1beta1 resources * Fix Elasticsearch webhook path * Regenerate CRDs with v1 version * Regenerate webhook manifests with v1 webhook * Use v1 APIs in the entire codebase & homogenize imports * Adapt golangci exceptions to v1 apis * Use v1 CRD in samples * Regenerate API docs to cover v1 crds * Default to using crd v1 in the documentation * Fix typo: corev1 * Regenerate api docs with the fixed version with sorting --- .golangci.yml | 4 + cmd/manager/main.go | 31 +- config/crds/all-crds.yaml | 21 +- .../bases/apm.k8s.elastic.co_apmservers.yaml | 7 +- ...search.k8s.elastic.co_elasticsearches.yaml | 7 +- .../bases/kibana.k8s.elastic.co_kibanas.yaml | 7 +- config/e2e/global_operator.yaml | 19 + config/operator/global/webhook.template.yaml | 19 + config/recipes/beats/1_monitor.yaml | 4 +- config/samples/apm/apm_es_kibana.yaml | 6 +- config/samples/apm/apmserver.yaml | 2 +- .../samples/elasticsearch/elasticsearch.yaml | 2 +- config/samples/kibana/kibana_es.yaml | 4 +- config/webhook/manifests.yaml | 20 +- docs/api-docs.asciidoc | 1077 +++++++++++++++-- docs/eck-attributes.asciidoc | 2 +- pkg/apis/apm/v1/apmserver_types.go | 123 ++ pkg/apis/apm/v1/doc.go | 8 + pkg/apis/apm/v1/groupversion_info.go | 21 + pkg/apis/apm/v1/zz_generated.deepcopy.go | 123 ++ pkg/apis/apm/v1beta1/apmserver_types.go | 1 - pkg/apis/common/v1/association.go | 113 ++ pkg/apis/common/v1/association_test.go | 77 ++ pkg/apis/common/v1/common.go | 154 +++ pkg/apis/common/v1/common_test.go | 134 ++ pkg/apis/common/v1/config.go | 60 + pkg/apis/common/v1/config_test.go | 83 ++ pkg/apis/common/v1/doc.go | 8 + pkg/apis/common/v1/groupversion_info.go | 21 + pkg/apis/common/v1/zz_generated.deepcopy.go | 223 ++++ pkg/apis/elasticsearch/v1/doc.go | 8 + .../elasticsearch/v1/elasticsearch_config.go | 62 + .../v1/elasticsearch_config_test.go | 202 ++++ .../elasticsearch/v1/elasticsearch_types.go | 247 ++++ .../v1/elasticsearch_types_test.go | 214 ++++ pkg/apis/elasticsearch/v1/fields.go | 62 + .../elasticsearch/v1/groupversion_info.go | 21 + pkg/apis/elasticsearch/v1/name.go | 137 +++ pkg/apis/elasticsearch/v1/name_test.go | 74 ++ pkg/apis/elasticsearch/v1/validations.go | 218 ++++ pkg/apis/elasticsearch/v1/validations_test.go | 660 ++++++++++ pkg/apis/elasticsearch/v1/warnings.go | 41 + pkg/apis/elasticsearch/v1/warnings_test.go | 136 +++ pkg/apis/elasticsearch/v1/webhook.go | 72 ++ .../elasticsearch/v1/zz_generated.deepcopy.go | 261 ++++ .../v1beta1/elasticsearch_types.go | 1 - pkg/apis/elasticsearch/v1beta1/webhook.go | 2 +- pkg/apis/kibana/v1/doc.go | 8 + pkg/apis/kibana/v1/groupversion_info.go | 21 + pkg/apis/kibana/v1/kibana_types.go | 123 ++ pkg/apis/kibana/v1/zz_generated.deepcopy.go | 123 ++ pkg/apis/kibana/v1beta1/kibana_types.go | 1 - .../apmserver/apmserver_controller.go | 24 +- .../apmserver/apmserver_controller_test.go | 12 +- .../apmserver/certificates/reconcile.go | 11 +- pkg/controller/apmserver/config/config.go | 10 +- .../apmserver/config/config_test.go | 25 +- pkg/controller/apmserver/config/reconcile.go | 13 +- pkg/controller/apmserver/pod.go | 6 +- pkg/controller/apmserver/pod_test.go | 8 +- pkg/controller/apmserver/services.go | 4 +- pkg/controller/apmserver/services_test.go | 32 +- pkg/controller/apmserver/state.go | 13 +- ...rverelasticsearchassociation_controller.go | 75 +- ...lasticsearchassociation_controller_test.go | 20 +- .../common/annotation/association.go | 13 +- .../annotation/controller_version_test.go | 27 +- .../common/association/association.go | 7 +- .../common/association/association_test.go | 18 +- pkg/controller/common/association/ca.go | 19 +- pkg/controller/common/association/ca_test.go | 16 +- pkg/controller/common/association/conf.go | 17 +- .../common/association/conf_test.go | 44 +- pkg/controller/common/association/gc_test.go | 21 +- pkg/controller/common/association/user.go | 25 +- .../common/association/user_test.go | 24 +- .../common/certificates/ca_reconcile_test.go | 6 +- .../certificates/http/certificates_secret.go | 4 +- .../certificates/http/dynamic_watches.go | 4 +- .../certificates/http/public_secret_test.go | 8 +- .../common/certificates/http/reconcile.go | 12 +- .../certificates/http/reconcile_test.go | 50 +- .../common/deployment/reconcile_test.go | 4 +- .../common/finalizer/finalizers_test.go | 18 +- pkg/controller/common/keystore/resources.go | 9 +- .../common/keystore/resources_test.go | 16 +- pkg/controller/common/keystore/user_secret.go | 19 +- .../common/keystore/user_secret_test.go | 53 +- pkg/controller/common/scheme/scheme.go | 17 +- pkg/controller/common/service_control_test.go | 4 +- pkg/controller/common/user/label.go | 11 +- .../certificates/ca_reconcile.go | 12 +- .../certificates/transport/csr.go | 11 +- .../certificates/transport/csr_test.go | 4 +- .../certificates/transport/pod_secret.go | 9 +- .../certificates/transport/public_secret.go | 6 +- .../transport/public_secret_test.go | 4 +- .../certificates/transport/reconcile.go | 8 +- .../certificates/transport/reconcile_test.go | 6 +- .../transport/transport_fixtures_test.go | 4 +- .../elasticsearch/cleanup/resources.go | 9 +- .../elasticsearch/cleanup/resources_test.go | 6 +- .../elasticsearch/configmap/configmap.go | 15 +- .../configmap/configmap_control.go | 9 +- .../elasticsearch/driver/bootstrap.go | 12 +- .../elasticsearch/driver/bootstrap_test.go | 32 +- .../elasticsearch/driver/downscale.go | 10 +- .../driver/downscale_invariants.go | 7 +- .../driver/downscale_invariants_test.go | 6 +- .../elasticsearch/driver/downscale_test.go | 20 +- .../elasticsearch/driver/downscale_utils.go | 6 +- pkg/controller/elasticsearch/driver/driver.go | 6 +- .../elasticsearch/driver/esstate.go | 4 +- .../elasticsearch/driver/esstate_test.go | 6 +- .../elasticsearch/driver/expectations_test.go | 4 +- .../elasticsearch/driver/fixtures.go | 21 +- pkg/controller/elasticsearch/driver/pvc.go | 4 +- .../elasticsearch/driver/pvc_test.go | 11 +- .../elasticsearch/driver/upgrade.go | 6 +- .../elasticsearch/driver/upgrade_forced.go | 4 +- .../driver/upgrade_pods_deletion.go | 9 +- .../driver/upgrade_predicates.go | 6 +- .../driver/upgrade_predicates_test.go | 8 +- .../elasticsearch/driver/upscale.go | 6 +- .../driver/upscale_state_test.go | 4 +- .../elasticsearch/driver/upscale_test.go | 18 +- .../elasticsearch/elasticsearch_controller.go | 18 +- .../elasticsearch/initcontainer/prepare_fs.go | 4 +- pkg/controller/elasticsearch/label/label.go | 6 +- pkg/controller/elasticsearch/license/apply.go | 4 +- .../elasticsearch/license/apply_test.go | 19 +- .../elasticsearch/license/reconcile.go | 4 +- .../elasticsearch/nodespec/defaults.go | 4 +- .../elasticsearch/nodespec/podspec.go | 16 +- .../elasticsearch/nodespec/podspec_test.go | 12 +- .../elasticsearch/nodespec/resources.go | 8 +- .../elasticsearch/nodespec/statefulset.go | 21 +- .../nodespec/statefulset_test.go | 52 +- .../elasticsearch/nodespec/volumes.go | 12 +- pkg/controller/elasticsearch/pdb/reconcile.go | 35 +- .../elasticsearch/pdb/reconcile_test.go | 64 +- .../reconcile/resources_state.go | 6 +- .../elasticsearch/reconcile/state.go | 31 +- .../elasticsearch/reconcile/state_test.go | 77 +- .../elasticsearch/services/services.go | 12 +- .../elasticsearch/services/services_test.go | 48 +- .../settings/canonical_config.go | 6 +- .../elasticsearch/settings/config_volume.go | 8 +- .../settings/config_volume_test.go | 6 +- .../elasticsearch/settings/masters.go | 6 +- .../elasticsearch/settings/masters_test.go | 8 +- .../elasticsearch/settings/merged_config.go | 60 +- .../settings/merged_config_test.go | 55 +- pkg/controller/elasticsearch/sset/fixtures.go | 9 +- pkg/controller/elasticsearch/sset/pod.go | 13 +- pkg/controller/elasticsearch/sset/pod_test.go | 4 +- .../elasticsearch/sset/reconcile.go | 9 +- .../elasticsearch/sset/reconcile_test.go | 5 +- .../elasticsearch/user/credentials.go | 8 +- .../elasticsearch/user/reconciler.go | 13 +- .../version/zen1/compatibility.go | 9 +- .../version/zen1/compatibility_test.go | 4 +- .../version/zen1/minimum_masters.go | 17 +- .../version/zen1/minimum_masters_test.go | 31 +- .../version/zen2/compatibility.go | 6 +- .../version/zen2/compatibility_test.go | 20 +- .../version/zen2/initial_master_nodes.go | 4 +- .../version/zen2/initial_master_nodes_test.go | 8 +- .../version/zen2/voting_exclusions.go | 6 +- .../version/zen2/voting_exclusions_test.go | 4 +- .../kibana/certificates/reconcile.go | 11 +- pkg/controller/kibana/config/reconciler.go | 4 +- .../kibana/config/reconciler_test.go | 8 +- pkg/controller/kibana/config/secret_volume.go | 6 +- pkg/controller/kibana/config/settings.go | 14 +- pkg/controller/kibana/config/settings_test.go | 36 +- pkg/controller/kibana/driver.go | 10 +- pkg/controller/kibana/driver_test.go | 49 +- pkg/controller/kibana/es/secret.go | 6 +- pkg/controller/kibana/kibana_controller.go | 16 +- pkg/controller/kibana/pod/pod.go | 8 +- pkg/controller/kibana/pod/pod_test.go | 39 +- pkg/controller/kibana/services.go | 4 +- pkg/controller/kibana/services_test.go | 41 +- pkg/controller/kibana/state.go | 19 +- .../kibana/version/version6/settings.go | 4 +- .../kibana/version/version7/settings.go | 4 +- .../association_controller.go | 73 +- .../association_controller_test.go | 39 +- pkg/controller/kibanaassociation/labels.go | 9 +- pkg/controller/kibanaassociation/watch.go | 10 +- pkg/controller/license/license_controller.go | 32 +- .../license_controller_integration_test.go | 10 +- .../license/license_controller_test.go | 8 +- pkg/controller/license/list.go | 7 +- pkg/controller/license/list_test.go | 9 +- test/e2e/apm/association_test.go | 12 +- test/e2e/apm/configuration_test.go | 12 +- test/e2e/apm/standalone_test.go | 8 +- test/e2e/es/certs_test.go | 6 +- test/e2e/es/failure_test.go | 4 +- test/e2e/es/forced_upgrade_test.go | 14 +- test/e2e/es/keystore_test.go | 4 +- test/e2e/es/naming_test.go | 14 +- test/e2e/es/podtemplate_test.go | 4 +- test/e2e/es/reversal_test.go | 20 +- test/e2e/kb/association_test.go | 12 +- test/e2e/kb/keystore_test.go | 4 +- test/e2e/kb/testdata/kibana_standalone.yaml | 4 +- test/e2e/samples_test.go | 4 +- test/e2e/test/apmserver/builder.go | 18 +- test/e2e/test/apmserver/checks_apm.go | 16 +- test/e2e/test/apmserver/http_client.go | 4 +- test/e2e/test/apmserver/steps_creation.go | 4 +- test/e2e/test/apmserver/steps_init.go | 4 +- test/e2e/test/elasticsearch/builder.go | 63 +- test/e2e/test/elasticsearch/checks_budget.go | 6 +- test/e2e/test/elasticsearch/checks_es.go | 25 +- test/e2e/test/elasticsearch/checks_k8s.go | 18 +- test/e2e/test/elasticsearch/checks_volume.go | 6 +- test/e2e/test/elasticsearch/cluster_uuid.go | 8 +- test/e2e/test/elasticsearch/http_client.go | 6 +- test/e2e/test/elasticsearch/pause.go | 10 +- test/e2e/test/elasticsearch/settings.go | 8 +- test/e2e/test/elasticsearch/steps_creation.go | 4 +- test/e2e/test/elasticsearch/steps_init.go | 6 +- test/e2e/test/elasticsearch/steps_license.go | 17 +- test/e2e/test/elasticsearch/steps_mutation.go | 6 +- test/e2e/test/helper/yaml.go | 18 +- test/e2e/test/k8s_client.go | 16 +- test/e2e/test/kibana/builder.go | 23 +- test/e2e/test/kibana/checks_kb.go | 6 +- test/e2e/test/kibana/http_client.go | 4 +- test/e2e/test/kibana/steps_creation.go | 4 +- test/e2e/test/kibana/steps_init.go | 4 +- test/e2e/test/kibana/steps_mutation.go | 4 +- 236 files changed, 6285 insertions(+), 1500 deletions(-) create mode 100644 pkg/apis/apm/v1/apmserver_types.go create mode 100644 pkg/apis/apm/v1/doc.go create mode 100644 pkg/apis/apm/v1/groupversion_info.go create mode 100644 pkg/apis/apm/v1/zz_generated.deepcopy.go create mode 100644 pkg/apis/common/v1/association.go create mode 100644 pkg/apis/common/v1/association_test.go create mode 100644 pkg/apis/common/v1/common.go create mode 100644 pkg/apis/common/v1/common_test.go create mode 100644 pkg/apis/common/v1/config.go create mode 100644 pkg/apis/common/v1/config_test.go create mode 100644 pkg/apis/common/v1/doc.go create mode 100644 pkg/apis/common/v1/groupversion_info.go create mode 100644 pkg/apis/common/v1/zz_generated.deepcopy.go create mode 100644 pkg/apis/elasticsearch/v1/doc.go create mode 100644 pkg/apis/elasticsearch/v1/elasticsearch_config.go create mode 100644 pkg/apis/elasticsearch/v1/elasticsearch_config_test.go create mode 100644 pkg/apis/elasticsearch/v1/elasticsearch_types.go create mode 100644 pkg/apis/elasticsearch/v1/elasticsearch_types_test.go create mode 100644 pkg/apis/elasticsearch/v1/fields.go create mode 100644 pkg/apis/elasticsearch/v1/groupversion_info.go create mode 100644 pkg/apis/elasticsearch/v1/name.go create mode 100644 pkg/apis/elasticsearch/v1/name_test.go create mode 100644 pkg/apis/elasticsearch/v1/validations.go create mode 100644 pkg/apis/elasticsearch/v1/validations_test.go create mode 100644 pkg/apis/elasticsearch/v1/warnings.go create mode 100644 pkg/apis/elasticsearch/v1/warnings_test.go create mode 100644 pkg/apis/elasticsearch/v1/webhook.go create mode 100644 pkg/apis/elasticsearch/v1/zz_generated.deepcopy.go create mode 100644 pkg/apis/kibana/v1/doc.go create mode 100644 pkg/apis/kibana/v1/groupversion_info.go create mode 100644 pkg/apis/kibana/v1/kibana_types.go create mode 100644 pkg/apis/kibana/v1/zz_generated.deepcopy.go diff --git a/.golangci.yml b/.golangci.yml index 2c1ea880317..2416c7d1681 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -66,6 +66,8 @@ issues: text: 'ifElseChain: rewrite if\-else to switch statement' - path: pkg/apis/elasticsearch/v1beta1/fields\.go text: 'const .* should be' + - path: pkg/apis/elasticsearch/v1/fields\.go + text: 'const .* should be' - path: pkg/controller/elasticsearch/user/reconciler\.go text: 'Consider preallocating `allUsers`' - path: pkg/controller/elasticsearch/user/user\.go @@ -92,6 +94,8 @@ issues: text: 'G101: Potential hardcoded credentials' - path: pkg/apis/elasticsearch/v1beta1/name\.go text: 'G101: Potential hardcoded credentials' + - path: pkg/apis/elasticsearch/v1/name\.go + text: 'G101: Potential hardcoded credentials' - path: pkg/controller/elasticsearch/driver/version\.go text: 'Consider preallocating `vs`' - linters: diff --git a/cmd/manager/main.go b/cmd/manager/main.go index ca0b28d8dff..3f3135754b8 100644 --- a/cmd/manager/main.go +++ b/cmd/manager/main.go @@ -17,10 +17,20 @@ import ( // allow gcp authentication _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" + "github.com/spf13/cobra" + "github.com/spf13/viper" + "k8s.io/client-go/kubernetes" + clientgoscheme "k8s.io/client-go/kubernetes/scheme" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/cache" + logf "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/manager" + "sigs.k8s.io/controller-runtime/pkg/manager/signals" + "github.com/elastic/cloud-on-k8s/pkg/about" - apmtype "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1beta1" - estype "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - kibanatype "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + apmv1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/apmserver" asesassn "github.com/elastic/cloud-on-k8s/pkg/controller/apmserverelasticsearchassociation" "github.com/elastic/cloud-on-k8s/pkg/controller/common/association" @@ -36,15 +46,6 @@ import ( "github.com/elastic/cloud-on-k8s/pkg/dev" "github.com/elastic/cloud-on-k8s/pkg/dev/portforward" "github.com/elastic/cloud-on-k8s/pkg/utils/net" - "github.com/spf13/cobra" - "github.com/spf13/viper" - "k8s.io/client-go/kubernetes" - clientgoscheme "k8s.io/client-go/kubernetes/scheme" - ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/cache" - logf "sigs.k8s.io/controller-runtime/pkg/log" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/manager/signals" ) const ( @@ -349,8 +350,8 @@ func garbageCollectUsers(cfg *rest.Config, managedNamespaces []string) { os.Exit(1) } err = ugc. - For(&apmtype.ApmServerList{}, asesassn.AssociationLabelNamespace, asesassn.AssociationLabelName). - For(&kibanatype.KibanaList{}, kbassn.AssociationLabelNamespace, kbassn.AssociationLabelName). + For(&apmv1.ApmServerList{}, asesassn.AssociationLabelNamespace, asesassn.AssociationLabelName). + For(&kbv1.KibanaList{}, kbassn.AssociationLabelNamespace, kbassn.AssociationLabelName). DoGarbageCollection() if err != nil { log.Error(err, "user garbage collector failed") @@ -382,7 +383,7 @@ func setupWebhook(mgr manager.Manager, certRotation certificates.RotationParams, } } - if err := (&estype.Elasticsearch{}).SetupWebhookWithManager(mgr); err != nil { + if err := (&esv1.Elasticsearch{}).SetupWebhookWithManager(mgr); err != nil { log.Error(err, "unable to create webhook", "webhook", "Elasticsearch") os.Exit(1) } diff --git a/config/crds/all-crds.yaml b/config/crds/all-crds.yaml index acad73791d7..8fb518d8dfb 100644 --- a/config/crds/all-crds.yaml +++ b/config/crds/all-crds.yaml @@ -375,11 +375,14 @@ spec: connect to. type: string type: object - version: v1beta1 + version: v1 versions: - - name: v1beta1 + - name: v1 served: true storage: true + - name: v1beta1 + served: true + storage: false - name: v1alpha1 served: false storage: false @@ -1084,11 +1087,14 @@ spec: is in from the controller point of view. type: string type: object - version: v1beta1 + version: v1 versions: - - name: v1beta1 + - name: v1 served: true storage: true + - name: v1beta1 + served: true + storage: false - name: v1alpha1 served: false storage: false @@ -1465,11 +1471,14 @@ spec: description: KibanaHealth expresses the status of the Kibana instances. type: string type: object - version: v1beta1 + version: v1 versions: - - name: v1beta1 + - name: v1 served: true storage: true + - name: v1beta1 + served: true + storage: false - name: v1alpha1 served: false storage: false diff --git a/config/crds/bases/apm.k8s.elastic.co_apmservers.yaml b/config/crds/bases/apm.k8s.elastic.co_apmservers.yaml index 6828326f440..d016f677934 100644 --- a/config/crds/bases/apm.k8s.elastic.co_apmservers.yaml +++ b/config/crds/bases/apm.k8s.elastic.co_apmservers.yaml @@ -4566,11 +4566,14 @@ spec: type: string type: object type: object - version: v1beta1 + version: v1 versions: - - name: v1beta1 + - name: v1 served: true storage: true + - name: v1beta1 + served: true + storage: false status: acceptedNames: kind: "" diff --git a/config/crds/bases/elasticsearch.k8s.elastic.co_elasticsearches.yaml b/config/crds/bases/elasticsearch.k8s.elastic.co_elasticsearches.yaml index 48cc87480b5..a6fdc54a0f0 100644 --- a/config/crds/bases/elasticsearch.k8s.elastic.co_elasticsearches.yaml +++ b/config/crds/bases/elasticsearch.k8s.elastic.co_elasticsearches.yaml @@ -5181,11 +5181,14 @@ spec: type: string type: object type: object - version: v1beta1 + version: v1 versions: - - name: v1beta1 + - name: v1 served: true storage: true + - name: v1beta1 + served: true + storage: false status: acceptedNames: kind: "" diff --git a/config/crds/bases/kibana.k8s.elastic.co_kibanas.yaml b/config/crds/bases/kibana.k8s.elastic.co_kibanas.yaml index 13b5df5fa0e..6e842e278e8 100644 --- a/config/crds/bases/kibana.k8s.elastic.co_kibanas.yaml +++ b/config/crds/bases/kibana.k8s.elastic.co_kibanas.yaml @@ -4555,11 +4555,14 @@ spec: type: string type: object type: object - version: v1beta1 + version: v1 versions: - - name: v1beta1 + - name: v1 served: true storage: true + - name: v1beta1 + served: true + storage: false status: acceptedNames: kind: "" diff --git a/config/e2e/global_operator.yaml b/config/e2e/global_operator.yaml index b64427fd6fe..5e681ed7584 100644 --- a/config/e2e/global_operator.yaml +++ b/config/e2e/global_operator.yaml @@ -225,6 +225,25 @@ webhooks: - UPDATE resources: - elasticsearches + - clientConfig: + caBundle: Cg== + service: + name: elastic-webhook-server + namespace: {{ .GlobalOperator.Namespace }} + # this is the path controller-runtime automatically generates + path: /validate-elasticsearch-k8s-elastic-co-v1-elasticsearch + failurePolicy: Ignore + name: elastic-es-validation.k8s.elastic.co + rules: + - apiGroups: + - elasticsearch.k8s.elastic.co + apiVersions: + - v1 + operations: + - CREATE + - UPDATE + resources: + - elasticsearches --- apiVersion: v1 kind: Service diff --git a/config/operator/global/webhook.template.yaml b/config/operator/global/webhook.template.yaml index 7996b3eee38..5f303bb6dee 100644 --- a/config/operator/global/webhook.template.yaml +++ b/config/operator/global/webhook.template.yaml @@ -3,6 +3,25 @@ kind: ValidatingWebhookConfiguration metadata: name: elastic-webhook.k8s.elastic.co webhooks: + - clientConfig: + caBundle: Cg== + service: + name: elastic-webhook-server + namespace: + # this is the path controller-runtime automatically generates + path: /validate-elasticsearch-k8s-elastic-co-v1-elasticsearch + failurePolicy: Ignore + name: elastic-es-validation.k8s.elastic.co + rules: + - apiGroups: + - elasticsearch.k8s.elastic.co + apiVersions: + - v1 + operations: + - CREATE + - UPDATE + resources: + - elasticsearches - clientConfig: caBundle: Cg== service: diff --git a/config/recipes/beats/1_monitor.yaml b/config/recipes/beats/1_monitor.yaml index 8492765059a..9478133eb70 100644 --- a/config/recipes/beats/1_monitor.yaml +++ b/config/recipes/beats/1_monitor.yaml @@ -1,5 +1,5 @@ # This sample sets up an Elasticsearch cluster and a Kibana instance preconfigured for that cluster -apiVersion: elasticsearch.k8s.elastic.co/v1beta1 +apiVersion: elasticsearch.k8s.elastic.co/v1 kind: Elasticsearch metadata: name: monitor @@ -24,7 +24,7 @@ spec: requests: storage: 50Gi --- -apiVersion: kibana.k8s.elastic.co/v1beta1 +apiVersion: kibana.k8s.elastic.co/v1 kind: Kibana metadata: name: monitor diff --git a/config/samples/apm/apm_es_kibana.yaml b/config/samples/apm/apm_es_kibana.yaml index 613690546c6..1deb956f1ca 100644 --- a/config/samples/apm/apm_es_kibana.yaml +++ b/config/samples/apm/apm_es_kibana.yaml @@ -1,6 +1,6 @@ # This sample sets up a an Elasticsearch cluster along with a Kibana instance # and an APM server, configured to be able to communicate with each other -apiVersion: elasticsearch.k8s.elastic.co/v1beta1 +apiVersion: elasticsearch.k8s.elastic.co/v1 kind: Elasticsearch metadata: name: es-apm-sample @@ -14,7 +14,7 @@ spec: # See: https://www.elastic.co/guide/en/cloud-on-k8s/master/k8s-virtual-memory.html node.store.allow_mmap: false --- -apiVersion: apm.k8s.elastic.co/v1beta1 +apiVersion: apm.k8s.elastic.co/v1 kind: ApmServer metadata: name: apm-apm-sample @@ -24,7 +24,7 @@ spec: elasticsearchRef: name: "es-apm-sample" --- -apiVersion: kibana.k8s.elastic.co/v1beta1 +apiVersion: kibana.k8s.elastic.co/v1 kind: Kibana metadata: name: kb-apm-sample diff --git a/config/samples/apm/apmserver.yaml b/config/samples/apm/apmserver.yaml index 0ca72fe7766..b0f2ea78091 100644 --- a/config/samples/apm/apmserver.yaml +++ b/config/samples/apm/apmserver.yaml @@ -1,4 +1,4 @@ -apiVersion: apm.k8s.elastic.co/v1beta1 +apiVersion: apm.k8s.elastic.co/v1 kind: ApmServer metadata: name: apmserver-sample diff --git a/config/samples/elasticsearch/elasticsearch.yaml b/config/samples/elasticsearch/elasticsearch.yaml index 681118081ed..27e3717e95a 100644 --- a/config/samples/elasticsearch/elasticsearch.yaml +++ b/config/samples/elasticsearch/elasticsearch.yaml @@ -1,5 +1,5 @@ # This sample sets up an Elasticsearch cluster with 3 nodes. -apiVersion: elasticsearch.k8s.elastic.co/v1beta1 +apiVersion: elasticsearch.k8s.elastic.co/v1 kind: Elasticsearch metadata: name: elasticsearch-sample diff --git a/config/samples/kibana/kibana_es.yaml b/config/samples/kibana/kibana_es.yaml index 893b3b837ef..758efa85c3c 100644 --- a/config/samples/kibana/kibana_es.yaml +++ b/config/samples/kibana/kibana_es.yaml @@ -1,5 +1,5 @@ # This sample sets up an Elasticsearch cluster and a Kibana instance preconfigured for that cluster -apiVersion: elasticsearch.k8s.elastic.co/v1beta1 +apiVersion: elasticsearch.k8s.elastic.co/v1 kind: Elasticsearch metadata: name: elasticsearch-sample @@ -13,7 +13,7 @@ spec: # See: https://www.elastic.co/guide/en/cloud-on-k8s/master/k8s-virtual-memory.html node.store.allow_mmap: false --- -apiVersion: kibana.k8s.elastic.co/v1beta1 +apiVersion: kibana.k8s.elastic.co/v1 kind: Kibana metadata: name: kibana-sample diff --git a/config/webhook/manifests.yaml b/config/webhook/manifests.yaml index 64c1765a4ff..938121ddde4 100644 --- a/config/webhook/manifests.yaml +++ b/config/webhook/manifests.yaml @@ -11,7 +11,25 @@ webhooks: service: name: webhook-service namespace: system - path: /validate-elasticsearch + path: /validate-elasticsearch-k8s-elastic-co-v1-elasticsearch + failurePolicy: Ignore + name: elastic-es-validation.k8s.elastic.co + rules: + - apiGroups: + - elasticsearch.k8s.elastic.co + apiVersions: + - v1 + operations: + - CREATE + - UPDATE + resources: + - elasticsearches +- clientConfig: + caBundle: Cg== + service: + name: webhook-service + namespace: system + path: /validate-elasticsearch-k8s-elastic-co-v1beta1-elasticsearch failurePolicy: Ignore name: elastic-es-validation.k8s.elastic.co rules: diff --git a/docs/api-docs.asciidoc b/docs/api-docs.asciidoc index 9b96067ce83..3353ee1a0b3 100644 --- a/docs/api-docs.asciidoc +++ b/docs/api-docs.asciidoc @@ -3,14 +3,124 @@ == API Reference .Packages +* xref:{p}-apm-k8s-elastic-co-v1[apm.k8s.elastic.co/v1] * xref:{p}-apm-k8s-elastic-co-v1beta1[apm.k8s.elastic.co/v1beta1] +* xref:{p}-common-k8s-elastic-co-v1[common.k8s.elastic.co/v1] * xref:{p}-common-k8s-elastic-co-v1beta1[common.k8s.elastic.co/v1beta1] +* xref:{p}-elasticsearch-k8s-elastic-co-v1[elasticsearch.k8s.elastic.co/v1] * xref:{p}-elasticsearch-k8s-elastic-co-v1beta1[elasticsearch.k8s.elastic.co/v1beta1] +* xref:{p}-kibana-k8s-elastic-co-v1[kibana.k8s.elastic.co/v1] * xref:{p}-kibana-k8s-elastic-co-v1beta1[kibana.k8s.elastic.co/v1beta1] ''' +[id="{p}-apm-k8s-elastic-co-v1"] +=== apm.k8s.elastic.co/v1 +Package v1 contains API schema definitions for managing APM Server resources. + +.Resource Types +-- +- xref:apm-k8s-elastic-co-v1-apmserver[$$ApmServer$$] +-- + +[id="apm-k8s-elastic-co-v1-apmserver"] +[float] +==== ApmServer + +ApmServer represents an APM Server resource in a Kubernetes cluster. + + + +[cols="20a,80a", options="header"] +|=== +|Field |Description +| *`apiVersion`* + +_string_ +| `apm.k8s.elastic.co/v1` + +| *`kind`* + +_string_ +| `ApmServer` + +| *`metadata`* + +_link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#objectmeta-v1-meta[$$Kubernetes meta/v1.ObjectMeta$$]_ +| +--- +Refer to the Kubernetes API documentation for the fields of the `metadata` field. +| *`spec`* + +_xref:apm-k8s-elastic-co-v1-apmserverspec[$$ApmServerSpec$$]_ +| +--- + +*`version`* _string_:: +Version of the APM Server. +*`image`* _string_:: +Image is the APM Server Docker image to deploy. +*`count`* _int32_:: +Count of APM Server instances to deploy. +*`config`* _xref:common-k8s-elastic-co-v1-config[$$Config$$]_:: +Config holds the APM Server configuration. See: https://www.elastic.co/guide/en/apm/server/current/configuring-howto-apm-server.html +*`http`* _xref:common-k8s-elastic-co-v1-httpconfig[$$HTTPConfig$$]_:: +HTTP holds the HTTP layer configuration for the APM Server resource. +*`elasticsearchRef`* _xref:common-k8s-elastic-co-v1-objectselector[$$ObjectSelector$$]_:: +ElasticsearchRef is a reference to the output Elasticsearch cluster running in the same Kubernetes cluster. +*`podTemplate`* _link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#podtemplatespec-v1-core[$$Kubernetes core/v1.PodTemplateSpec$$]_:: +PodTemplate provides customisation options (labels, annotations, affinity rules, resource requests, and so on) for the APM Server pods. +*`secureSettings`* _xref:common-k8s-elastic-co-v1-secretsource[$$[]SecretSource$$]_:: +SecureSettings is a list of references to Kubernetes secrets containing sensitive configuration options for APM Server. +See: https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-apm-server.html#k8s-apm-secure-settings +|=== + +[id="apm-k8s-elastic-co-v1-apmserverspec"] +[float] +==== ApmServerSpec + +ApmServerSpec holds the specification of an APM Server. + + +.Appears in: +**** +- xref:apm-k8s-elastic-co-v1-apmserver[$$ApmServer$$] +**** +[cols="20a,80a", options="header"] +|=== +|Field |Description + +| *`version`* + +_string_ +| +Version of the APM Server. +| *`image`* + +_string_ +| +Image is the APM Server Docker image to deploy. +| *`count`* + +_int32_ +| +Count of APM Server instances to deploy. +| *`config`* + +_xref:common-k8s-elastic-co-v1-config[$$Config$$]_ +| +Config holds the APM Server configuration. See: https://www.elastic.co/guide/en/apm/server/current/configuring-howto-apm-server.html +| *`http`* + +_xref:common-k8s-elastic-co-v1-httpconfig[$$HTTPConfig$$]_ +| +HTTP holds the HTTP layer configuration for the APM Server resource. +| *`elasticsearchRef`* + +_xref:common-k8s-elastic-co-v1-objectselector[$$ObjectSelector$$]_ +| +ElasticsearchRef is a reference to the output Elasticsearch cluster running in the same Kubernetes cluster. +| *`podTemplate`* + +_link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#podtemplatespec-v1-core[$$Kubernetes core/v1.PodTemplateSpec$$]_ +| +PodTemplate provides customisation options (labels, annotations, affinity rules, resource requests, and so on) for the APM Server pods. +| *`secureSettings`* + +_xref:common-k8s-elastic-co-v1-secretsource[$$[]SecretSource$$]_ +| +SecureSettings is a list of references to Kubernetes secrets containing sensitive configuration options for APM Server. +See: https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-apm-server.html#k8s-apm-secure-settings +|=== [id="{p}-apm-k8s-elastic-co-v1beta1"] === apm.k8s.elastic.co/v1beta1 Package v1beta1 contains API schema definitions for managing APM Server resources. @@ -117,15 +227,15 @@ _xref:common-k8s-elastic-co-v1beta1-secretsource[$$[]SecretSource$$]_ SecureSettings is a list of references to Kubernetes secrets containing sensitive configuration options for APM Server. See: https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-apm-server.html#k8s-apm-secure-settings |=== -[id="{p}-common-k8s-elastic-co-v1beta1"] -=== common.k8s.elastic.co/v1beta1 -Package v1beta1 contains API schema definitions for common types used by all resources. +[id="{p}-common-k8s-elastic-co-v1"] +=== common.k8s.elastic.co/v1 +Package v1 contains API schema definitions for common types used by all resources. .Resource Types -- -- -[id="common-k8s-elastic-co-v1beta1-config"] +[id="common-k8s-elastic-co-v1-config"] [float] ==== Config @@ -134,9 +244,9 @@ Config represents untyped YAML configuration. .Appears in: **** -- xref:apm-k8s-elastic-co-v1beta1-apmserverspec[$$ApmServerSpec$$], -- xref:kibana-k8s-elastic-co-v1beta1-kibanaspec[$$KibanaSpec$$], -- xref:elasticsearch-k8s-elastic-co-v1beta1-nodeset[$$NodeSet$$] +- xref:apm-k8s-elastic-co-v1-apmserverspec[$$ApmServerSpec$$], +- xref:kibana-k8s-elastic-co-v1-kibanaspec[$$KibanaSpec$$], +- xref:elasticsearch-k8s-elastic-co-v1-nodeset[$$NodeSet$$] **** [cols="20a,80a", options="header"] |=== @@ -149,7 +259,7 @@ Data holds the configuration keys and values. This field exists to work around https://github.com/kubernetes-sigs/kubebuilder/issues/528 |=== -[id="common-k8s-elastic-co-v1beta1-httpconfig"] +[id="common-k8s-elastic-co-v1-httpconfig"] [float] ==== HTTPConfig @@ -158,25 +268,25 @@ HTTPConfig holds the HTTP layer configuration for resources. .Appears in: **** -- xref:apm-k8s-elastic-co-v1beta1-apmserverspec[$$ApmServerSpec$$], -- xref:elasticsearch-k8s-elastic-co-v1beta1-elasticsearchspec[$$ElasticsearchSpec$$], -- xref:kibana-k8s-elastic-co-v1beta1-kibanaspec[$$KibanaSpec$$] +- xref:apm-k8s-elastic-co-v1-apmserverspec[$$ApmServerSpec$$], +- xref:elasticsearch-k8s-elastic-co-v1-elasticsearchspec[$$ElasticsearchSpec$$], +- xref:kibana-k8s-elastic-co-v1-kibanaspec[$$KibanaSpec$$] **** [cols="20a,80a", options="header"] |=== |Field |Description | *`service`* + -_xref:common-k8s-elastic-co-v1beta1-servicetemplate[$$ServiceTemplate$$]_ +_xref:common-k8s-elastic-co-v1-servicetemplate[$$ServiceTemplate$$]_ | Service defines the template for the associated Kubernetes Service object. | *`tls`* + -_xref:common-k8s-elastic-co-v1beta1-tlsoptions[$$TLSOptions$$]_ +_xref:common-k8s-elastic-co-v1-tlsoptions[$$TLSOptions$$]_ | TLS defines options for configuring TLS for HTTP. |=== -[id="common-k8s-elastic-co-v1beta1-keytopath"] +[id="common-k8s-elastic-co-v1-keytopath"] [float] ==== KeyToPath @@ -185,7 +295,7 @@ KeyToPath defines how to map a key in a Secret object to a filesystem path. .Appears in: **** -- xref:common-k8s-elastic-co-v1beta1-secretsource[$$SecretSource$$] +- xref:common-k8s-elastic-co-v1-secretsource[$$SecretSource$$] **** [cols="20a,80a", options="header"] |=== @@ -202,7 +312,7 @@ Path is the relative file path to map the key to. Path must not be an absolute file path and must not contain any ".." components. |=== -[id="common-k8s-elastic-co-v1beta1-objectselector"] +[id="common-k8s-elastic-co-v1-objectselector"] [float] ==== ObjectSelector @@ -211,8 +321,8 @@ ObjectSelector defines a reference to a Kubernetes object. .Appears in: **** -- xref:apm-k8s-elastic-co-v1beta1-apmserverspec[$$ApmServerSpec$$], -- xref:kibana-k8s-elastic-co-v1beta1-kibanaspec[$$KibanaSpec$$] +- xref:apm-k8s-elastic-co-v1-apmserverspec[$$ApmServerSpec$$], +- xref:kibana-k8s-elastic-co-v1-kibanaspec[$$KibanaSpec$$] **** [cols="20a,80a", options="header"] |=== @@ -228,7 +338,7 @@ _string_ Namespace of the Kubernetes object. If empty, defaults to the current namespace. |=== -[id="common-k8s-elastic-co-v1beta1-poddisruptionbudgettemplate"] +[id="common-k8s-elastic-co-v1-poddisruptionbudgettemplate"] [float] ==== PodDisruptionBudgetTemplate @@ -237,7 +347,7 @@ PodDisruptionBudgetTemplate defines the template for creating a PodDisruptionBud .Appears in: **** -- xref:elasticsearch-k8s-elastic-co-v1beta1-elasticsearchspec[$$ElasticsearchSpec$$] +- xref:elasticsearch-k8s-elastic-co-v1-elasticsearchspec[$$ElasticsearchSpec$$] **** [cols="20a,80a", options="header"] |=== @@ -272,7 +382,7 @@ the evicted pod. For example, one can prevent all voluntary evictions by specifying 0. This is a mutually exclusive setting with "minAvailable". |=== -[id="common-k8s-elastic-co-v1beta1-secretref"] +[id="common-k8s-elastic-co-v1-secretref"] [float] ==== SecretRef @@ -281,7 +391,7 @@ SecretRef is a reference to a secret that exists in the same namespace. .Appears in: **** -- xref:common-k8s-elastic-co-v1beta1-tlsoptions[$$TLSOptions$$] +- xref:common-k8s-elastic-co-v1-tlsoptions[$$TLSOptions$$] **** [cols="20a,80a", options="header"] |=== @@ -293,7 +403,7 @@ _string_ SecretName is the name of the secret. |=== -[id="common-k8s-elastic-co-v1beta1-secretsource"] +[id="common-k8s-elastic-co-v1-secretsource"] [float] ==== SecretSource @@ -302,9 +412,9 @@ SecretSource defines a data source based on a Kubernetes Secret. .Appears in: **** -- xref:apm-k8s-elastic-co-v1beta1-apmserverspec[$$ApmServerSpec$$], -- xref:elasticsearch-k8s-elastic-co-v1beta1-elasticsearchspec[$$ElasticsearchSpec$$], -- xref:kibana-k8s-elastic-co-v1beta1-kibanaspec[$$KibanaSpec$$] +- xref:apm-k8s-elastic-co-v1-apmserverspec[$$ApmServerSpec$$], +- xref:elasticsearch-k8s-elastic-co-v1-elasticsearchspec[$$ElasticsearchSpec$$], +- xref:kibana-k8s-elastic-co-v1-kibanaspec[$$KibanaSpec$$] **** [cols="20a,80a", options="header"] |=== @@ -315,14 +425,14 @@ _string_ | SecretName is the name of the secret. | *`entries`* + -_xref:common-k8s-elastic-co-v1beta1-keytopath[$$[]KeyToPath$$]_ +_xref:common-k8s-elastic-co-v1-keytopath[$$[]KeyToPath$$]_ | Entries define how to project each key-value pair in the secret to filesystem paths. If not defined, all keys will be projected to similarly named paths in the filesystem. If defined, only the specified keys will be projected to the corresponding paths. |=== -[id="common-k8s-elastic-co-v1beta1-selfsignedcertificate"] +[id="common-k8s-elastic-co-v1-selfsignedcertificate"] [float] ==== SelfSignedCertificate @@ -331,14 +441,14 @@ SelfSignedCertificate holds configuration for the self-signed certificate genera .Appears in: **** -- xref:common-k8s-elastic-co-v1beta1-tlsoptions[$$TLSOptions$$] +- xref:common-k8s-elastic-co-v1-tlsoptions[$$TLSOptions$$] **** [cols="20a,80a", options="header"] |=== |Field |Description | *`subjectAltNames`* + -_xref:common-k8s-elastic-co-v1beta1-subjectalternativename[$$[]SubjectAlternativeName$$]_ +_xref:common-k8s-elastic-co-v1-subjectalternativename[$$[]SubjectAlternativeName$$]_ | SubjectAlternativeNames is a list of SANs to include in the generated HTTP TLS certificate. | *`disabled`* + @@ -347,7 +457,7 @@ _bool_ Disabled indicates that the provisioning of the self-signed certifcate should be disabled. |=== -[id="common-k8s-elastic-co-v1beta1-servicetemplate"] +[id="common-k8s-elastic-co-v1-servicetemplate"] [float] ==== ServiceTemplate @@ -356,7 +466,7 @@ ServiceTemplate defines the template for a Kubernetes Service. .Appears in: **** -- xref:common-k8s-elastic-co-v1beta1-httpconfig[$$HTTPConfig$$] +- xref:common-k8s-elastic-co-v1-httpconfig[$$HTTPConfig$$] **** [cols="20a,80a", options="header"] |=== @@ -472,7 +582,7 @@ _(Optional)_ sessionAffinityConfig contains the configurations of session affinity. |=== -[id="common-k8s-elastic-co-v1beta1-subjectalternativename"] +[id="common-k8s-elastic-co-v1-subjectalternativename"] [float] ==== SubjectAlternativeName @@ -481,7 +591,7 @@ SubjectAlternativeName represents a SAN entry in a x509 certificate. .Appears in: **** -- xref:common-k8s-elastic-co-v1beta1-selfsignedcertificate[$$SelfSignedCertificate$$] +- xref:common-k8s-elastic-co-v1-selfsignedcertificate[$$SelfSignedCertificate$$] **** [cols="20a,80a", options="header"] |=== @@ -497,7 +607,7 @@ _string_ IP is the IP address of the subject. |=== -[id="common-k8s-elastic-co-v1beta1-tlsoptions"] +[id="common-k8s-elastic-co-v1-tlsoptions"] [float] ==== TLSOptions @@ -506,18 +616,18 @@ TLSOptions holds TLS configuration options. .Appears in: **** -- xref:common-k8s-elastic-co-v1beta1-httpconfig[$$HTTPConfig$$] +- xref:common-k8s-elastic-co-v1-httpconfig[$$HTTPConfig$$] **** [cols="20a,80a", options="header"] |=== |Field |Description | *`selfSignedCertificate`* + -_xref:common-k8s-elastic-co-v1beta1-selfsignedcertificate[$$SelfSignedCertificate$$]_ +_xref:common-k8s-elastic-co-v1-selfsignedcertificate[$$SelfSignedCertificate$$]_ | SelfSignedCertificate allows configuring the self-signed certificate generated by the operator. | *`certificate`* + -_xref:common-k8s-elastic-co-v1beta1-secretref[$$SecretRef$$]_ +_xref:common-k8s-elastic-co-v1-secretref[$$SecretRef$$]_ | Certificate is a reference to a Kubernetes secret that contains the certificate and private key for enabling TLS. The referenced secret should contain the following: @@ -526,145 +636,750 @@ The referenced secret should contain the following: - `tls.crt`: The certificate (or a chain). - `tls.key`: The private key to the first certificate in the certificate chain. |=== -[id="{p}-elasticsearch-k8s-elastic-co-v1beta1"] -=== elasticsearch.k8s.elastic.co/v1beta1 -Package v1beta1 contains API schema definitions for managing Elasticsearch resources. +[id="{p}-common-k8s-elastic-co-v1beta1"] +=== common.k8s.elastic.co/v1beta1 +Package v1beta1 contains API schema definitions for common types used by all resources. .Resource Types -- -- xref:elasticsearch-k8s-elastic-co-v1beta1-elasticsearch[$$Elasticsearch$$] -- -[id="elasticsearch-k8s-elastic-co-v1beta1-elasticsearch"] +[id="common-k8s-elastic-co-v1beta1-config"] [float] -==== Elasticsearch - -Elasticsearch represents an Elasticsearch resource in a Kubernetes cluster. +==== Config +Config represents untyped YAML configuration. +.Appears in: +**** +- xref:apm-k8s-elastic-co-v1beta1-apmserverspec[$$ApmServerSpec$$], +- xref:kibana-k8s-elastic-co-v1beta1-kibanaspec[$$KibanaSpec$$], +- xref:elasticsearch-k8s-elastic-co-v1beta1-nodeset[$$NodeSet$$] +**** [cols="20a,80a", options="header"] |=== |Field |Description -| *`apiVersion`* + -_string_ -| `elasticsearch.k8s.elastic.co/v1beta1` - -| *`kind`* + -_string_ -| `Elasticsearch` -| *`metadata`* + -_link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#objectmeta-v1-meta[$$Kubernetes meta/v1.ObjectMeta$$]_ -| ---- -Refer to the Kubernetes API documentation for the fields of the `metadata` field. -| *`spec`* + -_xref:elasticsearch-k8s-elastic-co-v1beta1-elasticsearchspec[$$ElasticsearchSpec$$]_ +| *`Data`* + +_map[string]interface{}_ | ---- - -*`version`* _string_:: -Version of Elasticsearch. -*`image`* _string_:: -Image is the Elasticsearch Docker image to deploy. -*`http`* _xref:common-k8s-elastic-co-v1beta1-httpconfig[$$HTTPConfig$$]_:: -HTTP holds HTTP layer settings for Elasticsearch. -*`nodeSets`* _xref:elasticsearch-k8s-elastic-co-v1beta1-nodeset[$$[]NodeSet$$]_:: -NodeSets allow specifying groups of Elasticsearch nodes sharing the same configuration and Pod templates. -See: https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-orchestration.html -*`updateStrategy`* _xref:elasticsearch-k8s-elastic-co-v1beta1-updatestrategy[$$UpdateStrategy$$]_:: -UpdateStrategy specifies how updates to the cluster should be performed. -*`podDisruptionBudget`* _xref:common-k8s-elastic-co-v1beta1-poddisruptionbudgettemplate[$$PodDisruptionBudgetTemplate$$]_:: -PodDisruptionBudget provides access to the default pod disruption budget for the Elasticsearch cluster. -The default budget selects all cluster pods and sets `maxUnavailable` to 1. To disable, set `PodDisruptionBudget` -to the empty value (`{}` in YAML). -*`secureSettings`* _xref:common-k8s-elastic-co-v1beta1-secretsource[$$[]SecretSource$$]_:: -SecureSettings is a list of references to Kubernetes secrets containing sensitive configuration options for Elasticsearch. -See: https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-es-secure-settings.html +Data holds the configuration keys and values. +This field exists to work around https://github.com/kubernetes-sigs/kubebuilder/issues/528 |=== -[id="elasticsearch-k8s-elastic-co-v1beta1-changebudget"] +[id="common-k8s-elastic-co-v1beta1-httpconfig"] [float] -==== ChangeBudget +==== HTTPConfig -ChangeBudget defines the constraints to consider when applying changes to the Elasticsearch cluster. +HTTPConfig holds the HTTP layer configuration for resources. .Appears in: **** -- xref:elasticsearch-k8s-elastic-co-v1beta1-updatestrategy[$$UpdateStrategy$$] +- xref:apm-k8s-elastic-co-v1beta1-apmserverspec[$$ApmServerSpec$$], +- xref:elasticsearch-k8s-elastic-co-v1beta1-elasticsearchspec[$$ElasticsearchSpec$$], +- xref:kibana-k8s-elastic-co-v1beta1-kibanaspec[$$KibanaSpec$$] **** [cols="20a,80a", options="header"] |=== |Field |Description -| *`maxUnavailable`* + -_int32_ +| *`service`* + +_xref:common-k8s-elastic-co-v1beta1-servicetemplate[$$ServiceTemplate$$]_ | -MaxUnavailable is the maximum number of pods that can be unavailable (not ready) during the update due to -circumstances under the control of the operator. Setting a negative value will disable this restriction. -Defaults to 1 if not specified. -| *`maxSurge`* + -_int32_ +Service defines the template for the associated Kubernetes Service object. +| *`tls`* + +_xref:common-k8s-elastic-co-v1beta1-tlsoptions[$$TLSOptions$$]_ | -MaxSurge is the maximum number of new pods that can be created exceeding the original number of pods defined in -the specification. MaxSurge is only taken into consideration when scaling up. Setting a negative value will -disable the restriction. Defaults to unbounded if not specified. +TLS defines options for configuring TLS for HTTP. |=== -[id="elasticsearch-k8s-elastic-co-v1beta1-elasticsearchspec"] +[id="common-k8s-elastic-co-v1beta1-keytopath"] [float] -==== ElasticsearchSpec +==== KeyToPath -ElasticsearchSpec holds the specification of an Elasticsearch cluster. +KeyToPath defines how to map a key in a Secret object to a filesystem path. .Appears in: **** -- xref:elasticsearch-k8s-elastic-co-v1beta1-elasticsearch[$$Elasticsearch$$] +- xref:common-k8s-elastic-co-v1beta1-secretsource[$$SecretSource$$] **** [cols="20a,80a", options="header"] |=== |Field |Description -| *`version`* + +| *`key`* + _string_ | -Version of Elasticsearch. -| *`image`* + +Key is the key contained in the secret. +| *`path`* + _string_ | -Image is the Elasticsearch Docker image to deploy. -| *`http`* + -_xref:common-k8s-elastic-co-v1beta1-httpconfig[$$HTTPConfig$$]_ -| -HTTP holds HTTP layer settings for Elasticsearch. -| *`nodeSets`* + -_xref:elasticsearch-k8s-elastic-co-v1beta1-nodeset[$$[]NodeSet$$]_ -| -NodeSets allow specifying groups of Elasticsearch nodes sharing the same configuration and Pod templates. -See: https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-orchestration.html -| *`updateStrategy`* + -_xref:elasticsearch-k8s-elastic-co-v1beta1-updatestrategy[$$UpdateStrategy$$]_ -| -UpdateStrategy specifies how updates to the cluster should be performed. -| *`podDisruptionBudget`* + -_xref:common-k8s-elastic-co-v1beta1-poddisruptionbudgettemplate[$$PodDisruptionBudgetTemplate$$]_ -| -PodDisruptionBudget provides access to the default pod disruption budget for the Elasticsearch cluster. -The default budget selects all cluster pods and sets `maxUnavailable` to 1. To disable, set `PodDisruptionBudget` -to the empty value (`{}` in YAML). -| *`secureSettings`* + -_xref:common-k8s-elastic-co-v1beta1-secretsource[$$[]SecretSource$$]_ -| -SecureSettings is a list of references to Kubernetes secrets containing sensitive configuration options for Elasticsearch. -See: https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-es-secure-settings.html +Path is the relative file path to map the key to. +Path must not be an absolute file path and must not contain any ".." components. |=== -[id="elasticsearch-k8s-elastic-co-v1beta1-nodeset"] +[id="common-k8s-elastic-co-v1beta1-objectselector"] [float] -==== NodeSet +==== ObjectSelector + +ObjectSelector defines a reference to a Kubernetes object. + + +.Appears in: +**** +- xref:apm-k8s-elastic-co-v1beta1-apmserverspec[$$ApmServerSpec$$], +- xref:kibana-k8s-elastic-co-v1beta1-kibanaspec[$$KibanaSpec$$] +**** +[cols="20a,80a", options="header"] +|=== +|Field |Description + +| *`name`* + +_string_ +| +Name of the Kubernetes object. +| *`namespace`* + +_string_ +| +Namespace of the Kubernetes object. If empty, defaults to the current namespace. +|=== + +[id="common-k8s-elastic-co-v1beta1-poddisruptionbudgettemplate"] +[float] +==== PodDisruptionBudgetTemplate + +PodDisruptionBudgetTemplate defines the template for creating a PodDisruptionBudget. + + +.Appears in: +**** +- xref:elasticsearch-k8s-elastic-co-v1beta1-elasticsearchspec[$$ElasticsearchSpec$$] +**** +[cols="20a,80a", options="header"] +|=== +|Field |Description + +| *`metadata`* + +_link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#objectmeta-v1-meta[$$Kubernetes meta/v1.ObjectMeta$$]_ +| +ObjectMeta is the metadata of the PDB. +The name and namespace provided here are managed by ECK and will be ignored. +Refer to the Kubernetes API documentation for the fields of the `metadata` field. +| *`spec`* + +_link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#poddisruptionbudgetspec-v1beta1-policy[$$Kubernetes policy/v1beta1.PodDisruptionBudgetSpec$$]_ +| +Spec is the specification of the PDB. + +*`minAvailable`* _Kubernetes intstr.IntOrString_:: +_(Optional)_ +An eviction is allowed if at least "minAvailable" pods selected by +"selector" will still be available after the eviction, i.e. even in the +absence of the evicted pod. So for example you can prevent all voluntary +evictions by specifying "100%". +*`selector`* _link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#labelselector-v1-meta[$$Kubernetes meta/v1.LabelSelector$$]_:: +_(Optional)_ +Label query over pods whose evictions are managed by the disruption +budget. +*`maxUnavailable`* _Kubernetes intstr.IntOrString_:: +_(Optional)_ +An eviction is allowed if at most "maxUnavailable" pods selected by +"selector" are unavailable after the eviction, i.e. even in absence of +the evicted pod. For example, one can prevent all voluntary evictions +by specifying 0. This is a mutually exclusive setting with "minAvailable". +|=== + +[id="common-k8s-elastic-co-v1beta1-secretref"] +[float] +==== SecretRef + +SecretRef is a reference to a secret that exists in the same namespace. + + +.Appears in: +**** +- xref:common-k8s-elastic-co-v1beta1-tlsoptions[$$TLSOptions$$] +**** +[cols="20a,80a", options="header"] +|=== +|Field |Description + +| *`secretName`* + +_string_ +| +SecretName is the name of the secret. +|=== + +[id="common-k8s-elastic-co-v1beta1-secretsource"] +[float] +==== SecretSource + +SecretSource defines a data source based on a Kubernetes Secret. + + +.Appears in: +**** +- xref:apm-k8s-elastic-co-v1beta1-apmserverspec[$$ApmServerSpec$$], +- xref:elasticsearch-k8s-elastic-co-v1beta1-elasticsearchspec[$$ElasticsearchSpec$$], +- xref:kibana-k8s-elastic-co-v1beta1-kibanaspec[$$KibanaSpec$$] +**** +[cols="20a,80a", options="header"] +|=== +|Field |Description + +| *`secretName`* + +_string_ +| +SecretName is the name of the secret. +| *`entries`* + +_xref:common-k8s-elastic-co-v1beta1-keytopath[$$[]KeyToPath$$]_ +| +Entries define how to project each key-value pair in the secret to filesystem paths. +If not defined, all keys will be projected to similarly named paths in the filesystem. +If defined, only the specified keys will be projected to the corresponding paths. +|=== + +[id="common-k8s-elastic-co-v1beta1-selfsignedcertificate"] +[float] +==== SelfSignedCertificate + +SelfSignedCertificate holds configuration for the self-signed certificate generated by the operator. + + +.Appears in: +**** +- xref:common-k8s-elastic-co-v1beta1-tlsoptions[$$TLSOptions$$] +**** +[cols="20a,80a", options="header"] +|=== +|Field |Description + +| *`subjectAltNames`* + +_xref:common-k8s-elastic-co-v1beta1-subjectalternativename[$$[]SubjectAlternativeName$$]_ +| +SubjectAlternativeNames is a list of SANs to include in the generated HTTP TLS certificate. +| *`disabled`* + +_bool_ +| +Disabled indicates that the provisioning of the self-signed certifcate should be disabled. +|=== + +[id="common-k8s-elastic-co-v1beta1-servicetemplate"] +[float] +==== ServiceTemplate + +ServiceTemplate defines the template for a Kubernetes Service. + + +.Appears in: +**** +- xref:common-k8s-elastic-co-v1beta1-httpconfig[$$HTTPConfig$$] +**** +[cols="20a,80a", options="header"] +|=== +|Field |Description + +| *`metadata`* + +_link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#objectmeta-v1-meta[$$Kubernetes meta/v1.ObjectMeta$$]_ +| +ObjectMeta is the metadata of the service. +The name and namespace provided here are managed by ECK and will be ignored. +Refer to the Kubernetes API documentation for the fields of the `metadata` field. +| *`spec`* + +_link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#servicespec-v1-core[$$Kubernetes core/v1.ServiceSpec$$]_ +| +Spec is the specification of the service. + +*`ports`* _link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#serviceport-v1-core[$$[]Kubernetes core/v1.ServicePort$$]_:: +The list of ports that are exposed by this service. +More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies +*`selector`* _map[string]string_:: +_(Optional)_ +Route service traffic to pods with label keys and values matching this +selector. If empty or not present, the service is assumed to have an +external process managing its endpoints, which Kubernetes will not +modify. Only applies to types ClusterIP, NodePort, and LoadBalancer. +Ignored if type is ExternalName. +More info: https://kubernetes.io/docs/concepts/services-networking/service/ +*`clusterIP`* _string_:: +_(Optional)_ +clusterIP is the IP address of the service and is usually assigned +randomly by the master. If an address is specified manually and is not in +use by others, it will be allocated to the service; otherwise, creation +of the service will fail. This field can not be changed through updates. +Valid values are "None", empty string (""), or a valid IP address. "None" +can be specified for headless services when proxying is not required. +Only applies to types ClusterIP, NodePort, and LoadBalancer. Ignored if +type is ExternalName. +More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies +*`type`* _link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#servicetype-v1-core[$$Kubernetes core/v1.ServiceType$$]_:: +_(Optional)_ +type determines how the Service is exposed. Defaults to ClusterIP. Valid +options are ExternalName, ClusterIP, NodePort, and LoadBalancer. +"ExternalName" maps to the specified externalName. +"ClusterIP" allocates a cluster-internal IP address for load-balancing to +endpoints. Endpoints are determined by the selector or if that is not +specified, by manual construction of an Endpoints object. If clusterIP is +"None", no virtual IP is allocated and the endpoints are published as a +set of endpoints rather than a stable IP. +"NodePort" builds on ClusterIP and allocates a port on every node which +routes to the clusterIP. +"LoadBalancer" builds on NodePort and creates an +external load-balancer (if supported in the current cloud) which routes +to the clusterIP. +More info: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types +*`externalIPs`* _[]string_:: +_(Optional)_ +externalIPs is a list of IP addresses for which nodes in the cluster +will also accept traffic for this service. These IPs are not managed by +Kubernetes. The user is responsible for ensuring that traffic arrives +at a node with this IP. A common example is external load-balancers +that are not part of the Kubernetes system. +*`sessionAffinity`* _link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#serviceaffinity-v1-core[$$Kubernetes core/v1.ServiceAffinity$$]_:: +_(Optional)_ +Supports "ClientIP" and "None". Used to maintain session affinity. +Enable client IP based session affinity. +Must be ClientIP or None. +Defaults to None. +More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies +*`loadBalancerIP`* _string_:: +_(Optional)_ +Only applies to Service Type: LoadBalancer +LoadBalancer will get created with the IP specified in this field. +This feature depends on whether the underlying cloud-provider supports specifying +the loadBalancerIP when a load balancer is created. +This field will be ignored if the cloud-provider does not support the feature. +*`loadBalancerSourceRanges`* _[]string_:: +_(Optional)_ +If specified and supported by the platform, this will restrict traffic through the cloud-provider +load-balancer will be restricted to the specified client IPs. This field will be ignored if the +cloud-provider does not support the feature." +More info: https://kubernetes.io/docs/tasks/access-application-cluster/configure-cloud-provider-firewall/ +*`externalName`* _string_:: +_(Optional)_ +externalName is the external reference that kubedns or equivalent will +return as a CNAME record for this service. No proxying will be involved. +Must be a valid RFC-1123 hostname (https://tools.ietf.org/html/rfc1123) +and requires Type to be ExternalName. +*`externalTrafficPolicy`* _link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#serviceexternaltrafficpolicytype-v1-core[$$Kubernetes core/v1.ServiceExternalTrafficPolicyType$$]_:: +_(Optional)_ +externalTrafficPolicy denotes if this Service desires to route external +traffic to node-local or cluster-wide endpoints. "Local" preserves the +client source IP and avoids a second hop for LoadBalancer and Nodeport +type services, but risks potentially imbalanced traffic spreading. +"Cluster" obscures the client source IP and may cause a second hop to +another node, but should have good overall load-spreading. +*`healthCheckNodePort`* _int32_:: +_(Optional)_ +healthCheckNodePort specifies the healthcheck nodePort for the service. +If not specified, HealthCheckNodePort is created by the service api +backend with the allocated nodePort. Will use user-specified nodePort value +if specified by the client. Only effects when Type is set to LoadBalancer +and ExternalTrafficPolicy is set to Local. +*`publishNotReadyAddresses`* _bool_:: +_(Optional)_ +publishNotReadyAddresses, when set to true, indicates that DNS implementations +must publish the notReadyAddresses of subsets for the Endpoints associated with +the Service. The default value is false. +The primary use case for setting this field is to use a StatefulSet's Headless Service +to propagate SRV records for its Pods without respect to their readiness for purpose +of peer discovery. +*`sessionAffinityConfig`* _link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#sessionaffinityconfig-v1-core[$$Kubernetes core/v1.SessionAffinityConfig$$]_:: +_(Optional)_ +sessionAffinityConfig contains the configurations of session affinity. +|=== + +[id="common-k8s-elastic-co-v1beta1-subjectalternativename"] +[float] +==== SubjectAlternativeName + +SubjectAlternativeName represents a SAN entry in a x509 certificate. + + +.Appears in: +**** +- xref:common-k8s-elastic-co-v1beta1-selfsignedcertificate[$$SelfSignedCertificate$$] +**** +[cols="20a,80a", options="header"] +|=== +|Field |Description + +| *`dns`* + +_string_ +| +DNS is the DNS name of the subject. +| *`ip`* + +_string_ +| +IP is the IP address of the subject. +|=== + +[id="common-k8s-elastic-co-v1beta1-tlsoptions"] +[float] +==== TLSOptions + +TLSOptions holds TLS configuration options. + + +.Appears in: +**** +- xref:common-k8s-elastic-co-v1beta1-httpconfig[$$HTTPConfig$$] +**** +[cols="20a,80a", options="header"] +|=== +|Field |Description + +| *`selfSignedCertificate`* + +_xref:common-k8s-elastic-co-v1beta1-selfsignedcertificate[$$SelfSignedCertificate$$]_ +| +SelfSignedCertificate allows configuring the self-signed certificate generated by the operator. +| *`certificate`* + +_xref:common-k8s-elastic-co-v1beta1-secretref[$$SecretRef$$]_ +| +Certificate is a reference to a Kubernetes secret that contains the certificate and private key for enabling TLS. +The referenced secret should contain the following: + +- `ca.crt`: The certificate authority (optional). +- `tls.crt`: The certificate (or a chain). +- `tls.key`: The private key to the first certificate in the certificate chain. +|=== +[id="{p}-elasticsearch-k8s-elastic-co-v1"] +=== elasticsearch.k8s.elastic.co/v1 +Package v1 contains API schema definitions for managing Elasticsearch resources. + +.Resource Types +-- +- xref:elasticsearch-k8s-elastic-co-v1-elasticsearch[$$Elasticsearch$$] +-- + +[id="elasticsearch-k8s-elastic-co-v1-elasticsearch"] +[float] +==== Elasticsearch + +Elasticsearch represents an Elasticsearch resource in a Kubernetes cluster. + + + +[cols="20a,80a", options="header"] +|=== +|Field |Description +| *`apiVersion`* + +_string_ +| `elasticsearch.k8s.elastic.co/v1` + +| *`kind`* + +_string_ +| `Elasticsearch` + +| *`metadata`* + +_link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#objectmeta-v1-meta[$$Kubernetes meta/v1.ObjectMeta$$]_ +| +--- +Refer to the Kubernetes API documentation for the fields of the `metadata` field. +| *`spec`* + +_xref:elasticsearch-k8s-elastic-co-v1-elasticsearchspec[$$ElasticsearchSpec$$]_ +| +--- + +*`version`* _string_:: +Version of Elasticsearch. +*`image`* _string_:: +Image is the Elasticsearch Docker image to deploy. +*`http`* _xref:common-k8s-elastic-co-v1-httpconfig[$$HTTPConfig$$]_:: +HTTP holds HTTP layer settings for Elasticsearch. +*`nodeSets`* _xref:elasticsearch-k8s-elastic-co-v1-nodeset[$$[]NodeSet$$]_:: +NodeSets allow specifying groups of Elasticsearch nodes sharing the same configuration and Pod templates. +See: https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-orchestration.html +*`updateStrategy`* _xref:elasticsearch-k8s-elastic-co-v1-updatestrategy[$$UpdateStrategy$$]_:: +UpdateStrategy specifies how updates to the cluster should be performed. +*`podDisruptionBudget`* _xref:common-k8s-elastic-co-v1-poddisruptionbudgettemplate[$$PodDisruptionBudgetTemplate$$]_:: +PodDisruptionBudget provides access to the default pod disruption budget for the Elasticsearch cluster. +The default budget selects all cluster pods and sets `maxUnavailable` to 1. To disable, set `PodDisruptionBudget` +to the empty value (`{}` in YAML). +*`secureSettings`* _xref:common-k8s-elastic-co-v1-secretsource[$$[]SecretSource$$]_:: +SecureSettings is a list of references to Kubernetes secrets containing sensitive configuration options for Elasticsearch. +See: https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-es-secure-settings.html +|=== + +[id="elasticsearch-k8s-elastic-co-v1-changebudget"] +[float] +==== ChangeBudget + +ChangeBudget defines the constraints to consider when applying changes to the Elasticsearch cluster. + + +.Appears in: +**** +- xref:elasticsearch-k8s-elastic-co-v1-updatestrategy[$$UpdateStrategy$$] +**** +[cols="20a,80a", options="header"] +|=== +|Field |Description + +| *`maxUnavailable`* + +_int32_ +| +MaxUnavailable is the maximum number of pods that can be unavailable (not ready) during the update due to +circumstances under the control of the operator. Setting a negative value will disable this restriction. +Defaults to 1 if not specified. +| *`maxSurge`* + +_int32_ +| +MaxSurge is the maximum number of new pods that can be created exceeding the original number of pods defined in +the specification. MaxSurge is only taken into consideration when scaling up. Setting a negative value will +disable the restriction. Defaults to unbounded if not specified. +|=== + +[id="elasticsearch-k8s-elastic-co-v1-elasticsearchspec"] +[float] +==== ElasticsearchSpec + +ElasticsearchSpec holds the specification of an Elasticsearch cluster. + + +.Appears in: +**** +- xref:elasticsearch-k8s-elastic-co-v1-elasticsearch[$$Elasticsearch$$] +**** +[cols="20a,80a", options="header"] +|=== +|Field |Description + +| *`version`* + +_string_ +| +Version of Elasticsearch. +| *`image`* + +_string_ +| +Image is the Elasticsearch Docker image to deploy. +| *`http`* + +_xref:common-k8s-elastic-co-v1-httpconfig[$$HTTPConfig$$]_ +| +HTTP holds HTTP layer settings for Elasticsearch. +| *`nodeSets`* + +_xref:elasticsearch-k8s-elastic-co-v1-nodeset[$$[]NodeSet$$]_ +| +NodeSets allow specifying groups of Elasticsearch nodes sharing the same configuration and Pod templates. +See: https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-orchestration.html +| *`updateStrategy`* + +_xref:elasticsearch-k8s-elastic-co-v1-updatestrategy[$$UpdateStrategy$$]_ +| +UpdateStrategy specifies how updates to the cluster should be performed. +| *`podDisruptionBudget`* + +_xref:common-k8s-elastic-co-v1-poddisruptionbudgettemplate[$$PodDisruptionBudgetTemplate$$]_ +| +PodDisruptionBudget provides access to the default pod disruption budget for the Elasticsearch cluster. +The default budget selects all cluster pods and sets `maxUnavailable` to 1. To disable, set `PodDisruptionBudget` +to the empty value (`{}` in YAML). +| *`secureSettings`* + +_xref:common-k8s-elastic-co-v1-secretsource[$$[]SecretSource$$]_ +| +SecureSettings is a list of references to Kubernetes secrets containing sensitive configuration options for Elasticsearch. +See: https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-es-secure-settings.html +|=== + +[id="elasticsearch-k8s-elastic-co-v1-nodeset"] +[float] +==== NodeSet + +NodeSet is the specification for a group of Elasticsearch nodes sharing the same configuration and a Pod template. + + +.Appears in: +**** +- xref:elasticsearch-k8s-elastic-co-v1-elasticsearchspec[$$ElasticsearchSpec$$] +**** +[cols="20a,80a", options="header"] +|=== +|Field |Description + +| *`name`* + +_string_ +| +Name of this set of nodes. Becomes a part of the Elasticsearch node.name setting. +| *`config`* + +_xref:common-k8s-elastic-co-v1-config[$$Config$$]_ +| +Config holds the Elasticsearch configuration. +| *`count`* + +_int32_ +| +Count of Elasticsearch nodes to deploy. +| *`podTemplate`* + +_link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#podtemplatespec-v1-core[$$Kubernetes core/v1.PodTemplateSpec$$]_ +| +PodTemplate provides customisation options (labels, annotations, affinity rules, resource requests, and so on) for the Pods belonging to this NodeSet. +| *`volumeClaimTemplates`* + +_link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#persistentvolumeclaim-v1-core[$$[]Kubernetes core/v1.PersistentVolumeClaim$$]_ +| +VolumeClaimTemplates is a list of persistent volume claims to be used by each Pod in this NodeSet. +Every claim in this list must have a matching volumeMount in one of the containers defined in the PodTemplate. +Items defined here take precedence over any default claims added by the operator with the same name. +See: https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-volume-claim-templates.html +|=== + +[id="elasticsearch-k8s-elastic-co-v1-updatestrategy"] +[float] +==== UpdateStrategy + +UpdateStrategy specifies how updates to the cluster should be performed. + + +.Appears in: +**** +- xref:elasticsearch-k8s-elastic-co-v1-elasticsearchspec[$$ElasticsearchSpec$$] +**** +[cols="20a,80a", options="header"] +|=== +|Field |Description + +| *`changeBudget`* + +_xref:elasticsearch-k8s-elastic-co-v1-changebudget[$$ChangeBudget$$]_ +| +ChangeBudget defines the constraints to consider when applying changes to the Elasticsearch cluster. +|=== +[id="{p}-elasticsearch-k8s-elastic-co-v1beta1"] +=== elasticsearch.k8s.elastic.co/v1beta1 +Package v1beta1 contains API schema definitions for managing Elasticsearch resources. + +.Resource Types +-- +- xref:elasticsearch-k8s-elastic-co-v1beta1-elasticsearch[$$Elasticsearch$$] +-- + +[id="elasticsearch-k8s-elastic-co-v1beta1-elasticsearch"] +[float] +==== Elasticsearch + +Elasticsearch represents an Elasticsearch resource in a Kubernetes cluster. + + + +[cols="20a,80a", options="header"] +|=== +|Field |Description +| *`apiVersion`* + +_string_ +| `elasticsearch.k8s.elastic.co/v1beta1` + +| *`kind`* + +_string_ +| `Elasticsearch` + +| *`metadata`* + +_link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#objectmeta-v1-meta[$$Kubernetes meta/v1.ObjectMeta$$]_ +| +--- +Refer to the Kubernetes API documentation for the fields of the `metadata` field. +| *`spec`* + +_xref:elasticsearch-k8s-elastic-co-v1beta1-elasticsearchspec[$$ElasticsearchSpec$$]_ +| +--- + +*`version`* _string_:: +Version of Elasticsearch. +*`image`* _string_:: +Image is the Elasticsearch Docker image to deploy. +*`http`* _xref:common-k8s-elastic-co-v1beta1-httpconfig[$$HTTPConfig$$]_:: +HTTP holds HTTP layer settings for Elasticsearch. +*`nodeSets`* _xref:elasticsearch-k8s-elastic-co-v1beta1-nodeset[$$[]NodeSet$$]_:: +NodeSets allow specifying groups of Elasticsearch nodes sharing the same configuration and Pod templates. +See: https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-orchestration.html +*`updateStrategy`* _xref:elasticsearch-k8s-elastic-co-v1beta1-updatestrategy[$$UpdateStrategy$$]_:: +UpdateStrategy specifies how updates to the cluster should be performed. +*`podDisruptionBudget`* _xref:common-k8s-elastic-co-v1beta1-poddisruptionbudgettemplate[$$PodDisruptionBudgetTemplate$$]_:: +PodDisruptionBudget provides access to the default pod disruption budget for the Elasticsearch cluster. +The default budget selects all cluster pods and sets `maxUnavailable` to 1. To disable, set `PodDisruptionBudget` +to the empty value (`{}` in YAML). +*`secureSettings`* _xref:common-k8s-elastic-co-v1beta1-secretsource[$$[]SecretSource$$]_:: +SecureSettings is a list of references to Kubernetes secrets containing sensitive configuration options for Elasticsearch. +See: https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-es-secure-settings.html +|=== + +[id="elasticsearch-k8s-elastic-co-v1beta1-changebudget"] +[float] +==== ChangeBudget + +ChangeBudget defines the constraints to consider when applying changes to the Elasticsearch cluster. + + +.Appears in: +**** +- xref:elasticsearch-k8s-elastic-co-v1beta1-updatestrategy[$$UpdateStrategy$$] +**** +[cols="20a,80a", options="header"] +|=== +|Field |Description + +| *`maxUnavailable`* + +_int32_ +| +MaxUnavailable is the maximum number of pods that can be unavailable (not ready) during the update due to +circumstances under the control of the operator. Setting a negative value will disable this restriction. +Defaults to 1 if not specified. +| *`maxSurge`* + +_int32_ +| +MaxSurge is the maximum number of new pods that can be created exceeding the original number of pods defined in +the specification. MaxSurge is only taken into consideration when scaling up. Setting a negative value will +disable the restriction. Defaults to unbounded if not specified. +|=== + +[id="elasticsearch-k8s-elastic-co-v1beta1-elasticsearchspec"] +[float] +==== ElasticsearchSpec + +ElasticsearchSpec holds the specification of an Elasticsearch cluster. + + +.Appears in: +**** +- xref:elasticsearch-k8s-elastic-co-v1beta1-elasticsearch[$$Elasticsearch$$] +**** +[cols="20a,80a", options="header"] +|=== +|Field |Description + +| *`version`* + +_string_ +| +Version of Elasticsearch. +| *`image`* + +_string_ +| +Image is the Elasticsearch Docker image to deploy. +| *`http`* + +_xref:common-k8s-elastic-co-v1beta1-httpconfig[$$HTTPConfig$$]_ +| +HTTP holds HTTP layer settings for Elasticsearch. +| *`nodeSets`* + +_xref:elasticsearch-k8s-elastic-co-v1beta1-nodeset[$$[]NodeSet$$]_ +| +NodeSets allow specifying groups of Elasticsearch nodes sharing the same configuration and Pod templates. +See: https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-orchestration.html +| *`updateStrategy`* + +_xref:elasticsearch-k8s-elastic-co-v1beta1-updatestrategy[$$UpdateStrategy$$]_ +| +UpdateStrategy specifies how updates to the cluster should be performed. +| *`podDisruptionBudget`* + +_xref:common-k8s-elastic-co-v1beta1-poddisruptionbudgettemplate[$$PodDisruptionBudgetTemplate$$]_ +| +PodDisruptionBudget provides access to the default pod disruption budget for the Elasticsearch cluster. +The default budget selects all cluster pods and sets `maxUnavailable` to 1. To disable, set `PodDisruptionBudget` +to the empty value (`{}` in YAML). +| *`secureSettings`* + +_xref:common-k8s-elastic-co-v1beta1-secretsource[$$[]SecretSource$$]_ +| +SecureSettings is a list of references to Kubernetes secrets containing sensitive configuration options for Elasticsearch. +See: https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-es-secure-settings.html +|=== + +[id="elasticsearch-k8s-elastic-co-v1beta1-nodeset"] +[float] +==== NodeSet NodeSet is the specification for a group of Elasticsearch nodes sharing the same configuration and a Pod template. @@ -722,6 +1437,112 @@ _xref:elasticsearch-k8s-elastic-co-v1beta1-changebudget[$$ChangeBudget$$]_ | ChangeBudget defines the constraints to consider when applying changes to the Elasticsearch cluster. |=== +[id="{p}-kibana-k8s-elastic-co-v1"] +=== kibana.k8s.elastic.co/v1 +Package v1 contains API schema definitions for managing Kibana resources. + +.Resource Types +-- +- xref:kibana-k8s-elastic-co-v1-kibana[$$Kibana$$] +-- + +[id="kibana-k8s-elastic-co-v1-kibana"] +[float] +==== Kibana + +Kibana represents a Kibana resource in a Kubernetes cluster. + + + +[cols="20a,80a", options="header"] +|=== +|Field |Description +| *`apiVersion`* + +_string_ +| `kibana.k8s.elastic.co/v1` + +| *`kind`* + +_string_ +| `Kibana` + +| *`metadata`* + +_link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#objectmeta-v1-meta[$$Kubernetes meta/v1.ObjectMeta$$]_ +| +--- +Refer to the Kubernetes API documentation for the fields of the `metadata` field. +| *`spec`* + +_xref:kibana-k8s-elastic-co-v1-kibanaspec[$$KibanaSpec$$]_ +| +--- + +*`version`* _string_:: +Version of Kibana. +*`image`* _string_:: +Image is the Kibana Docker image to deploy. +*`count`* _int32_:: +Count of Kibana instances to deploy. +*`elasticsearchRef`* _xref:common-k8s-elastic-co-v1-objectselector[$$ObjectSelector$$]_:: +ElasticsearchRef is a reference to an Elasticsearch cluster running in the same Kubernetes cluster. +*`config`* _xref:common-k8s-elastic-co-v1-config[$$Config$$]_:: +Config holds the Kibana configuration. See: https://www.elastic.co/guide/en/kibana/current/settings.html +*`http`* _xref:common-k8s-elastic-co-v1-httpconfig[$$HTTPConfig$$]_:: +HTTP holds the HTTP layer configuration for Kibana. +*`podTemplate`* _link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#podtemplatespec-v1-core[$$Kubernetes core/v1.PodTemplateSpec$$]_:: +PodTemplate provides customisation options (labels, annotations, affinity rules, resource requests, and so on) for the Kibana pods +*`secureSettings`* _xref:common-k8s-elastic-co-v1-secretsource[$$[]SecretSource$$]_:: +SecureSettings is a list of references to Kubernetes secrets containing sensitive configuration options for Kibana. +See: https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-kibana.html#k8s-kibana-secure-settings +|=== + +[id="kibana-k8s-elastic-co-v1-kibanaspec"] +[float] +==== KibanaSpec + +KibanaSpec holds the specification of a Kibana instance. + + +.Appears in: +**** +- xref:kibana-k8s-elastic-co-v1-kibana[$$Kibana$$] +**** +[cols="20a,80a", options="header"] +|=== +|Field |Description + +| *`version`* + +_string_ +| +Version of Kibana. +| *`image`* + +_string_ +| +Image is the Kibana Docker image to deploy. +| *`count`* + +_int32_ +| +Count of Kibana instances to deploy. +| *`elasticsearchRef`* + +_xref:common-k8s-elastic-co-v1-objectselector[$$ObjectSelector$$]_ +| +ElasticsearchRef is a reference to an Elasticsearch cluster running in the same Kubernetes cluster. +| *`config`* + +_xref:common-k8s-elastic-co-v1-config[$$Config$$]_ +| +Config holds the Kibana configuration. See: https://www.elastic.co/guide/en/kibana/current/settings.html +| *`http`* + +_xref:common-k8s-elastic-co-v1-httpconfig[$$HTTPConfig$$]_ +| +HTTP holds the HTTP layer configuration for Kibana. +| *`podTemplate`* + +_link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#podtemplatespec-v1-core[$$Kubernetes core/v1.PodTemplateSpec$$]_ +| +PodTemplate provides customisation options (labels, annotations, affinity rules, resource requests, and so on) for the Kibana pods +| *`secureSettings`* + +_xref:common-k8s-elastic-co-v1-secretsource[$$[]SecretSource$$]_ +| +SecureSettings is a list of references to Kubernetes secrets containing sensitive configuration options for Kibana. +See: https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-kibana.html#k8s-kibana-secure-settings +|=== [id="{p}-kibana-k8s-elastic-co-v1beta1"] === kibana.k8s.elastic.co/v1beta1 Package v1beta1 contains API schema definitions for managing Kibana resources. diff --git a/docs/eck-attributes.asciidoc b/docs/eck-attributes.asciidoc index 171ca9124e5..91ca0a27668 100644 --- a/docs/eck-attributes.asciidoc +++ b/docs/eck-attributes.asciidoc @@ -1,2 +1,2 @@ :eck_version: 1.0.0-beta1 -:eck_crd_version: v1beta1 +:eck_crd_version: v1 diff --git a/pkg/apis/apm/v1/apmserver_types.go b/pkg/apis/apm/v1/apmserver_types.go new file mode 100644 index 00000000000..6db26355de7 --- /dev/null +++ b/pkg/apis/apm/v1/apmserver_types.go @@ -0,0 +1,123 @@ +// 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 v1 + +import ( + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" +) + +const ApmServerContainerName = "apm-server" + +// ApmServerSpec holds the specification of an APM Server. +type ApmServerSpec struct { + // Version of the APM Server. + Version string `json:"version,omitempty"` + + // Image is the APM Server Docker image to deploy. + Image string `json:"image,omitempty"` + + // Count of APM Server instances to deploy. + Count int32 `json:"count,omitempty"` + + // Config holds the APM Server configuration. See: https://www.elastic.co/guide/en/apm/server/current/configuring-howto-apm-server.html + Config *commonv1.Config `json:"config,omitempty"` + + // HTTP holds the HTTP layer configuration for the APM Server resource. + HTTP commonv1.HTTPConfig `json:"http,omitempty"` + + // ElasticsearchRef is a reference to the output Elasticsearch cluster running in the same Kubernetes cluster. + ElasticsearchRef commonv1.ObjectSelector `json:"elasticsearchRef,omitempty"` + + // PodTemplate provides customisation options (labels, annotations, affinity rules, resource requests, and so on) for the APM Server pods. + // +kubebuilder:validation:Optional + PodTemplate corev1.PodTemplateSpec `json:"podTemplate,omitempty"` + + // SecureSettings is a list of references to Kubernetes secrets containing sensitive configuration options for APM Server. + // See: https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-apm-server.html#k8s-apm-secure-settings + SecureSettings []commonv1.SecretSource `json:"secureSettings,omitempty"` +} + +// ApmServerHealth expresses the status of the Apm Server instances. +type ApmServerHealth string + +const ( + // ApmServerRed means no instance is currently available. + ApmServerRed ApmServerHealth = "red" + // ApmServerGreen means at least one instance is available. + ApmServerGreen ApmServerHealth = "green" +) + +// ApmServerStatus defines the observed state of ApmServer +type ApmServerStatus struct { + commonv1.ReconcilerStatus `json:",inline"` + Health ApmServerHealth `json:"health,omitempty"` + // ExternalService is the name of the service the agents should connect to. + ExternalService string `json:"service,omitempty"` + // SecretTokenSecretName is the name of the Secret that contains the secret token + SecretTokenSecretName string `json:"secretTokenSecret,omitempty"` + // Association is the status of any auto-linking to Elasticsearch clusters. + Association commonv1.AssociationStatus `json:"associationStatus,omitempty"` +} + +// IsDegraded returns true if the current status is worse than the previous. +func (as ApmServerStatus) IsDegraded(prev ApmServerStatus) bool { + return prev.Health == ApmServerGreen && as.Health != ApmServerGreen +} + +// +kubebuilder:object:root=true + +// ApmServer represents an APM Server resource in a Kubernetes cluster. +// +kubebuilder:resource:categories=elastic,shortName=apm +// +kubebuilder:subresource:status +// +kubebuilder:printcolumn:name="health",type="string",JSONPath=".status.health" +// +kubebuilder:printcolumn:name="nodes",type="integer",JSONPath=".status.availableNodes",description="Available nodes" +// +kubebuilder:printcolumn:name="version",type="string",JSONPath=".spec.version",description="APM version" +// +kubebuilder:printcolumn:name="age",type="date",JSONPath=".metadata.creationTimestamp" +// +kubebuilder:storageversion +type ApmServer struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec ApmServerSpec `json:"spec,omitempty"` + Status ApmServerStatus `json:"status,omitempty"` + assocConf *commonv1.AssociationConf `json:"-"` //nolint:govet +} + +// +kubebuilder:object:root=true + +// ApmServerList contains a list of ApmServer +type ApmServerList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []ApmServer `json:"items"` +} + +func init() { + SchemeBuilder.Register(&ApmServer{}, &ApmServerList{}) +} + +// IsMarkedForDeletion returns true if the APM is going to be deleted +func (as *ApmServer) IsMarkedForDeletion() bool { + return !as.DeletionTimestamp.IsZero() +} + +func (as *ApmServer) ElasticsearchRef() commonv1.ObjectSelector { + return as.Spec.ElasticsearchRef +} + +func (as *ApmServer) SecureSettings() []commonv1.SecretSource { + return as.Spec.SecureSettings +} + +func (as *ApmServer) AssociationConf() *commonv1.AssociationConf { + return as.assocConf +} + +func (as *ApmServer) SetAssociationConf(assocConf *commonv1.AssociationConf) { + as.assocConf = assocConf +} diff --git a/pkg/apis/apm/v1/doc.go b/pkg/apis/apm/v1/doc.go new file mode 100644 index 00000000000..f0bcc3aa1fd --- /dev/null +++ b/pkg/apis/apm/v1/doc.go @@ -0,0 +1,8 @@ +// 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 v1 contains API schema definitions for managing APM Server resources. +// +kubebuilder:object:generate=true +// +groupName=apm.k8s.elastic.co +package v1 diff --git a/pkg/apis/apm/v1/groupversion_info.go b/pkg/apis/apm/v1/groupversion_info.go new file mode 100644 index 00000000000..bba0415873d --- /dev/null +++ b/pkg/apis/apm/v1/groupversion_info.go @@ -0,0 +1,21 @@ +// 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 v1 + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + "sigs.k8s.io/controller-runtime/pkg/scheme" +) + +var ( + // GroupVersion is group version used to register these objects + GroupVersion = schema.GroupVersion{Group: "apm.k8s.elastic.co", Version: "v1"} + + // SchemeBuilder is used to add go types to the GroupVersionKind scheme + SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} + + // AddToScheme adds the types in this group-version to the given scheme. + AddToScheme = SchemeBuilder.AddToScheme +) diff --git a/pkg/apis/apm/v1/zz_generated.deepcopy.go b/pkg/apis/apm/v1/zz_generated.deepcopy.go new file mode 100644 index 00000000000..3129cf2ab4f --- /dev/null +++ b/pkg/apis/apm/v1/zz_generated.deepcopy.go @@ -0,0 +1,123 @@ +// +build !ignore_autogenerated + +// 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. + +// Code generated by controller-gen. DO NOT EDIT. + +package v1 + +import ( + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ApmServer) DeepCopyInto(out *ApmServer) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + out.Status = in.Status + if in.assocConf != nil { + in, out := &in.assocConf, &out.assocConf + *out = new(commonv1.AssociationConf) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ApmServer. +func (in *ApmServer) DeepCopy() *ApmServer { + if in == nil { + return nil + } + out := new(ApmServer) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ApmServer) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ApmServerList) DeepCopyInto(out *ApmServerList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]ApmServer, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ApmServerList. +func (in *ApmServerList) DeepCopy() *ApmServerList { + if in == nil { + return nil + } + out := new(ApmServerList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ApmServerList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ApmServerSpec) DeepCopyInto(out *ApmServerSpec) { + *out = *in + if in.Config != nil { + in, out := &in.Config, &out.Config + *out = (*in).DeepCopy() + } + in.HTTP.DeepCopyInto(&out.HTTP) + out.ElasticsearchRef = in.ElasticsearchRef + in.PodTemplate.DeepCopyInto(&out.PodTemplate) + if in.SecureSettings != nil { + in, out := &in.SecureSettings, &out.SecureSettings + *out = make([]commonv1.SecretSource, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ApmServerSpec. +func (in *ApmServerSpec) DeepCopy() *ApmServerSpec { + if in == nil { + return nil + } + out := new(ApmServerSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ApmServerStatus) DeepCopyInto(out *ApmServerStatus) { + *out = *in + out.ReconcilerStatus = in.ReconcilerStatus +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ApmServerStatus. +func (in *ApmServerStatus) DeepCopy() *ApmServerStatus { + if in == nil { + return nil + } + out := new(ApmServerStatus) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/apis/apm/v1beta1/apmserver_types.go b/pkg/apis/apm/v1beta1/apmserver_types.go index a5030791e2e..15e20d91238 100644 --- a/pkg/apis/apm/v1beta1/apmserver_types.go +++ b/pkg/apis/apm/v1beta1/apmserver_types.go @@ -77,7 +77,6 @@ func (as ApmServerStatus) IsDegraded(prev ApmServerStatus) bool { // +kubebuilder:printcolumn:name="nodes",type="integer",JSONPath=".status.availableNodes",description="Available nodes" // +kubebuilder:printcolumn:name="version",type="string",JSONPath=".spec.version",description="APM version" // +kubebuilder:printcolumn:name="age",type="date",JSONPath=".metadata.creationTimestamp" -// +kubebuilder:storageversion type ApmServer struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` diff --git a/pkg/apis/common/v1/association.go b/pkg/apis/common/v1/association.go new file mode 100644 index 00000000000..e0c05956d70 --- /dev/null +++ b/pkg/apis/common/v1/association.go @@ -0,0 +1,113 @@ +// 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 v1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" +) + +// AssociationStatus is the status of an association resource. +type AssociationStatus string + +const ( + AssociationUnknown AssociationStatus = "" + AssociationPending AssociationStatus = "Pending" + AssociationEstablished AssociationStatus = "Established" + AssociationFailed AssociationStatus = "Failed" +) + +// Associated interface represents a Elastic stack application that is associated with an Elasticsearch cluster. +// An associated object needs some credentials to establish a connection to the Elasticsearch cluster and usually it +// offers a keystore which in ECK is represented with an underlying Secret. +// Kibana and the APM server are two examples of associated objects. +// +kubebuilder:object:generate=false +type Associated interface { + metav1.Object + runtime.Object + ElasticsearchRef() ObjectSelector + AssociationConf() *AssociationConf +} + +// Associator describes an object that allows its association to be set. +// +kubebuilder:object:generate=false +type Associator interface { + metav1.Object + runtime.Object + SetAssociationConf(*AssociationConf) +} + +// AssociationConf holds the association configuration of an Elasticsearch cluster. +type AssociationConf struct { + AuthSecretName string `json:"authSecretName"` + AuthSecretKey string `json:"authSecretKey"` + CACertProvided bool `json:"caCertProvided"` + CASecretName string `json:"caSecretName"` + URL string `json:"url"` +} + +// IsConfigured returns true if all the fields are set. +func (ac *AssociationConf) IsConfigured() bool { + return ac.AuthIsConfigured() && ac.CAIsConfigured() && ac.URLIsConfigured() +} + +// AuthIsConfigured returns true if all the auth fields are set. +func (ac *AssociationConf) AuthIsConfigured() bool { + if ac == nil { + return false + } + return ac.AuthSecretName != "" && ac.AuthSecretKey != "" +} + +// CAIsConfigured returns true if the CA field is set. +func (ac *AssociationConf) CAIsConfigured() bool { + if ac == nil { + return false + } + return ac.CASecretName != "" +} + +// URLIsConfigured returns true if the URL field is set. +func (ac *AssociationConf) URLIsConfigured() bool { + if ac == nil { + return false + } + return ac.URL != "" +} + +func (ac *AssociationConf) GetAuthSecretName() string { + if ac == nil { + return "" + } + return ac.AuthSecretName +} + +func (ac *AssociationConf) GetAuthSecretKey() string { + if ac == nil { + return "" + } + return ac.AuthSecretKey +} + +func (ac *AssociationConf) GetCACertProvided() bool { + if ac == nil { + return false + } + return ac.CACertProvided +} + +func (ac *AssociationConf) GetCASecretName() string { + if ac == nil { + return "" + } + return ac.CASecretName +} + +func (ac *AssociationConf) GetURL() string { + if ac == nil { + return "" + } + return ac.URL +} diff --git a/pkg/apis/common/v1/association_test.go b/pkg/apis/common/v1/association_test.go new file mode 100644 index 00000000000..05b19c47601 --- /dev/null +++ b/pkg/apis/common/v1/association_test.go @@ -0,0 +1,77 @@ +// 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 v1 + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestAssociationConfIsConfigured(t *testing.T) { + tests := []struct { + name string + assocConf *AssociationConf + want bool + }{ + { + name: "nil object", + want: false, + }, + { + name: "missing URL", + assocConf: &AssociationConf{ + AuthSecretName: "auth-secret", + AuthSecretKey: "elastic", + CASecretName: "ca-secret", + }, + want: false, + }, + { + name: "missing auth secret name", + assocConf: &AssociationConf{ + AuthSecretKey: "elastic", + CASecretName: "ca-secret", + URL: "https://my-es.svc", + }, + want: false, + }, + { + name: "missing auth secret key", + assocConf: &AssociationConf{ + AuthSecretName: "auth-secret", + CASecretName: "ca-secret", + URL: "https://my-es.svc", + }, + want: false, + }, + { + name: "missing CA secret name", + assocConf: &AssociationConf{ + AuthSecretName: "auth-secret", + AuthSecretKey: "elastic", + URL: "https://my-es.svc", + }, + want: false, + }, + { + name: "correctly configured", + assocConf: &AssociationConf{ + AuthSecretName: "auth-secret", + AuthSecretKey: "elastic", + CASecretName: "ca-secret", + URL: "https://my-es.svc", + }, + want: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := tt.assocConf.IsConfigured() + require.Equal(t, tt.want, got) + }) + } +} diff --git a/pkg/apis/common/v1/common.go b/pkg/apis/common/v1/common.go new file mode 100644 index 00000000000..0b4412e61c1 --- /dev/null +++ b/pkg/apis/common/v1/common.go @@ -0,0 +1,154 @@ +// 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 v1 + +import ( + "reflect" + + v1 "k8s.io/api/core/v1" + "k8s.io/api/policy/v1beta1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/intstr" +) + +// ReconcilerStatus represents status information about desired/available nodes. +type ReconcilerStatus struct { + AvailableNodes int32 `json:"availableNodes,omitempty"` +} + +// SecretRef is a reference to a secret that exists in the same namespace. +type SecretRef struct { + // SecretName is the name of the secret. + SecretName string `json:"secretName,omitempty"` +} + +// ObjectSelector defines a reference to a Kubernetes object. +type ObjectSelector struct { + // Name of the Kubernetes object. + Name string `json:"name"` + // Namespace of the Kubernetes object. If empty, defaults to the current namespace. + Namespace string `json:"namespace,omitempty"` +} + +// NamespacedName is a convenience method to turn an ObjectSelector into a NamespacedName. +func (s ObjectSelector) NamespacedName() types.NamespacedName { + return types.NamespacedName{ + Name: s.Name, + Namespace: s.Namespace, + } +} + +// IsDefined checks if the object selector is not nil and has a name. +// Namespace is not mandatory as it may be inherited by the parent object. +func (s *ObjectSelector) IsDefined() bool { + return s != nil && s.Name != "" +} + +// HTTPConfig holds the HTTP layer configuration for resources. +type HTTPConfig struct { + // Service defines the template for the associated Kubernetes Service object. + Service ServiceTemplate `json:"service,omitempty"` + // TLS defines options for configuring TLS for HTTP. + TLS TLSOptions `json:"tls,omitempty"` +} + +// Protocol returns the inferrred protocol (http or https) for this configuration. +func (http HTTPConfig) Protocol() string { + if http.TLS.Enabled() { + return "https" + } + return "http" +} + +// TLSOptions holds TLS configuration options. +type TLSOptions struct { + // SelfSignedCertificate allows configuring the self-signed certificate generated by the operator. + SelfSignedCertificate *SelfSignedCertificate `json:"selfSignedCertificate,omitempty"` + + // Certificate is a reference to a Kubernetes secret that contains the certificate and private key for enabling TLS. + // The referenced secret should contain the following: + // + // - `ca.crt`: The certificate authority (optional). + // - `tls.crt`: The certificate (or a chain). + // - `tls.key`: The private key to the first certificate in the certificate chain. + Certificate SecretRef `json:"certificate,omitempty"` +} + +// Enabled returns true when TLS is enabled based on this option struct. +func (tls TLSOptions) Enabled() bool { + selfSigned := tls.SelfSignedCertificate + return selfSigned == nil || !selfSigned.Disabled || tls.Certificate.SecretName != "" +} + +// SelfSignedCertificate holds configuration for the self-signed certificate generated by the operator. +type SelfSignedCertificate struct { + // SubjectAlternativeNames is a list of SANs to include in the generated HTTP TLS certificate. + SubjectAlternativeNames []SubjectAlternativeName `json:"subjectAltNames,omitempty"` + // Disabled indicates that the provisioning of the self-signed certifcate should be disabled. + Disabled bool `json:"disabled,omitempty"` +} + +// SubjectAlternativeName represents a SAN entry in a x509 certificate. +type SubjectAlternativeName struct { + // DNS is the DNS name of the subject. + DNS string `json:"dns,omitempty"` + // IP is the IP address of the subject. + IP string `json:"ip,omitempty"` +} + +// ServiceTemplate defines the template for a Kubernetes Service. +type ServiceTemplate struct { + // ObjectMeta is the metadata of the service. + // The name and namespace provided here are managed by ECK and will be ignored. + // +kubebuilder:validation:Optional + ObjectMeta metav1.ObjectMeta `json:"metadata,omitempty"` + + // Spec is the specification of the service. + // +kubebuilder:validation:Optional + Spec v1.ServiceSpec `json:"spec,omitempty"` +} + +// DefaultPodDisruptionBudgetMaxUnavailable is the default max unavailable pods in a PDB. +var DefaultPodDisruptionBudgetMaxUnavailable = intstr.FromInt(1) + +// PodDisruptionBudgetTemplate defines the template for creating a PodDisruptionBudget. +type PodDisruptionBudgetTemplate struct { + // ObjectMeta is the metadata of the PDB. + // The name and namespace provided here are managed by ECK and will be ignored. + // +kubebuilder:validation:Optional + ObjectMeta metav1.ObjectMeta `json:"metadata,omitempty"` + + // Spec is the specification of the PDB. + // +kubebuilder:validation:Optional + Spec v1beta1.PodDisruptionBudgetSpec `json:"spec,omitempty"` +} + +// IsDisabled returns true if the PodDisruptionBudget is explicitly disabled (not nil, but empty). +func (p *PodDisruptionBudgetTemplate) IsDisabled() bool { + return reflect.DeepEqual(p, &PodDisruptionBudgetTemplate{}) +} + +// SecretSource defines a data source based on a Kubernetes Secret. +type SecretSource struct { + // SecretName is the name of the secret. + SecretName string `json:"secretName"` + // Entries define how to project each key-value pair in the secret to filesystem paths. + // If not defined, all keys will be projected to similarly named paths in the filesystem. + // If defined, only the specified keys will be projected to the corresponding paths. + // +kubebuilder:validation:Optional + Entries []KeyToPath `json:"entries,omitempty"` +} + +// KeyToPath defines how to map a key in a Secret object to a filesystem path. +type KeyToPath struct { + // Key is the key contained in the secret. + Key string `json:"key"` + + // Path is the relative file path to map the key to. + // Path must not be an absolute file path and must not contain any ".." components. + // +kubebuilder:validation:Optional + Path string `json:"path,omitempty"` +} diff --git a/pkg/apis/common/v1/common_test.go b/pkg/apis/common/v1/common_test.go new file mode 100644 index 00000000000..6882838e68e --- /dev/null +++ b/pkg/apis/common/v1/common_test.go @@ -0,0 +1,134 @@ +// 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 v1 + +import "testing" + +func TestTLSOptions_Enabled(t *testing.T) { + type fields struct { + SelfSignedCertificate *SelfSignedCertificate + Certificate SecretRef + } + tests := []struct { + name string + fields fields + want bool + }{ + { + name: "disabled: no custom cert and self-signed disabled", + fields: fields{ + SelfSignedCertificate: &SelfSignedCertificate{ + Disabled: true, + }, + Certificate: SecretRef{}, + }, + want: false, + }, + { + name: "enabled: custom certs and self-signed disabled", + fields: fields{ + SelfSignedCertificate: &SelfSignedCertificate{ + Disabled: true, + }, + Certificate: SecretRef{ + SecretName: "my-custom-certs", + }, + }, + want: true, + }, + { + name: "enabled: by default", + fields: fields{}, + want: true, + }, + { + name: "enabled: via self-signed certificates", + fields: fields{ + SelfSignedCertificate: &SelfSignedCertificate{ + SubjectAlternativeNames: []SubjectAlternativeName{}, + Disabled: false, + }, + Certificate: SecretRef{}, + }, + want: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + tls := TLSOptions{ + SelfSignedCertificate: tt.fields.SelfSignedCertificate, + Certificate: tt.fields.Certificate, + } + if got := tls.Enabled(); got != tt.want { + t.Errorf("TLSOptions.Enabled() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestHTTPConfig_Scheme(t *testing.T) { + type fields struct { + TLS TLSOptions + } + tests := []struct { + name string + fields fields + want string + }{ + { + name: "enabled", + fields: fields{ + TLS: TLSOptions{ + SelfSignedCertificate: &SelfSignedCertificate{ + Disabled: false, + }, + }, + }, + want: "https", + }, + { + name: "enabled: custom certs and self-signed disabled", + fields: fields{ + TLS: TLSOptions{ + SelfSignedCertificate: &SelfSignedCertificate{ + Disabled: true, + }, + Certificate: SecretRef{ + SecretName: "my-custom-certs", + }, + }, + }, + want: "https", + }, + { + name: "disabled", + fields: fields{ + TLS: TLSOptions{ + SelfSignedCertificate: &SelfSignedCertificate{ + Disabled: true, + }, + }, + }, + want: "http", + }, + { + name: "default", + fields: fields{ + TLS: TLSOptions{}, + }, + want: "https", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + http := HTTPConfig{ + TLS: tt.fields.TLS, + } + if got := http.Protocol(); got != tt.want { + t.Errorf("Protocol() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/pkg/apis/common/v1/config.go b/pkg/apis/common/v1/config.go new file mode 100644 index 00000000000..19f206b20b0 --- /dev/null +++ b/pkg/apis/common/v1/config.go @@ -0,0 +1,60 @@ +// 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 v1 + +import ( + "encoding/json" + + ucfg "github.com/elastic/go-ucfg" +) + +// CfgOptions are config options for YAML config. Currently contains only support for dotted keys. +var CfgOptions = []ucfg.Option{ucfg.PathSep(".")} + +// Config represents untyped YAML configuration. +type Config struct { + // Data holds the configuration keys and values. + // This field exists to work around https://github.com/kubernetes-sigs/kubebuilder/issues/528 + Data map[string]interface{} `json:"-"` +} + +// NewConfig constructs a Config with the given unstructured configuration data. +func NewConfig(cfg map[string]interface{}) Config { + return Config{Data: cfg} +} + +// MarshalJSON implements the Marshaler interface. +func (c *Config) MarshalJSON() ([]byte, error) { + return json.Marshal(c.Data) +} + +// UnmarshalJSON implements the Unmarshaler interface. +func (c *Config) UnmarshalJSON(data []byte) error { + var out map[string]interface{} + err := json.Unmarshal(data, &out) + if err != nil { + return err + } + c.Data = out + return nil +} + +// DeepCopyInto is an ~autogenerated~ deepcopy function, copying the receiver, writing into out. in must be non-nil. +// This exists here to work around https://github.com/kubernetes/code-generator/issues/50 +func (c *Config) DeepCopyInto(out *Config) { + bytes, err := json.Marshal(c.Data) + if err != nil { + // we assume that it marshals cleanly because otherwise the resource would not have been + // created in the API server + panic(err) + } + var copy map[string]interface{} + err = json.Unmarshal(bytes, ©) + if err != nil { + // we assume again optimistically because we just marshalled that the round trip works as well + panic(err) + } + out.Data = copy +} diff --git a/pkg/apis/common/v1/config_test.go b/pkg/apis/common/v1/config_test.go new file mode 100644 index 00000000000..61fe650ef10 --- /dev/null +++ b/pkg/apis/common/v1/config_test.go @@ -0,0 +1,83 @@ +// 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 v1 + +import ( + "testing" + + "github.com/go-test/deep" +) + +var testFixture = Config{ + Data: map[string]interface{}{ + "a": map[string]interface{}{ + "b": map[string]interface{}{ + "c": 1.0, + }, + "d": 1, + }, + "a.b.foo": "bar", + "e": []interface{}{1, 2, 3}, + "f": true, + }, +} + +var expectedJSONized = Config{ + Data: map[string]interface{}{ + "a": map[string]interface{}{ + "b": map[string]interface{}{ + "c": 1.0, + }, + "d": float64(1), + }, + "a.b.foo": "bar", + "e": []interface{}{float64(1), float64(2), float64(3)}, + "f": true, + }, +} + +func TestConfig_DeepCopyInto(t *testing.T) { + tests := []struct { + name string + in Config + expected Config + }{ + { + name: "deep copy via JSON roundtrip changes some types", + in: testFixture, + expected: expectedJSONized, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + var out Config + tt.in.DeepCopyInto(&out) + if diff := deep.Equal(out, tt.expected); diff != nil { + t.Error(diff) + } + }) + } +} + +func TestConfig_DeepCopy(t *testing.T) { + tests := []struct { + name string + in Config + want Config + }{ + { + name: "deep copy via JSON roundtrip changes some types", + in: testFixture, + want: expectedJSONized, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if diff := deep.Equal(tt.in.DeepCopy(), &tt.want); diff != nil { + t.Error(diff) + } + }) + } +} diff --git a/pkg/apis/common/v1/doc.go b/pkg/apis/common/v1/doc.go new file mode 100644 index 00000000000..8ea47bbf767 --- /dev/null +++ b/pkg/apis/common/v1/doc.go @@ -0,0 +1,8 @@ +// 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 v1 contains API schema definitions for common types used by all resources. +// +kubebuilder:object:generate=true +// +groupName=common.k8s.elastic.co +package v1 diff --git a/pkg/apis/common/v1/groupversion_info.go b/pkg/apis/common/v1/groupversion_info.go new file mode 100644 index 00000000000..6efeb727d74 --- /dev/null +++ b/pkg/apis/common/v1/groupversion_info.go @@ -0,0 +1,21 @@ +// 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 v1 + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + "sigs.k8s.io/controller-runtime/pkg/scheme" +) + +var ( + // GroupVersion is group version used to register these objects + GroupVersion = schema.GroupVersion{Group: "common.k8s.elastic.co", Version: "v1"} + + // SchemeBuilder is used to add go types to the GroupVersionKind scheme + SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} + + // AddToScheme adds the types in this group-version to the given scheme. + AddToScheme = SchemeBuilder.AddToScheme +) diff --git a/pkg/apis/common/v1/zz_generated.deepcopy.go b/pkg/apis/common/v1/zz_generated.deepcopy.go new file mode 100644 index 00000000000..598e63a11e8 --- /dev/null +++ b/pkg/apis/common/v1/zz_generated.deepcopy.go @@ -0,0 +1,223 @@ +// +build !ignore_autogenerated + +// 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. + +// Code generated by controller-gen. DO NOT EDIT. + +package v1 + +import () + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AssociationConf) DeepCopyInto(out *AssociationConf) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AssociationConf. +func (in *AssociationConf) DeepCopy() *AssociationConf { + if in == nil { + return nil + } + out := new(AssociationConf) + in.DeepCopyInto(out) + return out +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Config. +func (in *Config) DeepCopy() *Config { + if in == nil { + return nil + } + out := new(Config) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *HTTPConfig) DeepCopyInto(out *HTTPConfig) { + *out = *in + in.Service.DeepCopyInto(&out.Service) + in.TLS.DeepCopyInto(&out.TLS) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HTTPConfig. +func (in *HTTPConfig) DeepCopy() *HTTPConfig { + if in == nil { + return nil + } + out := new(HTTPConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KeyToPath) DeepCopyInto(out *KeyToPath) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KeyToPath. +func (in *KeyToPath) DeepCopy() *KeyToPath { + if in == nil { + return nil + } + out := new(KeyToPath) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ObjectSelector) DeepCopyInto(out *ObjectSelector) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ObjectSelector. +func (in *ObjectSelector) DeepCopy() *ObjectSelector { + if in == nil { + return nil + } + out := new(ObjectSelector) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PodDisruptionBudgetTemplate) DeepCopyInto(out *PodDisruptionBudgetTemplate) { + *out = *in + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodDisruptionBudgetTemplate. +func (in *PodDisruptionBudgetTemplate) DeepCopy() *PodDisruptionBudgetTemplate { + if in == nil { + return nil + } + out := new(PodDisruptionBudgetTemplate) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ReconcilerStatus) DeepCopyInto(out *ReconcilerStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ReconcilerStatus. +func (in *ReconcilerStatus) DeepCopy() *ReconcilerStatus { + if in == nil { + return nil + } + out := new(ReconcilerStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SecretRef) DeepCopyInto(out *SecretRef) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SecretRef. +func (in *SecretRef) DeepCopy() *SecretRef { + if in == nil { + return nil + } + out := new(SecretRef) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SecretSource) DeepCopyInto(out *SecretSource) { + *out = *in + if in.Entries != nil { + in, out := &in.Entries, &out.Entries + *out = make([]KeyToPath, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SecretSource. +func (in *SecretSource) DeepCopy() *SecretSource { + if in == nil { + return nil + } + out := new(SecretSource) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SelfSignedCertificate) DeepCopyInto(out *SelfSignedCertificate) { + *out = *in + if in.SubjectAlternativeNames != nil { + in, out := &in.SubjectAlternativeNames, &out.SubjectAlternativeNames + *out = make([]SubjectAlternativeName, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SelfSignedCertificate. +func (in *SelfSignedCertificate) DeepCopy() *SelfSignedCertificate { + if in == nil { + return nil + } + out := new(SelfSignedCertificate) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ServiceTemplate) DeepCopyInto(out *ServiceTemplate) { + *out = *in + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceTemplate. +func (in *ServiceTemplate) DeepCopy() *ServiceTemplate { + if in == nil { + return nil + } + out := new(ServiceTemplate) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SubjectAlternativeName) DeepCopyInto(out *SubjectAlternativeName) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SubjectAlternativeName. +func (in *SubjectAlternativeName) DeepCopy() *SubjectAlternativeName { + if in == nil { + return nil + } + out := new(SubjectAlternativeName) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TLSOptions) DeepCopyInto(out *TLSOptions) { + *out = *in + if in.SelfSignedCertificate != nil { + in, out := &in.SelfSignedCertificate, &out.SelfSignedCertificate + *out = new(SelfSignedCertificate) + (*in).DeepCopyInto(*out) + } + out.Certificate = in.Certificate +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TLSOptions. +func (in *TLSOptions) DeepCopy() *TLSOptions { + if in == nil { + return nil + } + out := new(TLSOptions) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/apis/elasticsearch/v1/doc.go b/pkg/apis/elasticsearch/v1/doc.go new file mode 100644 index 00000000000..bfc0fd0c64e --- /dev/null +++ b/pkg/apis/elasticsearch/v1/doc.go @@ -0,0 +1,8 @@ +// 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 v1 contains API schema definitions for managing Elasticsearch resources. +// +kubebuilder:object:generate=true +// +groupName=elasticsearch.k8s.elastic.co +package v1 diff --git a/pkg/apis/elasticsearch/v1/elasticsearch_config.go b/pkg/apis/elasticsearch/v1/elasticsearch_config.go new file mode 100644 index 00000000000..f3ff4e7953c --- /dev/null +++ b/pkg/apis/elasticsearch/v1/elasticsearch_config.go @@ -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 v1 + +import ( + "github.com/elastic/go-ucfg" + + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" +) + +const ( + NodeData = "node.data" + NodeIngest = "node.ingest" + NodeMaster = "node.master" + NodeML = "node.ml" +) + +// ClusterSettings is the cluster node in elasticsearch.yml. +type ClusterSettings struct { + InitialMasterNodes []string `config:"initial_master_nodes"` +} + +// Node is the node section in elasticsearch.yml. +type Node struct { + Master bool `config:"master"` + Data bool `config:"data"` + Ingest bool `config:"ingest"` + ML bool `config:"ml"` +} + +// ElasticsearchSettings is a typed subset of elasticsearch.yml for purposes of the operator. +type ElasticsearchSettings struct { + Node Node `config:"node"` + Cluster ClusterSettings `config:"cluster"` +} + +// DefaultCfg is an instance of ElasticsearchSettings with defaults set as they are in Elasticsearch. +var DefaultCfg = ElasticsearchSettings{ + Node: Node{ + Master: true, + Data: true, + Ingest: true, + ML: true, + }, +} + +// Unpack unpacks Config into a typed subset. +func UnpackConfig(c *commonv1.Config) (ElasticsearchSettings, error) { + esSettings := DefaultCfg // defensive copy + if c == nil { + // make this nil safe to allow a ptr value to work around Json serialization issues + return esSettings, nil + } + config, err := ucfg.NewFrom(c.Data, commonv1.CfgOptions...) + if err != nil { + return esSettings, err + } + err = config.Unpack(&esSettings, commonv1.CfgOptions...) + return esSettings, err +} diff --git a/pkg/apis/elasticsearch/v1/elasticsearch_config_test.go b/pkg/apis/elasticsearch/v1/elasticsearch_config_test.go new file mode 100644 index 00000000000..4005f547599 --- /dev/null +++ b/pkg/apis/elasticsearch/v1/elasticsearch_config_test.go @@ -0,0 +1,202 @@ +// 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 v1 + +import ( + "testing" + + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + "github.com/go-test/deep" + "github.com/stretchr/testify/require" +) + +func TestConfig_RoleDefaults(t *testing.T) { + type args struct { + c2 commonv1.Config + } + tests := []struct { + name string + c commonv1.Config + args args + want bool + }{ + { + name: "empty is equal", + c: commonv1.Config{}, + args: args{}, + want: true, + }, + { + name: "same is equal", + c: commonv1.Config{ + Data: map[string]interface{}{ + NodeMaster: true, + }, + }, + args: args{ + c2: commonv1.Config{ + Data: map[string]interface{}{ + NodeMaster: true, + }, + }, + }, + want: true, + }, + { + name: "detect differences", + c: commonv1.Config{ + Data: map[string]interface{}{ + NodeMaster: false, + NodeData: true, + }, + }, + args: args{ + c2: commonv1.Config{ + Data: map[string]interface{}{ + NodeData: true, + }, + }, + }, + want: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + c1, err := UnpackConfig(&tt.c) + require.NoError(t, err) + c2, err := UnpackConfig(&tt.args.c2) + require.NoError(t, err) + if got := c1.Node == c2.Node; got != tt.want { + t.Errorf("Config.EqualRoles() = %v, want %v", got, tt.want) + } + }) + } +} + +var testFixture = commonv1.Config{ + Data: map[string]interface{}{ + "a": map[string]interface{}{ + "b": map[string]interface{}{ + "c": 1.0, + }, + "d": 1, + }, + "a.b.foo": "bar", + "e": []interface{}{1, 2, 3}, + "f": true, + }, +} + +var expectedJSONized = commonv1.Config{ + Data: map[string]interface{}{ + "a": map[string]interface{}{ + "b": map[string]interface{}{ + "c": 1.0, + }, + "d": float64(1), + }, + "a.b.foo": "bar", + "e": []interface{}{float64(1), float64(2), float64(3)}, + "f": true, + }, +} + +func TestConfig_DeepCopyInto(t *testing.T) { + tests := []struct { + name string + in commonv1.Config + expected commonv1.Config + }{ + { + name: "deep copy via JSON roundtrip changes some types", + in: testFixture, + expected: expectedJSONized, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + var out commonv1.Config + tt.in.DeepCopyInto(&out) + if diff := deep.Equal(out, tt.expected); diff != nil { + t.Error(diff) + } + }) + } +} + +func TestConfig_DeepCopy(t *testing.T) { + tests := []struct { + name string + in commonv1.Config + want commonv1.Config + }{ + { + name: "deep copy via JSON roundtrip changes some types", + in: testFixture, + want: expectedJSONized, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if diff := deep.Equal(tt.in.DeepCopy(), &tt.want); diff != nil { + t.Error(diff) + } + }) + } +} + +func TestConfig_Unpack(t *testing.T) { + tests := []struct { + name string + args *commonv1.Config + want ElasticsearchSettings + wantErr bool + }{ + { + name: "happy path", + args: &commonv1.Config{ + Data: map[string]interface{}{ + "node": map[string]interface{}{ + "master": false, + "data": true, + }, + "cluster": map[string]interface{}{ + "initial_master_nodes": []string{"a", "b"}, + }, + }, + }, + want: ElasticsearchSettings{ + Node: Node{ + Master: false, + Data: true, + Ingest: true, + ML: true, + }, + Cluster: ClusterSettings{ + InitialMasterNodes: []string{"a", "b"}, + }, + }, + wantErr: false, + }, + { + name: "Unpack is nil safe", + args: nil, + want: DefaultCfg, + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := UnpackConfig(tt.args) + if (err != nil) != tt.wantErr { + t.Errorf("Config.Unpack() error = %v, wantErr %v", err, tt.wantErr) + return + } + if diff := deep.Equal(tt.want, got); diff != nil { + t.Error(diff) + } + }) + } +} diff --git a/pkg/apis/elasticsearch/v1/elasticsearch_types.go b/pkg/apis/elasticsearch/v1/elasticsearch_types.go new file mode 100644 index 00000000000..89b6ef1f100 --- /dev/null +++ b/pkg/apis/elasticsearch/v1/elasticsearch_types.go @@ -0,0 +1,247 @@ +// 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 v1 + +import ( + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + "github.com/elastic/cloud-on-k8s/pkg/utils/pointer" +) + +const ElasticsearchContainerName = "elasticsearch" + +// ElasticsearchSpec holds the specification of an Elasticsearch cluster. +type ElasticsearchSpec struct { + // Version of Elasticsearch. + Version string `json:"version,omitempty"` + + // Image is the Elasticsearch Docker image to deploy. + Image string `json:"image,omitempty"` + + // HTTP holds HTTP layer settings for Elasticsearch. + // +kubebuilder:validation:Optional + HTTP commonv1.HTTPConfig `json:"http,omitempty"` + + // NodeSets allow specifying groups of Elasticsearch nodes sharing the same configuration and Pod templates. + // See: https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-orchestration.html + // +kubebuilder:validation:MinItems=1 + NodeSets []NodeSet `json:"nodeSets"` + + // UpdateStrategy specifies how updates to the cluster should be performed. + // +kubebuilder:validation:Optional + UpdateStrategy UpdateStrategy `json:"updateStrategy,omitempty"` + + // PodDisruptionBudget provides access to the default pod disruption budget for the Elasticsearch cluster. + // The default budget selects all cluster pods and sets `maxUnavailable` to 1. To disable, set `PodDisruptionBudget` + // to the empty value (`{}` in YAML). + // +kubebuilder:validation:Optional + PodDisruptionBudget *commonv1.PodDisruptionBudgetTemplate `json:"podDisruptionBudget,omitempty"` + + // SecureSettings is a list of references to Kubernetes secrets containing sensitive configuration options for Elasticsearch. + // See: https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-es-secure-settings.html + // +kubebuilder:validation:Optional + SecureSettings []commonv1.SecretSource `json:"secureSettings,omitempty"` +} + +// NodeCount returns the total number of nodes of the Elasticsearch cluster +func (es ElasticsearchSpec) NodeCount() int32 { + count := int32(0) + for _, topoElem := range es.NodeSets { + count += topoElem.Count + } + return count +} + +// NodeSet is the specification for a group of Elasticsearch nodes sharing the same configuration and a Pod template. +type NodeSet struct { + // Name of this set of nodes. Becomes a part of the Elasticsearch node.name setting. + // +kubebuilder:validation:Pattern=[a-zA-Z0-9-]+ + // +kubebuilder:validation:MaxLength=23 + Name string `json:"name"` + + // Config holds the Elasticsearch configuration. + Config *commonv1.Config `json:"config,omitempty"` + + // Count of Elasticsearch nodes to deploy. + // +kubebuilder:validation:Minimum=1 + Count int32 `json:"count"` + + // PodTemplate provides customisation options (labels, annotations, affinity rules, resource requests, and so on) for the Pods belonging to this NodeSet. + // +kubebuilder:validation:Optional + PodTemplate corev1.PodTemplateSpec `json:"podTemplate,omitempty"` + + // VolumeClaimTemplates is a list of persistent volume claims to be used by each Pod in this NodeSet. + // Every claim in this list must have a matching volumeMount in one of the containers defined in the PodTemplate. + // Items defined here take precedence over any default claims added by the operator with the same name. + // See: https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-volume-claim-templates.html + // +kubebuilder:validation:Optional + VolumeClaimTemplates []corev1.PersistentVolumeClaim `json:"volumeClaimTemplates,omitempty"` +} + +// GetESContainerTemplate returns the Elasticsearch container (if set) from the NodeSet's PodTemplate +func (n NodeSet) GetESContainerTemplate() *corev1.Container { + for _, c := range n.PodTemplate.Spec.Containers { + if c.Name == ElasticsearchContainerName { + return &c + } + } + return nil +} + +// UpdateStrategy specifies how updates to the cluster should be performed. +type UpdateStrategy struct { + // ChangeBudget defines the constraints to consider when applying changes to the Elasticsearch cluster. + ChangeBudget ChangeBudget `json:"changeBudget,omitempty"` +} + +// ChangeBudget defines the constraints to consider when applying changes to the Elasticsearch cluster. +type ChangeBudget struct { + // MaxUnavailable is the maximum number of pods that can be unavailable (not ready) during the update due to + // circumstances under the control of the operator. Setting a negative value will disable this restriction. + // Defaults to 1 if not specified. + MaxUnavailable *int32 `json:"maxUnavailable,omitempty"` + + // MaxSurge is the maximum number of new pods that can be created exceeding the original number of pods defined in + // the specification. MaxSurge is only taken into consideration when scaling up. Setting a negative value will + // disable the restriction. Defaults to unbounded if not specified. + MaxSurge *int32 `json:"maxSurge,omitempty"` +} + +// DefaultChangeBudget is used when no change budget is provided. It might not be the most effective, but should work in +// most cases. +var DefaultChangeBudget = ChangeBudget{ + MaxSurge: nil, + MaxUnavailable: pointer.Int32(1), +} + +func (cb ChangeBudget) GetMaxSurgeOrDefault() *int32 { + // use default if not specified + maxSurge := DefaultChangeBudget.MaxSurge + if cb.MaxSurge != nil { + maxSurge = cb.MaxSurge + } + + // nil or negative in the spec denotes unlimited surge + // in the code unlimited surge is denoted by nil + if maxSurge == nil || *maxSurge < 0 { + maxSurge = nil + } + + return maxSurge +} + +func (cb ChangeBudget) GetMaxUnavailableOrDefault() *int32 { + // use default if not specified + maxUnavailable := DefaultChangeBudget.MaxUnavailable + if cb.MaxUnavailable != nil { + maxUnavailable = cb.MaxUnavailable + } + + // nil or negative in the spec denotes unlimited unavailability + // in the code unlimited unavailability is denoted by nil + if maxUnavailable == nil || *maxUnavailable < 0 { + maxUnavailable = nil + } + + return maxUnavailable +} + +// ElasticsearchHealth is the health of the cluster as returned by the health API. +type ElasticsearchHealth string + +// Possible traffic light states Elasticsearch health can have. +const ( + ElasticsearchRedHealth ElasticsearchHealth = "red" + ElasticsearchYellowHealth ElasticsearchHealth = "yellow" + ElasticsearchGreenHealth ElasticsearchHealth = "green" + ElasticsearchUnknownHealth ElasticsearchHealth = "unknown" +) + +var elasticsearchHealthOrder = map[ElasticsearchHealth]int{ + ElasticsearchRedHealth: 1, + ElasticsearchYellowHealth: 2, + ElasticsearchGreenHealth: 3, +} + +// Less for ElasticsearchHealth means green > yellow > red +func (h ElasticsearchHealth) Less(other ElasticsearchHealth) bool { + l := elasticsearchHealthOrder[h] + r := elasticsearchHealthOrder[other] + // 0 is not found/unknown and less is not defined for that + return l != 0 && r != 0 && l < r +} + +// ElasticsearchOrchestrationPhase is the phase Elasticsearch is in from the controller point of view. +type ElasticsearchOrchestrationPhase string + +const ( + // ElasticsearchReadyPhase is operating at the desired spec. + ElasticsearchReadyPhase ElasticsearchOrchestrationPhase = "Ready" + // ElasticsearchApplyingChangesPhase controller is working towards a desired state, cluster can be unavailable. + ElasticsearchApplyingChangesPhase ElasticsearchOrchestrationPhase = "ApplyingChanges" + // ElasticsearchMigratingDataPhase Elasticsearch is currently migrating data to another node. + ElasticsearchMigratingDataPhase ElasticsearchOrchestrationPhase = "MigratingData" + // ElasticsearchResourceInvalid is marking a resource as invalid, should never happen if admission control is installed correctly. + ElasticsearchResourceInvalid ElasticsearchOrchestrationPhase = "Invalid" +) + +// ElasticsearchStatus defines the observed state of Elasticsearch +type ElasticsearchStatus struct { + commonv1.ReconcilerStatus `json:",inline"` + Health ElasticsearchHealth `json:"health,omitempty"` + Phase ElasticsearchOrchestrationPhase `json:"phase,omitempty"` +} + +type ZenDiscoveryStatus struct { + MinimumMasterNodes int `json:"minimumMasterNodes,omitempty"` +} + +// IsDegraded returns true if the current status is worse than the previous. +func (es ElasticsearchStatus) IsDegraded(prev ElasticsearchStatus) bool { + return es.Health.Less(prev.Health) +} + +// +kubebuilder:object:root=true + +// Elasticsearch represents an Elasticsearch resource in a Kubernetes cluster. +// +kubebuilder:resource:categories=elastic,shortName=es +// +kubebuilder:subresource:status +// +kubebuilder:printcolumn:name="health",type="string",JSONPath=".status.health" +// +kubebuilder:printcolumn:name="nodes",type="integer",JSONPath=".status.availableNodes",description="Available nodes" +// +kubebuilder:printcolumn:name="version",type="string",JSONPath=".spec.version",description="Elasticsearch version" +// +kubebuilder:printcolumn:name="phase",type="string",JSONPath=".status.phase" +// +kubebuilder:printcolumn:name="age",type="date",JSONPath=".metadata.creationTimestamp" +// +kubebuilder:storageversion +type Elasticsearch struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec ElasticsearchSpec `json:"spec,omitempty"` + Status ElasticsearchStatus `json:"status,omitempty"` +} + +// IsMarkedForDeletion returns true if the Elasticsearch is going to be deleted +func (e Elasticsearch) IsMarkedForDeletion() bool { + return !e.DeletionTimestamp.IsZero() +} + +func (e Elasticsearch) SecureSettings() []commonv1.SecretSource { + return e.Spec.SecureSettings +} + +// +kubebuilder:object:root=true + +// ElasticsearchList contains a list of Elasticsearch clusters +type ElasticsearchList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []Elasticsearch `json:"items"` +} + +func init() { + SchemeBuilder.Register(&Elasticsearch{}, &ElasticsearchList{}) +} diff --git a/pkg/apis/elasticsearch/v1/elasticsearch_types_test.go b/pkg/apis/elasticsearch/v1/elasticsearch_types_test.go new file mode 100644 index 00000000000..b40cf0aaa92 --- /dev/null +++ b/pkg/apis/elasticsearch/v1/elasticsearch_types_test.go @@ -0,0 +1,214 @@ +// 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 v1 + +import ( + "fmt" + "reflect" + "sort" + "testing" + "time" + + "github.com/elastic/cloud-on-k8s/pkg/utils/pointer" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func TestElasticsearchHealth_Less(t *testing.T) { + + tests := []struct { + inputs []ElasticsearchHealth + sorted bool + }{ + { + inputs: []ElasticsearchHealth{ + "", + ElasticsearchYellowHealth, + "", + }, + sorted: true, + }, + { + inputs: []ElasticsearchHealth{ + ElasticsearchUnknownHealth, + ElasticsearchYellowHealth, + ElasticsearchUnknownHealth, + }, + sorted: true, + }, + { + inputs: []ElasticsearchHealth{ + ElasticsearchRedHealth, + ElasticsearchYellowHealth, + }, + sorted: true, + }, + { + inputs: []ElasticsearchHealth{ + ElasticsearchRedHealth, + ElasticsearchRedHealth, + }, + sorted: true, + }, + { + inputs: []ElasticsearchHealth{ + ElasticsearchRedHealth, + ElasticsearchGreenHealth, + }, + sorted: true, + }, + { + inputs: []ElasticsearchHealth{ + ElasticsearchRedHealth, + ElasticsearchYellowHealth, + ElasticsearchGreenHealth, + }, + sorted: true, + }, + { + inputs: []ElasticsearchHealth{ + ElasticsearchYellowHealth, + ElasticsearchGreenHealth, + }, + sorted: true, + }, + { + inputs: []ElasticsearchHealth{ + ElasticsearchGreenHealth, + ElasticsearchYellowHealth, + }, + sorted: false, + }, + } + + for _, tt := range tests { + assert.Equal(t, sort.SliceIsSorted(tt.inputs, func(i, j int) bool { + return tt.inputs[i].Less(tt.inputs[j]) + }), tt.sorted, fmt.Sprintf("%v", tt.inputs)) + } +} + +func TestElasticsearchCluster_IsMarkedForDeletion(t *testing.T) { + zeroTime := metav1.NewTime(time.Time{}) + currentTime := metav1.NewTime(time.Now()) + tests := []struct { + name string + deletionTimestamp *metav1.Time + want bool + }{ + { + name: "deletion timestamp nil", + deletionTimestamp: nil, + want: false, + }, + { + name: "deletion timestamp set to its zero value", + deletionTimestamp: &zeroTime, + want: false, + }, + { + name: "deletion timestamp set to any non-zero value", + deletionTimestamp: ¤tTime, + want: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + e := Elasticsearch{ + ObjectMeta: metav1.ObjectMeta{ + DeletionTimestamp: tt.deletionTimestamp, + }, + } + require.Equal(t, tt.want, e.IsMarkedForDeletion()) + }) + } +} +func Test_GetMaxSurgeOrDefault(t *testing.T) { + tests := []struct { + name string + fromSpec *int32 + want *int32 + }{ + { + name: "negative in spec results in unbounded", + fromSpec: pointer.Int32(-1), + want: nil, + }, + { + name: "nil in spec results in default, generic", + fromSpec: nil, + want: DefaultChangeBudget.MaxSurge, + }, + { + name: "nil in spec results in default, currently nil", + fromSpec: nil, + want: nil, + }, + { + name: "0 in spec results in 0", + fromSpec: pointer.Int32(0), + want: pointer.Int32(0), + }, + { + name: "1 in spec results in 1", + fromSpec: pointer.Int32(1), + want: pointer.Int32(1), + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := ChangeBudget{MaxSurge: tt.fromSpec}.GetMaxSurgeOrDefault() + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetMaxSurgeOrDefault() want = %v, got = %v", tt.want, got) + } + }) + } +} + +func Test_GetMaxUnavailableOrDefault(t *testing.T) { + tests := []struct { + name string + fromSpec *int32 + want *int32 + }{ + { + name: "negative in spec results in unbounded", + fromSpec: pointer.Int32(-1), + want: nil, + }, + { + name: "nil in spec results in default, generic", + fromSpec: nil, + want: DefaultChangeBudget.MaxUnavailable, + }, + { + name: "nil in spec results in default, currently 1", + fromSpec: nil, + want: pointer.Int32(1), + }, + { + name: "0 in spec results in 0", + fromSpec: pointer.Int32(0), + want: pointer.Int32(0), + }, + { + name: "1 in spec results in 1", + fromSpec: pointer.Int32(1), + want: pointer.Int32(1), + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := ChangeBudget{MaxUnavailable: tt.fromSpec}.GetMaxUnavailableOrDefault() + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetMaxUnavailableOrDefault() want = %v, got = %v", tt.want, got) + } + }) + } +} diff --git a/pkg/apis/elasticsearch/v1/fields.go b/pkg/apis/elasticsearch/v1/fields.go new file mode 100644 index 00000000000..bbb3904b6bb --- /dev/null +++ b/pkg/apis/elasticsearch/v1/fields.go @@ -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 v1 + +const ( + ClusterName = "cluster.name" + + DiscoveryZenMinimumMasterNodes = "discovery.zen.minimum_master_nodes" + ClusterInitialMasterNodes = "cluster.initial_master_nodes" + + DiscoveryZenHostsProvider = "discovery.zen.hosts_provider" // ES < 7.X + DiscoverySeedProviders = "discovery.seed_providers" // ES >= 7.X + + NetworkHost = "network.host" + NetworkPublishHost = "network.publish_host" + + NodeName = "node.name" + + PathData = "path.data" + PathLogs = "path.logs" + + XPackSecurityAuthcRealmsFileFile1Order = "xpack.security.authc.realms.file.file1.order" // 7.x realm syntax + XPackSecurityAuthcRealmsFile1Order = "xpack.security.authc.realms.file1.order" // 6.x realm syntax + XPackSecurityAuthcRealmsFile1Type = "xpack.security.authc.realms.file1.type" // 6.x realm syntax + XPackSecurityAuthcRealmsNativeNative1Order = "xpack.security.authc.realms.native.native1.order" // 7.x realm syntax + XPackSecurityAuthcRealmsNative1Order = "xpack.security.authc.realms.native1.order" // 6.x realm syntax + XPackSecurityAuthcRealmsNative1Type = "xpack.security.authc.realms.native1.type" // 6.x realm syntax + + XPackSecurityAuthcReservedRealmEnabled = "xpack.security.authc.reserved_realm.enabled" + XPackSecurityEnabled = "xpack.security.enabled" + XPackSecurityHttpSslCertificate = "xpack.security.http.ssl.certificate" + XPackSecurityHttpSslCertificateAuthorities = "xpack.security.http.ssl.certificate_authorities" + XPackSecurityHttpSslEnabled = "xpack.security.http.ssl.enabled" + XPackSecurityHttpSslKey = "xpack.security.http.ssl.key" + XPackSecurityTransportSslCertificate = "xpack.security.transport.ssl.certificate" + XPackSecurityTransportSslCertificateAuthorities = "xpack.security.transport.ssl.certificate_authorities" + XPackSecurityTransportSslEnabled = "xpack.security.transport.ssl.enabled" + XPackSecurityTransportSslKey = "xpack.security.transport.ssl.key" + XPackSecurityTransportSslVerificationMode = "xpack.security.transport.ssl.verification_mode" +) + +var UnsupportedSettings = []string{ + ClusterName, + DiscoveryZenMinimumMasterNodes, + ClusterInitialMasterNodes, + NetworkHost, + NetworkPublishHost, + NodeName, + PathData, + PathLogs, + XPackSecurityAuthcReservedRealmEnabled, + XPackSecurityEnabled, + XPackSecurityHttpSslCertificate, + XPackSecurityHttpSslEnabled, + XPackSecurityHttpSslKey, + XPackSecurityTransportSslCertificate, + XPackSecurityTransportSslEnabled, + XPackSecurityTransportSslKey, + XPackSecurityTransportSslVerificationMode, +} diff --git a/pkg/apis/elasticsearch/v1/groupversion_info.go b/pkg/apis/elasticsearch/v1/groupversion_info.go new file mode 100644 index 00000000000..c3b63176c6e --- /dev/null +++ b/pkg/apis/elasticsearch/v1/groupversion_info.go @@ -0,0 +1,21 @@ +// 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 v1 + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + "sigs.k8s.io/controller-runtime/pkg/scheme" +) + +var ( + // GroupVersion is group version used to register these objects + GroupVersion = schema.GroupVersion{Group: "elasticsearch.k8s.elastic.co", Version: "v1"} + + // SchemeBuilder is used to add go types to the GroupVersionKind scheme + SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} + + // AddToScheme adds the types in this group-version to the given scheme. + AddToScheme = SchemeBuilder.AddToScheme +) diff --git a/pkg/apis/elasticsearch/v1/name.go b/pkg/apis/elasticsearch/v1/name.go new file mode 100644 index 00000000000..e536f1379ca --- /dev/null +++ b/pkg/apis/elasticsearch/v1/name.go @@ -0,0 +1,137 @@ +// 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 v1 + +import ( + "fmt" + "strconv" + "strings" + + common_name "github.com/elastic/cloud-on-k8s/pkg/controller/common/name" + "github.com/pkg/errors" + apimachineryvalidation "k8s.io/apimachinery/pkg/api/validation" + utilvalidation "k8s.io/apimachinery/pkg/util/validation" +) + +const ( + configSecretSuffix = "config" + secureSettingsSecretSuffix = "secure-settings" + httpServiceSuffix = "http" + elasticUserSecretSuffix = "elastic-user" + xpackFileRealmSecretSuffix = "xpack-file-realm" + internalUsersSecretSuffix = "internal-users" + unicastHostsConfigMapSuffix = "unicast-hosts" + licenseSecretSuffix = "license" + defaultPodDisruptionBudget = "default" + scriptsConfigMapSuffix = "scripts" + transportCertificatesSecretSuffix = "transport-certificates" + + controllerRevisionHashLen = 10 +) + +var ( + // ESNamer is a Namer that is configured with the defaults for resources related to an ES cluster. + ESNamer = common_name.NewNamer("es") + + suffixes = []string{ + configSecretSuffix, + secureSettingsSecretSuffix, + httpServiceSuffix, + elasticUserSecretSuffix, + xpackFileRealmSecretSuffix, + internalUsersSecretSuffix, + unicastHostsConfigMapSuffix, + licenseSecretSuffix, + defaultPodDisruptionBudget, + scriptsConfigMapSuffix, + transportCertificatesSecretSuffix, + } +) + +// validateNames checks the validity of resource names that will be generated by the given Elasticsearch object. +func validateNames(es *Elasticsearch) error { + if len(es.Name) > common_name.MaxResourceNameLength { + return fmt.Errorf("name exceeds maximum allowed length of %d", common_name.MaxResourceNameLength) + } + // validate ssets + for _, nodeSet := range es.Spec.NodeSets { + if errs := apimachineryvalidation.NameIsDNSSubdomain(nodeSet.Name, false); len(errs) > 0 { + return fmt.Errorf("invalid nodeSet name '%s': [%s]", nodeSet.Name, strings.Join(errs, ",")) + } + + ssetName, err := ESNamer.SafeSuffix(es.Name, nodeSet.Name) + if err != nil { + return errors.Wrapf(err, "error generating StatefulSet name for nodeSet: '%s'", nodeSet.Name) + } + + // length of the ordinal suffix that will be added to the pods of this sset (dash + ordinal) + podOrdinalSuffixLen := len(strconv.FormatInt(int64(nodeSet.Count), 10)) + 1 + // there should be enough space for the ordinal suffix and the controller revision hash + if utilvalidation.LabelValueMaxLength-len(ssetName) < podOrdinalSuffixLen+controllerRevisionHashLen { + return fmt.Errorf("generated StatefulSet name '%s' exceeds allowed length of %d", + ssetName, + utilvalidation.LabelValueMaxLength-podOrdinalSuffixLen-controllerRevisionHashLen) + } + } + + // validate other suffixes + for _, suffix := range suffixes { + if _, err := ESNamer.SafeSuffix(es.Name, suffix); err != nil { + return err + } + } + + return nil +} + +// StatefulSet returns the name of the StatefulSet corresponding to the given NodeSet. +func StatefulSet(esName string, nodeSetName string) string { + return ESNamer.Suffix(esName, nodeSetName) +} + +func ConfigSecret(ssetName string) string { + return ESNamer.Suffix(ssetName, configSecretSuffix) +} + +func SecureSettingsSecret(esName string) string { + return ESNamer.Suffix(esName, secureSettingsSecretSuffix) +} + +func TransportCertificatesSecret(esName string) string { + return ESNamer.Suffix(esName, transportCertificatesSecretSuffix) +} + +func HTTPService(esName string) string { + return ESNamer.Suffix(esName, httpServiceSuffix) +} + +func ElasticUserSecret(esName string) string { + return ESNamer.Suffix(esName, elasticUserSecretSuffix) +} + +func XPackFileRealmSecret(esName string) string { + return ESNamer.Suffix(esName, xpackFileRealmSecretSuffix) +} + +func InternalUsersSecret(esName string) string { + return ESNamer.Suffix(esName, internalUsersSecretSuffix) +} + +// UnicastHostsConfigMap returns the name of the ConfigMap that holds the list of seed nodes for a given cluster. +func UnicastHostsConfigMap(esName string) string { + return ESNamer.Suffix(esName, unicastHostsConfigMapSuffix) +} + +func ScriptsConfigMap(esName string) string { + return ESNamer.Suffix(esName, scriptsConfigMapSuffix) +} + +func LicenseSecretName(esName string) string { + return ESNamer.Suffix(esName, licenseSecretSuffix) +} + +func DefaultPodDisruptionBudget(esName string) string { + return ESNamer.Suffix(esName, defaultPodDisruptionBudget) +} diff --git a/pkg/apis/elasticsearch/v1/name_test.go b/pkg/apis/elasticsearch/v1/name_test.go new file mode 100644 index 00000000000..83bbe150bb9 --- /dev/null +++ b/pkg/apis/elasticsearch/v1/name_test.go @@ -0,0 +1,74 @@ +// 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 v1 + +import ( + "testing" + + "github.com/stretchr/testify/require" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func TestValidate(t *testing.T) { + testCases := []struct { + name string + esName string + nodeSpecNames []string + wantErr bool + wantErrMsg string + }{ + { + name: "valid configuration", + esName: "test-es", + nodeSpecNames: []string{"default", "ha"}, + wantErr: false, + }, + { + name: "long ES name", + esName: "extremely-long-winded-and-unnecessary-name-for-elasticsearch", + nodeSpecNames: []string{"default", "ha"}, + wantErr: true, + wantErrMsg: "name exceeds maximum allowed length", + }, + { + name: "long nodeSpec name", + esName: "test-es", + nodeSpecNames: []string{"default", "extremely-long-nodespec-name-for-no-particular-reason"}, + wantErr: true, + wantErrMsg: "suffix exceeds max length", + }, + { + name: "invalid characters in nodeSpec name", + esName: "test-es", + nodeSpecNames: []string{"default", "my_ha_set"}, + wantErr: true, + wantErrMsg: "invalid nodeSet name", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + es := &Elasticsearch{ + ObjectMeta: metav1.ObjectMeta{ + Name: tc.esName, + Namespace: "test", + }, + Spec: ElasticsearchSpec{}, + } + + for _, nodeSpecName := range tc.nodeSpecNames { + es.Spec.NodeSets = append(es.Spec.NodeSets, NodeSet{Name: nodeSpecName, Count: 10}) + } + + err := validateNames(es) + if tc.wantErr { + require.Error(t, err) + require.Contains(t, err.Error(), tc.wantErrMsg) + } else { + require.NoError(t, err) + } + }) + } +} diff --git a/pkg/apis/elasticsearch/v1/validations.go b/pkg/apis/elasticsearch/v1/validations.go new file mode 100644 index 00000000000..11949cf6d5a --- /dev/null +++ b/pkg/apis/elasticsearch/v1/validations.go @@ -0,0 +1,218 @@ +// 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 v1 + +import ( + "fmt" + "net" + "reflect" + + "github.com/elastic/cloud-on-k8s/pkg/controller/common/version" + esversion "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/version" + netutil "github.com/elastic/cloud-on-k8s/pkg/utils/net" + "k8s.io/apimachinery/pkg/util/validation/field" +) + +const ( + cfgInvalidMsg = "Configuration invalid" + masterRequiredMsg = "Elasticsearch needs to have at least one master node" + parseVersionErrMsg = "Cannot parse Elasticsearch version" + parseStoredVersionErrMsg = "Cannot parse current Elasticsearch version" + invalidSanIPErrMsg = "Invalid SAN IP address" + pvcImmutableMsg = "Volume claim templates cannot be modified" + invalidNamesErrMsg = "Elasticsearch configuration would generate resources with invalid names" + unsupportedVersionErrMsg = "Unsupported version" + unsupportedConfigErrMsg = "Configuration setting is reserved for internal use. User-configured use is unsupported" + duplicateNodeSets = "NodeSet names must be unique" + noDowngradesMsg = "Downgrades are not supported" + unsupportedVersionMsg = "Unsupported version" + unsupportedUpgradeMsg = "Unsupported version upgrade path" +) + +type validation func(*Elasticsearch) field.ErrorList + +// validations are the validation funcs that apply to creates or updates +var validations = []validation{ + validName, + hasMaster, + supportedVersion, + validSanIP, +} + +type updateValidation func(*Elasticsearch, *Elasticsearch) field.ErrorList + +// updateValidations are the validation funcs that only apply to updates +var updateValidations = []updateValidation{ + noDowngrades, + validUpgradePath, + pvcModification, +} + +func (r *Elasticsearch) check(validations []validation) field.ErrorList { + var errs field.ErrorList + for _, val := range validations { + if err := val(r); err != nil { + errs = append(errs, err...) + } + } + return errs +} + +// validName checks whether the name is valid. +func validName(es *Elasticsearch) field.ErrorList { + var errs field.ErrorList + if err := validateNames(es); err != nil { + errs = append(errs, field.Invalid(field.NewPath("metadata").Child("name"), es.Name, fmt.Sprintf("%s: %s", invalidNamesErrMsg, err))) + } + return errs +} + +func supportedVersion(es *Elasticsearch) field.ErrorList { + ver, err := version.Parse(es.Spec.Version) + if err != nil { + return field.ErrorList{field.Invalid(field.NewPath("spec").Child("version"), es.Spec.Version, parseVersionErrMsg)} + } + if v := esversion.SupportedVersions(*ver); v != nil { + if err := v.Supports(*ver); err == nil { + return field.ErrorList{} + } + } + return field.ErrorList{field.Invalid(field.NewPath("spec").Child("version"), es.Spec.Version, unsupportedVersionErrMsg)} +} + +// hasMaster checks if the given Elasticsearch cluster has at least one master node. +func hasMaster(es *Elasticsearch) field.ErrorList { + var errs field.ErrorList + var hasMaster bool + for i, t := range es.Spec.NodeSets { + cfg, err := UnpackConfig(t.Config) + if err != nil { + errs = append(errs, field.Invalid(field.NewPath("spec").Child("nodeSets").Index(i), t.Config, cfgInvalidMsg)) + } + hasMaster = hasMaster || (cfg.Node.Master && t.Count > 0) + } + if !hasMaster { + errs = append(errs, field.Invalid(field.NewPath("spec").Child("nodeSets"), es.Spec.NodeSets, masterRequiredMsg)) + } + return errs +} + +func validSanIP(es *Elasticsearch) field.ErrorList { + var errs field.ErrorList + selfSignedCerts := es.Spec.HTTP.TLS.SelfSignedCertificate + if selfSignedCerts != nil { + for _, san := range selfSignedCerts.SubjectAlternativeNames { + if san.IP != "" { + ip := netutil.MaybeIPTo4(net.ParseIP(san.IP)) + if ip == nil { + errs = append(errs, field.Invalid(field.NewPath("spec").Child("http", "tls", "selfSignedCertificate", "subjectAlternativeNames"), san.IP, invalidSanIPErrMsg)) + } + } + } + } + return errs +} + +func checkNodeSetNameUniqueness(es *Elasticsearch) field.ErrorList { + var errs field.ErrorList + nodeSets := es.Spec.NodeSets + names := make(map[string]struct{}) + duplicates := make(map[string]struct{}) + for _, nodeSet := range nodeSets { + if _, found := names[nodeSet.Name]; found { + duplicates[nodeSet.Name] = struct{}{} + } + names[nodeSet.Name] = struct{}{} + } + for _, dupe := range duplicates { + errs = append(errs, field.Invalid(field.NewPath("spec").Child("nodeSets"), dupe, duplicateNodeSets)) + } + return errs +} + +// pvcModification ensures no PVCs are changed, as volume claim templates are immutable in stateful sets +func pvcModification(current, proposed *Elasticsearch) field.ErrorList { + var errs field.ErrorList + if current == nil || proposed == nil { + return errs + } + for i, node := range proposed.Spec.NodeSets { + currNode := getNode(node.Name, current) + if currNode == nil { + // this is a new sset, so there is nothing to check + continue + } + + // ssets do not allow modifications to fields other than 'replicas', 'template', and 'updateStrategy' + // reflection isn't ideal, but okay here since the ES object does not have the status of the claims + if !reflect.DeepEqual(node.VolumeClaimTemplates, currNode.VolumeClaimTemplates) { + errs = append(errs, field.Invalid(field.NewPath("spec").Child("nodeSet").Index(i).Child("volumeClaimTemplates"), node.VolumeClaimTemplates, pvcImmutableMsg)) + } + } + return errs +} + +func noDowngrades(current, proposed *Elasticsearch) field.ErrorList { + var errs field.ErrorList + if current == nil || proposed == nil { + return errs + } + currentVer, err := version.Parse(current.Spec.Version) + if err != nil { + // this should not happen, since this is the already persisted version + errs = append(errs, field.Invalid(field.NewPath("spec").Child("version"), current.Spec.Version, parseStoredVersionErrMsg)) + } + currVer, err := version.Parse(proposed.Spec.Version) + if err != nil { + errs = append(errs, field.Invalid(field.NewPath("spec").Child("version"), proposed.Spec.Version, parseVersionErrMsg)) + } + if len(errs) != 0 { + return errs + } + if !currVer.IsSameOrAfter(*currentVer) { + errs = append(errs, field.Invalid(field.NewPath("spec").Child("version"), proposed.Spec.Version, noDowngradesMsg)) + } + return errs +} + +func validUpgradePath(current, proposed *Elasticsearch) field.ErrorList { + var errs field.ErrorList + if current == nil || proposed == nil { + return errs + } + currentVer, err := version.Parse(current.Spec.Version) + if err != nil { + // this should not happen, since this is the already persisted version + errs = append(errs, field.Invalid(field.NewPath("spec").Child("version"), current.Spec.Version, parseStoredVersionErrMsg)) + } + currVer, err := version.Parse(proposed.Spec.Version) + if err != nil { + errs = append(errs, field.Invalid(field.NewPath("spec").Child("version"), proposed.Spec.Version, parseVersionErrMsg)) + } + if len(errs) != 0 { + return errs + } + + v := esversion.SupportedVersions(*currVer) + if v == nil { + errs = append(errs, field.Invalid(field.NewPath("spec").Child("version"), proposed.Spec.Version, unsupportedVersionMsg)) + return errs + } + + err = v.Supports(*currentVer) + if err != nil { + errs = append(errs, field.Invalid(field.NewPath("spec").Child("version"), proposed.Spec.Version, unsupportedUpgradeMsg)) + } + return errs +} + +func getNode(name string, es *Elasticsearch) *NodeSet { + for i := range es.Spec.NodeSets { + if es.Spec.NodeSets[i].Name == name { + return &es.Spec.NodeSets[i] + } + } + return nil +} diff --git a/pkg/apis/elasticsearch/v1/validations_test.go b/pkg/apis/elasticsearch/v1/validations_test.go new file mode 100644 index 00000000000..074b71abb61 --- /dev/null +++ b/pkg/apis/elasticsearch/v1/validations_test.go @@ -0,0 +1,660 @@ +// 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 v1 + +import ( + "testing" + + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func Test_checkNodeSetNameUniqueness(t *testing.T) { + type args struct { + name string + es *Elasticsearch + expectErrors bool + } + tests := []args{ + { + name: "several duplicate nodeSets", + es: &Elasticsearch{ + Spec: ElasticsearchSpec{ + Version: "7.4.0", + NodeSets: []NodeSet{ + {Name: "foo", Count: 1}, {Name: "foo", Count: 1}, + {Name: "bar", Count: 1}, {Name: "bar", Count: 1}, + }, + }, + }, + expectErrors: true, + }, + { + name: "good spec with 1 nodeSet", + es: &Elasticsearch{ + Spec: ElasticsearchSpec{ + Version: "7.4.0", + NodeSets: []NodeSet{{Name: "foo", Count: 1}}, + }, + }, + expectErrors: false, + }, + { + name: "good spec with 2 nodeSets", + es: &Elasticsearch{ + TypeMeta: metav1.TypeMeta{APIVersion: "elasticsearch.k8s.elastic.co/v1"}, + Spec: ElasticsearchSpec{ + Version: "7.4.0", + NodeSets: []NodeSet{{Name: "foo", Count: 1}, {Name: "bar", Count: 1}}, + }, + }, + expectErrors: false, + }, + { + name: "duplicate nodeSet", + es: &Elasticsearch{ + TypeMeta: metav1.TypeMeta{APIVersion: "elasticsearch.k8s.elastic.co/v1"}, + Spec: ElasticsearchSpec{ + Version: "7.4.0", + NodeSets: []NodeSet{{Name: "foo", Count: 1}, {Name: "foo", Count: 1}}, + }, + }, + expectErrors: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + actual := checkNodeSetNameUniqueness(tt.es) + actualErrors := len(actual) > 0 + + if tt.expectErrors != actualErrors { + t.Errorf("failed checkNodeSetNameUniqueness(). Name: %v, actual %v, wanted: %v, value: %v", tt.name, actual, tt.expectErrors, tt.es.Spec.NodeSets) + } + }) + } +} + +func Test_hasMaster(t *testing.T) { + tests := []struct { + name string + es *Elasticsearch + expectErrors bool + }{ + { + name: "no topology", + es: es("6.8.0"), + expectErrors: true, + }, + { + name: "topology but no master", + es: &Elasticsearch{ + Spec: ElasticsearchSpec{ + Version: "7.0.0", + NodeSets: []NodeSet{ + { + Config: &commonv1.Config{ + Data: map[string]interface{}{ + NodeMaster: "false", + NodeData: "false", + NodeIngest: "false", + NodeML: "false", + }, + }, + }, + }, + }, + }, + expectErrors: true, + }, + { + name: "master but zero sized", + es: &Elasticsearch{ + Spec: ElasticsearchSpec{ + Version: "7.0.0", + NodeSets: []NodeSet{ + { + Config: &commonv1.Config{ + Data: map[string]interface{}{ + NodeMaster: "true", + NodeData: "false", + NodeIngest: "false", + NodeML: "false", + }, + }, + }, + }, + }, + }, + expectErrors: true, + }, + { + name: "has master", + es: &Elasticsearch{ + Spec: ElasticsearchSpec{ + Version: "7.0.0", + NodeSets: []NodeSet{ + { + Config: &commonv1.Config{ + Data: map[string]interface{}{ + NodeMaster: "false", + NodeData: "true", + NodeIngest: "false", + NodeML: "false", + }, + }, + Count: 1, + }, + + { + Config: &commonv1.Config{ + Data: map[string]interface{}{ + NodeMaster: "true", + NodeData: "false", + NodeIngest: "false", + NodeML: "false", + }, + }, + Count: 1, + }, + }, + }, + }, + expectErrors: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + actual := hasMaster(tt.es) + actualErrors := len(actual) > 0 + if tt.expectErrors != actualErrors { + t.Errorf("failed hasMaster(). Name: %v, actual %v, wanted: %v, value: %v", tt.name, actual, tt.expectErrors, tt.es.Spec.NodeSets) + } + }) + } +} + +func Test_supportedVersion(t *testing.T) { + tests := []struct { + name string + es *Elasticsearch + expectErrors bool + }{ + { + name: "unsupported minor version should fail", + es: es("6.0.0"), + + expectErrors: true, + }, + { + name: "unsupported major should fail", + es: es("1.0.0"), + expectErrors: true, + }, + { + name: "supported OK", + es: es("6.8.0"), + expectErrors: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + actual := supportedVersion(tt.es) + actualErrors := len(actual) > 0 + if tt.expectErrors != actualErrors { + t.Errorf("failed supportedVersion(). Name: %v, actual %v, wanted: %v, value: %v", tt.name, actual, tt.expectErrors, tt.es.Spec.Version) + } + }) + } +} + +func Test_validName(t *testing.T) { + tests := []struct { + name string + es *Elasticsearch + expectErrors bool + }{ + { + name: "name length too long", + es: &Elasticsearch{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: "default", + Name: "that-is-a-very-long-name-with-37chars", + }, + }, + expectErrors: true, + }, + { + name: "name length OK", + es: &Elasticsearch{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: "default", + Name: "that-is-a-very-long-name-with-36char", + }, + }, + expectErrors: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + actual := validName(tt.es) + actualErrors := len(actual) > 0 + if tt.expectErrors != actualErrors { + t.Errorf("failed validName(). Name: %v, actual %v, wanted: %v, value: %v", tt.name, actual, tt.expectErrors, tt.es.Name) + } + }) + } +} + +func Test_validSanIP(t *testing.T) { + validIP := "3.4.5.6" + validIP2 := "192.168.12.13" + validIPv6 := "2001:db8:0:85a3:0:0:ac1f:8001" + invalidIP := "notanip" + + tests := []struct { + name string + es *Elasticsearch + expectErrors bool + }{ + { + name: "no SAN IP: OK", + es: &Elasticsearch{ + Spec: ElasticsearchSpec{}, + }, + expectErrors: false, + }, + { + name: "valid SAN IPs: OK", + es: &Elasticsearch{ + Spec: ElasticsearchSpec{ + HTTP: commonv1.HTTPConfig{ + TLS: commonv1.TLSOptions{ + SelfSignedCertificate: &commonv1.SelfSignedCertificate{ + SubjectAlternativeNames: []commonv1.SubjectAlternativeName{ + { + IP: validIP, + }, + { + IP: validIP2, + }, + { + IP: validIPv6, + }, + }, + }, + }, + }, + }, + }, + expectErrors: false, + }, + { + name: "invalid SAN IPs: NOT OK", + es: &Elasticsearch{ + Spec: ElasticsearchSpec{ + HTTP: commonv1.HTTPConfig{ + TLS: commonv1.TLSOptions{ + SelfSignedCertificate: &commonv1.SelfSignedCertificate{ + SubjectAlternativeNames: []commonv1.SubjectAlternativeName{ + { + IP: invalidIP, + }, + { + IP: validIP2, + }, + }, + }, + }, + }, + }, + }, + expectErrors: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + actual := validSanIP(tt.es) + actualErrors := len(actual) > 0 + if tt.expectErrors != actualErrors { + t.Errorf("failed validSanIP(). Name: %v, actual %v, wanted: %v, value: %v", tt.name, actual, tt.expectErrors, tt.es.Spec) + } + }) + } +} + +func Test_pvcModified(t *testing.T) { + current := getEsCluster() + + tests := []struct { + name string + current *Elasticsearch + proposed *Elasticsearch + expectErrors bool + }{ + { + name: "resize fails", + current: current, + proposed: &Elasticsearch{ + Spec: ElasticsearchSpec{ + Version: "7.2.0", + NodeSets: []NodeSet{ + { + Name: "master", + VolumeClaimTemplates: []corev1.PersistentVolumeClaim{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "elasticsearch-data", + }, + Spec: corev1.PersistentVolumeClaimSpec{ + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceStorage: resource.MustParse("10Gi"), + }, + }, + }, + }, + }, + }, + }, + }, + }, + expectErrors: true, + }, + + { + name: "same size accepted", + current: current, + proposed: &Elasticsearch{ + Spec: ElasticsearchSpec{ + Version: "7.2.0", + NodeSets: []NodeSet{ + { + Name: "master", + VolumeClaimTemplates: []corev1.PersistentVolumeClaim{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "elasticsearch-data", + }, + Spec: corev1.PersistentVolumeClaimSpec{ + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceStorage: resource.MustParse("5Gi"), + }, + }, + }, + }, + }, + }, + }, + }, + }, + expectErrors: false, + }, + + { + name: "additional PVC fails", + current: current, + proposed: &Elasticsearch{ + Spec: ElasticsearchSpec{ + Version: "7.2.0", + NodeSets: []NodeSet{ + { + Name: "master", + VolumeClaimTemplates: []corev1.PersistentVolumeClaim{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "elasticsearch-data", + }, + Spec: corev1.PersistentVolumeClaimSpec{ + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceStorage: resource.MustParse("5Gi"), + }, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "elasticsearch-data1", + }, + Spec: corev1.PersistentVolumeClaimSpec{ + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceStorage: resource.MustParse("5Gi"), + }, + }, + }, + }, + }, + }, + }, + }, + }, + expectErrors: true, + }, + + { + name: "name change rejected", + current: current, + proposed: &Elasticsearch{ + Spec: ElasticsearchSpec{ + Version: "7.2.0", + NodeSets: []NodeSet{ + { + Name: "master", + VolumeClaimTemplates: []corev1.PersistentVolumeClaim{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "elasticsearch-data1", + }, + Spec: corev1.PersistentVolumeClaimSpec{ + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceStorage: resource.MustParse("5Gi"), + }, + }, + }, + }, + }, + }, + }, + }, + }, + expectErrors: true, + }, + + { + name: "add new node set accepted", + current: current, + proposed: &Elasticsearch{ + Spec: ElasticsearchSpec{ + Version: "7.2.0", + NodeSets: []NodeSet{ + { + Name: "master", + VolumeClaimTemplates: []corev1.PersistentVolumeClaim{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "elasticsearch-data", + }, + Spec: corev1.PersistentVolumeClaimSpec{ + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceStorage: resource.MustParse("5Gi"), + }, + }, + }, + }, + }, + }, + { + Name: "ingest", + VolumeClaimTemplates: []corev1.PersistentVolumeClaim{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "elasticsearch-data", + }, + Spec: corev1.PersistentVolumeClaimSpec{ + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceStorage: resource.MustParse("10Gi"), + }, + }, + }, + }, + }, + }, + }, + }, + }, + expectErrors: false, + }, + + { + name: "new instance accepted", + current: nil, + proposed: current, + expectErrors: false, + }, + } + + for _, tt := range tests { + actual := pvcModification(tt.current, tt.proposed) + actualErrors := len(actual) > 0 + if tt.expectErrors != actualErrors { + t.Errorf("failed pvcModification(). Name: %v, actual %v, wanted: %v, value: %v", tt.name, actual, tt.expectErrors, tt.proposed) + } + } +} + +func TestValidation_noDowngrades(t *testing.T) { + tests := []struct { + name string + current *Elasticsearch + proposed *Elasticsearch + expectErrors bool + }{ + { + name: "no validation on create", + current: nil, + proposed: es("6.8.0"), + expectErrors: false, + }, + { + name: "prevent downgrade", + current: es("2.0.0"), + proposed: es("1.0.0"), + expectErrors: true, + }, + { + name: "allow upgrades", + current: es("1.0.0"), + proposed: es("1.2.0"), + expectErrors: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + actual := noDowngrades(tt.current, tt.proposed) + actualErrors := len(actual) > 0 + if tt.expectErrors != actualErrors { + t.Errorf("failed noDowngrades(). Name: %v, actual %v, wanted: %v, value: %v", tt.name, actual, tt.expectErrors, tt.proposed) + } + }) + } +} + +func Test_validUpgradePath(t *testing.T) { + + tests := []struct { + name string + current *Elasticsearch + proposed *Elasticsearch + expectErrors bool + }{ + { + name: "new cluster accepted", + current: nil, + proposed: es("1.0.0"), + expectErrors: false, + }, + { + name: "unsupported version rejected", + current: es("1.0.0"), + proposed: es("2.0.0"), + + expectErrors: true, + }, + { + name: "too old version rejected", + current: es("6.5.0"), + proposed: es("7.0.0"), + expectErrors: true, + }, + { + name: "too new rejected", + current: es("7.0.0"), + proposed: es("6.5.0"), + expectErrors: true, + }, + { + name: "in range accepted", + current: es("6.8.0"), + proposed: es("7.1.0"), + expectErrors: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + actual := validUpgradePath(tt.current, tt.proposed) + actualErrors := len(actual) > 0 + if tt.expectErrors != actualErrors { + t.Errorf("failed validUpgradePath(). Name: %v, actual %v, wanted: %v, value: %v", tt.name, actual, tt.expectErrors, tt.proposed) + } + }) + } +} + +// es returns an es fixture at a given version +func es(v string) *Elasticsearch { + return &Elasticsearch{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: "default", + Name: "foo", + }, + Spec: ElasticsearchSpec{Version: v}, + } +} + +// // getEsCluster returns a ES cluster test fixture +func getEsCluster() *Elasticsearch { + return &Elasticsearch{ + Spec: ElasticsearchSpec{ + Version: "7.2.0", + NodeSets: []NodeSet{ + { + Name: "master", + VolumeClaimTemplates: []corev1.PersistentVolumeClaim{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "elasticsearch-data", + }, + Spec: corev1.PersistentVolumeClaimSpec{ + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceStorage: resource.MustParse("5Gi"), + }, + }, + }, + }, + }, + }, + }, + }, + } +} diff --git a/pkg/apis/elasticsearch/v1/warnings.go b/pkg/apis/elasticsearch/v1/warnings.go new file mode 100644 index 00000000000..4abdac4e386 --- /dev/null +++ b/pkg/apis/elasticsearch/v1/warnings.go @@ -0,0 +1,41 @@ +// 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 v1 + +import ( + common "github.com/elastic/cloud-on-k8s/pkg/controller/common/settings" + "k8s.io/apimachinery/pkg/util/validation/field" +) + +var warnings = []validation{ + noUnsupportedSettings, +} + +func noUnsupportedSettings(es *Elasticsearch) field.ErrorList { + var errs field.ErrorList + for i, nodeSet := range es.Spec.NodeSets { + if nodeSet.Config == nil { + continue + } + config, err := common.NewCanonicalConfigFrom(nodeSet.Config.Data) + if err != nil { + errs = append(errs, field.Invalid(field.NewPath("spec").Child("nodeSets").Index(i).Child("config"), es.Spec.NodeSets[i].Config, cfgInvalidMsg)) + continue + } + unsupported := config.HasKeys(UnsupportedSettings) + for _, setting := range unsupported { + errs = append(errs, field.Forbidden(field.NewPath("spec").Child("nodeSets").Index(i).Child("config").Child(setting), unsupportedConfigErrMsg)) + } + } + return errs +} + +func (r *Elasticsearch) CheckForWarnings() error { + warnings := r.check(warnings) + if len(warnings) > 0 { + return warnings.ToAggregate() + } + return nil +} diff --git a/pkg/apis/elasticsearch/v1/warnings_test.go b/pkg/apis/elasticsearch/v1/warnings_test.go new file mode 100644 index 00000000000..19d5d78d0f9 --- /dev/null +++ b/pkg/apis/elasticsearch/v1/warnings_test.go @@ -0,0 +1,136 @@ +// 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 v1 + +import ( + "testing" + + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" +) + +func Test_noUnsupportedSettings(t *testing.T) { + tests := []struct { + name string + es *Elasticsearch + expectErrors bool + }{ + + { + name: "no settings OK", + es: es("7.0.0"), + expectErrors: false, + }, + { + name: "warn of unsupported setting FAIL", + es: &Elasticsearch{ + Spec: ElasticsearchSpec{ + Version: "7.0.0", + NodeSets: []NodeSet{ + { + Config: &commonv1.Config{ + Data: map[string]interface{}{ + ClusterInitialMasterNodes: "foo", + }, + }, + Count: 1, + }, + }, + }, + }, + expectErrors: true, + }, + { + name: "warn of unsupported in multiple nodes FAIL", + es: &Elasticsearch{ + Spec: ElasticsearchSpec{ + Version: "7.0.0", + NodeSets: []NodeSet{ + { + Config: &commonv1.Config{ + Data: map[string]interface{}{ + ClusterInitialMasterNodes: "foo", + }, + }, + }, + { + Config: &commonv1.Config{ + Data: map[string]interface{}{ + XPackSecurityTransportSslVerificationMode: "bar", + }, + }, + }, + }, + }, + }, + expectErrors: true, + }, + { + name: "non unsupported setting OK", + es: &Elasticsearch{ + Spec: ElasticsearchSpec{ + Version: "7.0.0", + NodeSets: []NodeSet{ + { + Config: &commonv1.Config{ + Data: map[string]interface{}{ + "node.attr.box_type": "foo", + }, + }, + }, + }, + }, + }, + expectErrors: false, + }, + { + name: "supported settings with unsupported string prefix OK", + es: &Elasticsearch{ + Spec: ElasticsearchSpec{ + Version: "7.0.0", + NodeSets: []NodeSet{ + { + Config: &commonv1.Config{ + Data: map[string]interface{}{ + XPackSecurityTransportSslCertificateAuthorities: "foo", + }, + }, + }, + }, + }, + }, + expectErrors: false, + }, + { + name: "settings are canonicalized before validation", + es: &Elasticsearch{ + Spec: ElasticsearchSpec{ + Version: "7.0.0", + NodeSets: []NodeSet{ + { + Config: &commonv1.Config{ + Data: map[string]interface{}{ + "cluster": map[string]interface{}{ + "initial_master_nodes": []string{"foo", "bar"}, + }, + "node.attr.box_type": "foo", + }, + }, + }, + }, + }, + }, + expectErrors: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + actual := noUnsupportedSettings(tt.es) + actualErrors := len(actual) > 0 + if tt.expectErrors != actualErrors { + t.Errorf("failed noUnsupportedSettings(). Name: %v, actual %v, wanted: %v, value: %v", tt.name, actual, tt.expectErrors, tt.es.Spec.Version) + } + }) + } +} diff --git a/pkg/apis/elasticsearch/v1/webhook.go b/pkg/apis/elasticsearch/v1/webhook.go new file mode 100644 index 00000000000..aee18ceefb5 --- /dev/null +++ b/pkg/apis/elasticsearch/v1/webhook.go @@ -0,0 +1,72 @@ +// 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 v1 + +import ( + "errors" + + apierrors "k8s.io/apimachinery/pkg/api/errors" + runtime "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/util/validation/field" + ctrl "sigs.k8s.io/controller-runtime" + logf "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/webhook" +) + +// +kubebuilder:webhook:path=/validate-elasticsearch-k8s-elastic-co-v1-elasticsearch,mutating=false,failurePolicy=ignore,groups=elasticsearch.k8s.elastic.co,resources=elasticsearches,verbs=create;update,versions=v1,name=elastic-es-validation.k8s.elastic.co + +func (r *Elasticsearch) SetupWebhookWithManager(mgr ctrl.Manager) error { + return ctrl.NewWebhookManagedBy(mgr). + For(r). + Complete() +} + +var eslog = logf.Log.WithName("es-validation") + +var _ webhook.Validator = &Elasticsearch{} + +func (r *Elasticsearch) ValidateCreate() error { + eslog.V(1).Info("validate create", "name", r.Name) + return r.validateElasticsearch() +} + +// ValidateDelete is required to implement webhook.Validator, but we do not actually validate deletes +func (r *Elasticsearch) ValidateDelete() error { + return nil +} + +func (r *Elasticsearch) ValidateUpdate(old runtime.Object) error { + eslog.V(1).Info("validate update", "name", r.Name) + oldEs, ok := old.(*Elasticsearch) + if !ok { + return errors.New("cannot cast old object to Elasticsearch type") + } + + var errs field.ErrorList + for _, val := range updateValidations { + if err := val(oldEs, r); err != nil { + errs = append(errs, err...) + } + } + if len(errs) > 0 { + return apierrors.NewInvalid( + schema.GroupKind{Group: "elasticsearch.k8s.elastic.co", Kind: "Elasticsearch"}, + r.Name, errs) + } + return r.validateElasticsearch() +} + +func (r *Elasticsearch) validateElasticsearch() error { + errs := r.check(validations) + if len(errs) > 0 { + return apierrors.NewInvalid( + schema.GroupKind{Group: "elasticsearch.k8s.elastic.co", Kind: "Elasticsearch"}, + r.Name, + errs, + ) + } + return nil +} diff --git a/pkg/apis/elasticsearch/v1/zz_generated.deepcopy.go b/pkg/apis/elasticsearch/v1/zz_generated.deepcopy.go new file mode 100644 index 00000000000..c157ac82d2c --- /dev/null +++ b/pkg/apis/elasticsearch/v1/zz_generated.deepcopy.go @@ -0,0 +1,261 @@ +// +build !ignore_autogenerated + +// 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. + +// Code generated by controller-gen. DO NOT EDIT. + +package v1 + +import ( + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ChangeBudget) DeepCopyInto(out *ChangeBudget) { + *out = *in + if in.MaxUnavailable != nil { + in, out := &in.MaxUnavailable, &out.MaxUnavailable + *out = new(int32) + **out = **in + } + if in.MaxSurge != nil { + in, out := &in.MaxSurge, &out.MaxSurge + *out = new(int32) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ChangeBudget. +func (in *ChangeBudget) DeepCopy() *ChangeBudget { + if in == nil { + return nil + } + out := new(ChangeBudget) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ClusterSettings) DeepCopyInto(out *ClusterSettings) { + *out = *in + if in.InitialMasterNodes != nil { + in, out := &in.InitialMasterNodes, &out.InitialMasterNodes + *out = make([]string, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterSettings. +func (in *ClusterSettings) DeepCopy() *ClusterSettings { + if in == nil { + return nil + } + out := new(ClusterSettings) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Elasticsearch) DeepCopyInto(out *Elasticsearch) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + out.Status = in.Status +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Elasticsearch. +func (in *Elasticsearch) DeepCopy() *Elasticsearch { + if in == nil { + return nil + } + out := new(Elasticsearch) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Elasticsearch) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ElasticsearchList) DeepCopyInto(out *ElasticsearchList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Elasticsearch, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ElasticsearchList. +func (in *ElasticsearchList) DeepCopy() *ElasticsearchList { + if in == nil { + return nil + } + out := new(ElasticsearchList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ElasticsearchList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ElasticsearchSettings) DeepCopyInto(out *ElasticsearchSettings) { + *out = *in + out.Node = in.Node + in.Cluster.DeepCopyInto(&out.Cluster) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ElasticsearchSettings. +func (in *ElasticsearchSettings) DeepCopy() *ElasticsearchSettings { + if in == nil { + return nil + } + out := new(ElasticsearchSettings) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ElasticsearchSpec) DeepCopyInto(out *ElasticsearchSpec) { + *out = *in + in.HTTP.DeepCopyInto(&out.HTTP) + if in.NodeSets != nil { + in, out := &in.NodeSets, &out.NodeSets + *out = make([]NodeSet, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + in.UpdateStrategy.DeepCopyInto(&out.UpdateStrategy) + if in.PodDisruptionBudget != nil { + in, out := &in.PodDisruptionBudget, &out.PodDisruptionBudget + *out = new(commonv1.PodDisruptionBudgetTemplate) + (*in).DeepCopyInto(*out) + } + if in.SecureSettings != nil { + in, out := &in.SecureSettings, &out.SecureSettings + *out = make([]commonv1.SecretSource, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ElasticsearchSpec. +func (in *ElasticsearchSpec) DeepCopy() *ElasticsearchSpec { + if in == nil { + return nil + } + out := new(ElasticsearchSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ElasticsearchStatus) DeepCopyInto(out *ElasticsearchStatus) { + *out = *in + out.ReconcilerStatus = in.ReconcilerStatus +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ElasticsearchStatus. +func (in *ElasticsearchStatus) DeepCopy() *ElasticsearchStatus { + if in == nil { + return nil + } + out := new(ElasticsearchStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Node) DeepCopyInto(out *Node) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Node. +func (in *Node) DeepCopy() *Node { + if in == nil { + return nil + } + out := new(Node) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NodeSet) DeepCopyInto(out *NodeSet) { + *out = *in + if in.Config != nil { + in, out := &in.Config, &out.Config + *out = (*in).DeepCopy() + } + in.PodTemplate.DeepCopyInto(&out.PodTemplate) + if in.VolumeClaimTemplates != nil { + in, out := &in.VolumeClaimTemplates, &out.VolumeClaimTemplates + *out = make([]corev1.PersistentVolumeClaim, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeSet. +func (in *NodeSet) DeepCopy() *NodeSet { + if in == nil { + return nil + } + out := new(NodeSet) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *UpdateStrategy) DeepCopyInto(out *UpdateStrategy) { + *out = *in + in.ChangeBudget.DeepCopyInto(&out.ChangeBudget) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UpdateStrategy. +func (in *UpdateStrategy) DeepCopy() *UpdateStrategy { + if in == nil { + return nil + } + out := new(UpdateStrategy) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ZenDiscoveryStatus) DeepCopyInto(out *ZenDiscoveryStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ZenDiscoveryStatus. +func (in *ZenDiscoveryStatus) DeepCopy() *ZenDiscoveryStatus { + if in == nil { + return nil + } + out := new(ZenDiscoveryStatus) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/apis/elasticsearch/v1beta1/elasticsearch_types.go b/pkg/apis/elasticsearch/v1beta1/elasticsearch_types.go index 636458be167..e90432d399c 100644 --- a/pkg/apis/elasticsearch/v1beta1/elasticsearch_types.go +++ b/pkg/apis/elasticsearch/v1beta1/elasticsearch_types.go @@ -214,7 +214,6 @@ func (es ElasticsearchStatus) IsDegraded(prev ElasticsearchStatus) bool { // +kubebuilder:printcolumn:name="version",type="string",JSONPath=".spec.version",description="Elasticsearch version" // +kubebuilder:printcolumn:name="phase",type="string",JSONPath=".status.phase" // +kubebuilder:printcolumn:name="age",type="date",JSONPath=".metadata.creationTimestamp" -// +kubebuilder:storageversion type Elasticsearch struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` diff --git a/pkg/apis/elasticsearch/v1beta1/webhook.go b/pkg/apis/elasticsearch/v1beta1/webhook.go index 431e6388474..a0293db036d 100644 --- a/pkg/apis/elasticsearch/v1beta1/webhook.go +++ b/pkg/apis/elasticsearch/v1beta1/webhook.go @@ -16,7 +16,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/webhook" ) -// +kubebuilder:webhook:path=/validate-elasticsearch,mutating=false,failurePolicy=ignore,groups=elasticsearch.k8s.elastic.co,resources=elasticsearches,verbs=create;update,versions=v1beta1,name=elastic-es-validation.k8s.elastic.co +// +kubebuilder:webhook:path=/validate-elasticsearch-k8s-elastic-co-v1beta1-elasticsearch,mutating=false,failurePolicy=ignore,groups=elasticsearch.k8s.elastic.co,resources=elasticsearches,verbs=create;update,versions=v1beta1,name=elastic-es-validation.k8s.elastic.co func (r *Elasticsearch) SetupWebhookWithManager(mgr ctrl.Manager) error { return ctrl.NewWebhookManagedBy(mgr). diff --git a/pkg/apis/kibana/v1/doc.go b/pkg/apis/kibana/v1/doc.go new file mode 100644 index 00000000000..47486e70db0 --- /dev/null +++ b/pkg/apis/kibana/v1/doc.go @@ -0,0 +1,8 @@ +// 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 v1 contains API schema definitions for managing Kibana resources. +// +kubebuilder:object:generate=true +// +groupName=kibana.k8s.elastic.co +package v1 diff --git a/pkg/apis/kibana/v1/groupversion_info.go b/pkg/apis/kibana/v1/groupversion_info.go new file mode 100644 index 00000000000..9d1087ebfe9 --- /dev/null +++ b/pkg/apis/kibana/v1/groupversion_info.go @@ -0,0 +1,21 @@ +// 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 v1 + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + "sigs.k8s.io/controller-runtime/pkg/scheme" +) + +var ( + // GroupVersion is group version used to register these objects + GroupVersion = schema.GroupVersion{Group: "kibana.k8s.elastic.co", Version: "v1"} + + // SchemeBuilder is used to add go types to the GroupVersionKind scheme + SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} + + // AddToScheme adds the types in this group-version to the given scheme. + AddToScheme = SchemeBuilder.AddToScheme +) diff --git a/pkg/apis/kibana/v1/kibana_types.go b/pkg/apis/kibana/v1/kibana_types.go new file mode 100644 index 00000000000..38553a5850a --- /dev/null +++ b/pkg/apis/kibana/v1/kibana_types.go @@ -0,0 +1,123 @@ +// 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 v1 + +import ( + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" +) + +const KibanaContainerName = "kibana" + +// KibanaSpec holds the specification of a Kibana instance. +type KibanaSpec struct { + // Version of Kibana. + Version string `json:"version,omitempty"` + + // Image is the Kibana Docker image to deploy. + Image string `json:"image,omitempty"` + + // Count of Kibana instances to deploy. + Count int32 `json:"count,omitempty"` + + // ElasticsearchRef is a reference to an Elasticsearch cluster running in the same Kubernetes cluster. + ElasticsearchRef commonv1.ObjectSelector `json:"elasticsearchRef,omitempty"` + + // Config holds the Kibana configuration. See: https://www.elastic.co/guide/en/kibana/current/settings.html + Config *commonv1.Config `json:"config,omitempty"` + + // HTTP holds the HTTP layer configuration for Kibana. + HTTP commonv1.HTTPConfig `json:"http,omitempty"` + + // PodTemplate provides customisation options (labels, annotations, affinity rules, resource requests, and so on) for the Kibana pods + // +kubebuilder:validation:Optional + PodTemplate corev1.PodTemplateSpec `json:"podTemplate,omitempty"` + + // SecureSettings is a list of references to Kubernetes secrets containing sensitive configuration options for Kibana. + // See: https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-kibana.html#k8s-kibana-secure-settings + SecureSettings []commonv1.SecretSource `json:"secureSettings,omitempty"` +} + +// KibanaHealth expresses the status of the Kibana instances. +type KibanaHealth string + +const ( + // KibanaRed means no instance is currently available. + KibanaRed KibanaHealth = "red" + // KibanaGreen means at least one instance is available. + KibanaGreen KibanaHealth = "green" +) + +// KibanaStatus defines the observed state of Kibana +type KibanaStatus struct { + commonv1.ReconcilerStatus `json:",inline"` + Health KibanaHealth `json:"health,omitempty"` + AssociationStatus commonv1.AssociationStatus `json:"associationStatus,omitempty"` +} + +// IsDegraded returns true if the current status is worse than the previous. +func (ks KibanaStatus) IsDegraded(prev KibanaStatus) bool { + return prev.Health == KibanaGreen && ks.Health != KibanaGreen +} + +// IsMarkedForDeletion returns true if the Kibana is going to be deleted +func (k Kibana) IsMarkedForDeletion() bool { + return !k.DeletionTimestamp.IsZero() +} + +func (k *Kibana) ElasticsearchRef() commonv1.ObjectSelector { + return k.Spec.ElasticsearchRef +} + +func (k *Kibana) SecureSettings() []commonv1.SecretSource { + return k.Spec.SecureSettings +} + +func (k *Kibana) AssociationConf() *commonv1.AssociationConf { + return k.assocConf +} + +func (k *Kibana) SetAssociationConf(assocConf *commonv1.AssociationConf) { + k.assocConf = assocConf +} + +// RequiresAssociation returns true if the spec specifies an Elasticsearch reference. +func (k *Kibana) RequiresAssociation() bool { + return k.Spec.ElasticsearchRef.Name != "" +} + +// +kubebuilder:object:root=true + +// Kibana represents a Kibana resource in a Kubernetes cluster. +// +kubebuilder:resource:categories=elastic,shortName=kb +// +kubebuilder:subresource:status +// +kubebuilder:printcolumn:name="health",type="string",JSONPath=".status.health" +// +kubebuilder:printcolumn:name="nodes",type="integer",JSONPath=".status.availableNodes",description="Available nodes" +// +kubebuilder:printcolumn:name="version",type="string",JSONPath=".spec.version",description="Kibana version" +// +kubebuilder:printcolumn:name="age",type="date",JSONPath=".metadata.creationTimestamp" +// +kubebuilder:storageversion +type Kibana struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec KibanaSpec `json:"spec,omitempty"` + Status KibanaStatus `json:"status,omitempty"` + assocConf *commonv1.AssociationConf `json:"-"` //nolint:govet +} + +// +kubebuilder:object:root=true + +// KibanaList contains a list of Kibana +type KibanaList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []Kibana `json:"items"` +} + +func init() { + SchemeBuilder.Register(&Kibana{}, &KibanaList{}) +} diff --git a/pkg/apis/kibana/v1/zz_generated.deepcopy.go b/pkg/apis/kibana/v1/zz_generated.deepcopy.go new file mode 100644 index 00000000000..d00d1ace44f --- /dev/null +++ b/pkg/apis/kibana/v1/zz_generated.deepcopy.go @@ -0,0 +1,123 @@ +// +build !ignore_autogenerated + +// 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. + +// Code generated by controller-gen. DO NOT EDIT. + +package v1 + +import ( + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Kibana) DeepCopyInto(out *Kibana) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + out.Status = in.Status + if in.assocConf != nil { + in, out := &in.assocConf, &out.assocConf + *out = new(commonv1.AssociationConf) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Kibana. +func (in *Kibana) DeepCopy() *Kibana { + if in == nil { + return nil + } + out := new(Kibana) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Kibana) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KibanaList) DeepCopyInto(out *KibanaList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Kibana, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KibanaList. +func (in *KibanaList) DeepCopy() *KibanaList { + if in == nil { + return nil + } + out := new(KibanaList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *KibanaList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KibanaSpec) DeepCopyInto(out *KibanaSpec) { + *out = *in + out.ElasticsearchRef = in.ElasticsearchRef + if in.Config != nil { + in, out := &in.Config, &out.Config + *out = (*in).DeepCopy() + } + in.HTTP.DeepCopyInto(&out.HTTP) + in.PodTemplate.DeepCopyInto(&out.PodTemplate) + if in.SecureSettings != nil { + in, out := &in.SecureSettings, &out.SecureSettings + *out = make([]commonv1.SecretSource, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KibanaSpec. +func (in *KibanaSpec) DeepCopy() *KibanaSpec { + if in == nil { + return nil + } + out := new(KibanaSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KibanaStatus) DeepCopyInto(out *KibanaStatus) { + *out = *in + out.ReconcilerStatus = in.ReconcilerStatus +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KibanaStatus. +func (in *KibanaStatus) DeepCopy() *KibanaStatus { + if in == nil { + return nil + } + out := new(KibanaStatus) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/apis/kibana/v1beta1/kibana_types.go b/pkg/apis/kibana/v1beta1/kibana_types.go index 6348e82965e..86409ed75db 100644 --- a/pkg/apis/kibana/v1beta1/kibana_types.go +++ b/pkg/apis/kibana/v1beta1/kibana_types.go @@ -99,7 +99,6 @@ func (k *Kibana) RequiresAssociation() bool { // +kubebuilder:printcolumn:name="nodes",type="integer",JSONPath=".status.availableNodes",description="Available nodes" // +kubebuilder:printcolumn:name="version",type="string",JSONPath=".spec.version",description="Kibana version" // +kubebuilder:printcolumn:name="age",type="date",JSONPath=".metadata.creationTimestamp" -// +kubebuilder:storageversion type Kibana struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` diff --git a/pkg/controller/apmserver/apmserver_controller.go b/pkg/controller/apmserver/apmserver_controller.go index d57a69b4ef4..63dbc9d055e 100644 --- a/pkg/controller/apmserver/apmserver_controller.go +++ b/pkg/controller/apmserver/apmserver_controller.go @@ -11,7 +11,7 @@ import ( "reflect" "sync/atomic" - apmv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1beta1" + apmv1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1" apmcerts "github.com/elastic/cloud-on-k8s/pkg/controller/apmserver/certificates" "github.com/elastic/cloud-on-k8s/pkg/controller/apmserver/config" "github.com/elastic/cloud-on-k8s/pkg/controller/apmserver/labels" @@ -97,7 +97,7 @@ func newReconciler(mgr manager.Manager, params operator.Parameters) *ReconcileAp func addWatches(c controller.Controller, r *ReconcileApmServer) error { // Watch for changes to ApmServer - err := c.Watch(&source.Kind{Type: &apmv1beta1.ApmServer{}}, &handler.EnqueueRequestForObject{}) + err := c.Watch(&source.Kind{Type: &apmv1.ApmServer{}}, &handler.EnqueueRequestForObject{}) if err != nil { return err } @@ -105,7 +105,7 @@ func addWatches(c controller.Controller, r *ReconcileApmServer) error { // Watch Deployments if err := c.Watch(&source.Kind{Type: &appsv1.Deployment{}}, &handler.EnqueueRequestForOwner{ IsController: true, - OwnerType: &apmv1beta1.ApmServer{}, + OwnerType: &apmv1.ApmServer{}, }); err != nil { return err } @@ -113,7 +113,7 @@ func addWatches(c controller.Controller, r *ReconcileApmServer) error { // Watch services if err := c.Watch(&source.Kind{Type: &corev1.Service{}}, &handler.EnqueueRequestForOwner{ IsController: true, - OwnerType: &apmv1beta1.ApmServer{}, + OwnerType: &apmv1.ApmServer{}, }); err != nil { return err } @@ -121,7 +121,7 @@ func addWatches(c controller.Controller, r *ReconcileApmServer) error { // Watch secrets if err := c.Watch(&source.Kind{Type: &corev1.Secret{}}, &handler.EnqueueRequestForOwner{ IsController: true, - OwnerType: &apmv1beta1.ApmServer{}, + OwnerType: &apmv1.ApmServer{}, }); err != nil { return err } @@ -176,7 +176,7 @@ var _ driver.Interface = &ReconcileApmServer{} func (r *ReconcileApmServer) Reconcile(request reconcile.Request) (reconcile.Result, error) { defer common.LogReconciliationRun(log, request, &r.iteration)() - var as apmv1beta1.ApmServer + var as apmv1.ApmServer if ok, err := association.FetchWithAssociation(r.Client, request, &as); !ok { if err != nil { return reconcile.Result{}, err @@ -216,7 +216,7 @@ func (r *ReconcileApmServer) Reconcile(request reconcile.Request) (reconcile.Res return r.doReconcile(request, &as) } -func (r *ReconcileApmServer) isCompatible(as *apmv1beta1.ApmServer) (bool, error) { +func (r *ReconcileApmServer) isCompatible(as *apmv1.ApmServer) (bool, error) { selector := map[string]string{labels.ApmServerNameLabelName: as.Name} compat, err := annotation.ReconcileCompatibility(r.Client, as, selector, r.OperatorInfo.BuildInfo.Version) if err != nil { @@ -225,7 +225,7 @@ func (r *ReconcileApmServer) isCompatible(as *apmv1beta1.ApmServer) (bool, error return compat, err } -func (r *ReconcileApmServer) doReconcile(request reconcile.Request, as *apmv1beta1.ApmServer) (reconcile.Result, error) { +func (r *ReconcileApmServer) doReconcile(request reconcile.Request, as *apmv1.ApmServer) (reconcile.Result, error) { state := NewState(request, as) svc, err := common.ReconcileService(r.Client, r.scheme, NewService(*as), as) if err != nil { @@ -266,7 +266,7 @@ func (r *ReconcileApmServer) onDelete(obj types.NamespacedName) { r.dynamicWatches.Secrets.RemoveHandlerForKey(keystore.SecureSettingsWatchName(obj)) } -func (r *ReconcileApmServer) reconcileApmServerSecret(as *apmv1beta1.ApmServer) (*corev1.Secret, error) { +func (r *ReconcileApmServer) reconcileApmServerSecret(as *apmv1.ApmServer) (*corev1.Secret, error) { expectedApmServerSecret := &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Namespace: as.Namespace, @@ -323,7 +323,7 @@ func (r *ReconcileApmServer) reconcileApmServerSecret(as *apmv1beta1.ApmServer) } func (r *ReconcileApmServer) deploymentParams( - as *apmv1beta1.ApmServer, + as *apmv1.ApmServer, params PodSpecParams, ) (deployment.Params, error) { @@ -390,7 +390,7 @@ func (r *ReconcileApmServer) deploymentParams( } httpCertsVolume := http.HTTPCertSecretVolume(apmname.APMNamer, as.Name) podSpec.Spec.Volumes = append(podSpec.Spec.Volumes, httpCertsVolume.Volume()) - apmServerContainer := pod.ContainerByName(podSpec.Spec, apmv1beta1.APMServerContainerName) + apmServerContainer := pod.ContainerByName(podSpec.Spec, apmv1.ApmServerContainerName) apmServerContainer.VolumeMounts = append(apmServerContainer.VolumeMounts, httpCertsVolume.VolumeMount()) } @@ -412,7 +412,7 @@ func (r *ReconcileApmServer) deploymentParams( func (r *ReconcileApmServer) reconcileApmServerDeployment( state State, - as *apmv1beta1.ApmServer, + as *apmv1.ApmServer, ) (State, error) { reconciledApmServerSecret, err := r.reconcileApmServerSecret(as) if err != nil { diff --git a/pkg/controller/apmserver/apmserver_controller_test.go b/pkg/controller/apmserver/apmserver_controller_test.go index 567f120a105..8addc4862ab 100644 --- a/pkg/controller/apmserver/apmserver_controller_test.go +++ b/pkg/controller/apmserver/apmserver_controller_test.go @@ -7,7 +7,7 @@ package apmserver import ( "testing" - apmv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1beta1" + apmv1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates/http" "github.com/elastic/cloud-on-k8s/pkg/controller/common/defaults" @@ -143,7 +143,7 @@ func expectedDeploymentParams() testParams { MountPath: "/mnt/elastic-internal/http-certs", }, }, - Name: apmv1beta1.APMServerContainerName, + Name: apmv1.ApmServerContainerName, Image: "docker.elastic.co/apm/apm-server:1.0", Command: []string{ "apm-server", @@ -191,7 +191,7 @@ func expectedDeploymentParams() testParams { } func TestReconcileApmServer_deploymentParams(t *testing.T) { - apmFixture := &apmv1beta1.ApmServer{ + apmFixture := &apmv1.ApmServer{ ObjectMeta: v1.ObjectMeta{ Name: "test-apm-server", }, @@ -215,7 +215,7 @@ func TestReconcileApmServer_deploymentParams(t *testing.T) { } type args struct { - as *apmv1beta1.ApmServer + as *apmv1.ApmServer podSpecParams PodSpecParams initialObjects []runtime.Object } @@ -365,7 +365,7 @@ func TestReconcileApmServer_doReconcile(t *testing.T) { } tests := []struct { name string - as apmv1beta1.ApmServer + as apmv1.ApmServer fields fields args args wantRequeue bool @@ -373,7 +373,7 @@ func TestReconcileApmServer_doReconcile(t *testing.T) { }{ { name: "If no error ensure a requeue is scheduled for CA", - as: apmv1beta1.ApmServer{ + as: apmv1.ApmServer{ ObjectMeta: metav1.ObjectMeta{ Name: "apmserver", Namespace: "default", diff --git a/pkg/controller/apmserver/certificates/reconcile.go b/pkg/controller/apmserver/certificates/reconcile.go index 60fe314ba4f..fb16b96a607 100644 --- a/pkg/controller/apmserver/certificates/reconcile.go +++ b/pkg/controller/apmserver/certificates/reconcile.go @@ -7,21 +7,22 @@ package certificates import ( "time" - "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1beta1" + corev1 "k8s.io/api/core/v1" + "sigs.k8s.io/controller-runtime/pkg/reconcile" + + apmv1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/apmserver/labels" "github.com/elastic/cloud-on-k8s/pkg/controller/apmserver/name" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates/http" "github.com/elastic/cloud-on-k8s/pkg/controller/common/driver" "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" - coverv1 "k8s.io/api/core/v1" - "sigs.k8s.io/controller-runtime/pkg/reconcile" ) func Reconcile( driver driver.Interface, - apm *v1beta1.ApmServer, - services []coverv1.Service, + apm *apmv1.ApmServer, + services []corev1.Service, rotation certificates.RotationParams, ) reconciler.Results { results := reconciler.Results{} diff --git a/pkg/controller/apmserver/config/config.go b/pkg/controller/apmserver/config/config.go index dcae290b69a..ace6f426ac7 100644 --- a/pkg/controller/apmserver/config/config.go +++ b/pkg/controller/apmserver/config/config.go @@ -9,8 +9,8 @@ import ( "path" "path/filepath" - "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1beta1" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" + apmv1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/association" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates/http" @@ -33,10 +33,10 @@ const ( APMServerSSLCertificate = "apm-server.ssl.certificate" ) -func NewConfigFromSpec(c k8s.Client, as *v1beta1.ApmServer) (*settings.CanonicalConfig, error) { +func NewConfigFromSpec(c k8s.Client, as *apmv1.ApmServer) (*settings.CanonicalConfig, error) { specConfig := as.Spec.Config if specConfig == nil { - specConfig = &commonv1beta1.Config{} + specConfig = &commonv1.Config{} } userSettings, err := settings.NewCanonicalConfigFrom(specConfig.Data) @@ -84,7 +84,7 @@ func NewConfigFromSpec(c k8s.Client, as *v1beta1.ApmServer) (*settings.Canonical return cfg, nil } -func tlsSettings(as *v1beta1.ApmServer) map[string]interface{} { +func tlsSettings(as *apmv1.ApmServer) map[string]interface{} { if !as.Spec.HTTP.TLS.Enabled() { return nil } diff --git a/pkg/controller/apmserver/config/config_test.go b/pkg/controller/apmserver/config/config_test.go index 2cba9dba44d..36e0105e280 100644 --- a/pkg/controller/apmserver/config/config_test.go +++ b/pkg/controller/apmserver/config/config_test.go @@ -7,20 +7,21 @@ package config import ( "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1beta1" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/settings" - "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/stretchr/testify/require" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + apmv1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/settings" + "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" ) func TestNewConfigFromSpec(t *testing.T) { testCases := []struct { name string configOverrides map[string]interface{} - assocConf *commonv1beta1.AssociationConf + assocConf *commonv1.AssociationConf wantConf map[string]interface{} wantErr bool }{ @@ -38,7 +39,7 @@ func TestNewConfigFromSpec(t *testing.T) { }, { name: "without Elasticsearch CA cert", - assocConf: &commonv1beta1.AssociationConf{ + assocConf: &commonv1.AssociationConf{ AuthSecretName: "test-es-elastic-user", AuthSecretKey: "elastic", CASecretName: "test-es-http-ca-public", @@ -53,7 +54,7 @@ func TestNewConfigFromSpec(t *testing.T) { }, { name: "with Elasticsearch CA cert", - assocConf: &commonv1beta1.AssociationConf{ + assocConf: &commonv1.AssociationConf{ AuthSecretName: "test-es-elastic-user", AuthSecretKey: "elastic", CASecretName: "test-es-http-ca-public", @@ -69,7 +70,7 @@ func TestNewConfigFromSpec(t *testing.T) { }, { name: "missing auth secret", - assocConf: &commonv1beta1.AssociationConf{ + assocConf: &commonv1.AssociationConf{ AuthSecretName: "wrong-secret", AuthSecretKey: "elastic", CASecretName: "test-es-http-ca-public", @@ -99,13 +100,13 @@ func TestNewConfigFromSpec(t *testing.T) { } } -func mkAPMServer(config map[string]interface{}, assocConf *commonv1beta1.AssociationConf) *v1beta1.ApmServer { - apmServer := &v1beta1.ApmServer{ +func mkAPMServer(config map[string]interface{}, assocConf *commonv1.AssociationConf) *apmv1.ApmServer { + apmServer := &apmv1.ApmServer{ ObjectMeta: metav1.ObjectMeta{ Name: "apm-server", }, - Spec: v1beta1.ApmServerSpec{ - Config: &commonv1beta1.Config{Data: config}, + Spec: apmv1.ApmServerSpec{ + Config: &commonv1.Config{Data: config}, }, } diff --git a/pkg/controller/apmserver/config/reconcile.go b/pkg/controller/apmserver/config/reconcile.go index 8b0cd96e448..b8a7e5c049b 100644 --- a/pkg/controller/apmserver/config/reconcile.go +++ b/pkg/controller/apmserver/config/reconcile.go @@ -7,15 +7,16 @@ package config import ( "reflect" - "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/apmserver/labels" - "github.com/elastic/cloud-on-k8s/pkg/controller/apmserver/name" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" - "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" logf "sigs.k8s.io/controller-runtime/pkg/log" + + apmv1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/apmserver/labels" + "github.com/elastic/cloud-on-k8s/pkg/controller/apmserver/name" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" + "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" ) const ApmCfgSecretKey = "apm-server.yml" @@ -24,7 +25,7 @@ var log = logf.Log.WithName("apmserver-config") // Reconcile reconciles the configuration of the APM server: it first creates the configuration from the APM // specification and then reconcile the underlying secret. -func Reconcile(client k8s.Client, scheme *runtime.Scheme, as *v1beta1.ApmServer) (*corev1.Secret, error) { +func Reconcile(client k8s.Client, scheme *runtime.Scheme, as *apmv1.ApmServer) (*corev1.Secret, error) { // Create a new configuration from the APM object spec. cfg, err := NewConfigFromSpec(client, as) diff --git a/pkg/controller/apmserver/pod.go b/pkg/controller/apmserver/pod.go index 74639e04860..73434979982 100644 --- a/pkg/controller/apmserver/pod.go +++ b/pkg/controller/apmserver/pod.go @@ -8,7 +8,7 @@ import ( "path/filepath" "strings" - "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1beta1" + apmv1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/apmserver/config" "github.com/elastic/cloud-on-k8s/pkg/controller/common/defaults" "github.com/elastic/cloud-on-k8s/pkg/controller/common/keystore" @@ -90,7 +90,7 @@ func imageWithVersion(image string, version string) string { return stringsutil.Concat(image, ":", version) } -func newPodSpec(as *v1beta1.ApmServer, p PodSpecParams) corev1.PodTemplateSpec { +func newPodSpec(as *apmv1.ApmServer, p PodSpecParams) corev1.PodTemplateSpec { configSecretVolume := volume.NewSecretVolumeWithMountPath( p.ConfigSecret.Name, "config", @@ -108,7 +108,7 @@ func newPodSpec(as *v1beta1.ApmServer, p PodSpecParams) corev1.PodTemplateSpec { }) builder := defaults.NewPodTemplateBuilder( - p.PodTemplate, v1beta1.APMServerContainerName). + p.PodTemplate, apmv1.ApmServerContainerName). WithResources(DefaultResources). WithDockerImage(p.CustomImageName, imageWithVersion(defaultImageRepositoryAndName, p.Version)). WithReadinessProbe(readinessProbe(as.Spec.HTTP.TLS.Enabled())). diff --git a/pkg/controller/apmserver/pod_test.go b/pkg/controller/apmserver/pod_test.go index 57ead41f698..ef77944937b 100644 --- a/pkg/controller/apmserver/pod_test.go +++ b/pkg/controller/apmserver/pod_test.go @@ -11,7 +11,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1beta1" + apmv1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/volume" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/settings" ) @@ -26,13 +26,13 @@ func TestNewPodSpec(t *testing.T) { probe := readinessProbe(true) tests := []struct { name string - as v1beta1.ApmServer + as apmv1.ApmServer p PodSpecParams want corev1.PodTemplateSpec }{ { name: "create default pod spec", - as: v1beta1.ApmServer{ + as: apmv1.ApmServer{ TypeMeta: metav1.TypeMeta{ Kind: "ApmServer", }, @@ -63,7 +63,7 @@ func TestNewPodSpec(t *testing.T) { AutomountServiceAccountToken: &varFalse, Containers: []corev1.Container{ { - Name: v1beta1.APMServerContainerName, + Name: apmv1.ApmServerContainerName, Image: imageWithVersion(defaultImageRepositoryAndName, "7.0.1"), Env: []corev1.EnvVar{ { diff --git a/pkg/controller/apmserver/services.go b/pkg/controller/apmserver/services.go index 12eb437f794..054fe11ce2f 100644 --- a/pkg/controller/apmserver/services.go +++ b/pkg/controller/apmserver/services.go @@ -5,14 +5,14 @@ package apmserver import ( - "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1beta1" + apmv1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/apmserver/labels" apmname "github.com/elastic/cloud-on-k8s/pkg/controller/apmserver/name" "github.com/elastic/cloud-on-k8s/pkg/controller/common/defaults" corev1 "k8s.io/api/core/v1" ) -func NewService(as v1beta1.ApmServer) *corev1.Service { +func NewService(as apmv1.ApmServer) *corev1.Service { svc := corev1.Service{ ObjectMeta: as.Spec.HTTP.Service.ObjectMeta, Spec: as.Spec.HTTP.Service.Spec, diff --git a/pkg/controller/apmserver/services_test.go b/pkg/controller/apmserver/services_test.go index 83888de3ac0..2a18291780c 100644 --- a/pkg/controller/apmserver/services_test.go +++ b/pkg/controller/apmserver/services_test.go @@ -7,8 +7,8 @@ package apmserver import ( "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1beta1" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" + apmv1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/apmserver/labels" "github.com/elastic/cloud-on-k8s/pkg/controller/common" "github.com/elastic/cloud-on-k8s/pkg/utils/compare" @@ -19,14 +19,14 @@ import ( func TestNewService(t *testing.T) { testCases := []struct { name string - httpConf commonv1beta1.HTTPConfig + httpConf commonv1.HTTPConfig wantSvc func() corev1.Service }{ { name: "no TLS", - httpConf: commonv1beta1.HTTPConfig{ - TLS: commonv1beta1.TLSOptions{ - SelfSignedCertificate: &commonv1beta1.SelfSignedCertificate{ + httpConf: commonv1.HTTPConfig{ + TLS: commonv1.TLSOptions{ + SelfSignedCertificate: &commonv1.SelfSignedCertificate{ Disabled: true, }, }, @@ -35,10 +35,10 @@ func TestNewService(t *testing.T) { }, { name: "self-signed certificate", - httpConf: commonv1beta1.HTTPConfig{ - TLS: commonv1beta1.TLSOptions{ - SelfSignedCertificate: &commonv1beta1.SelfSignedCertificate{ - SubjectAlternativeNames: []commonv1beta1.SubjectAlternativeName{ + httpConf: commonv1.HTTPConfig{ + TLS: commonv1.TLSOptions{ + SelfSignedCertificate: &commonv1.SelfSignedCertificate{ + SubjectAlternativeNames: []commonv1.SubjectAlternativeName{ { DNS: "apm-test.local", }, @@ -54,9 +54,9 @@ func TestNewService(t *testing.T) { }, { name: "user-provided certificate", - httpConf: commonv1beta1.HTTPConfig{ - TLS: commonv1beta1.TLSOptions{ - Certificate: commonv1beta1.SecretRef{ + httpConf: commonv1.HTTPConfig{ + TLS: commonv1.TLSOptions{ + Certificate: commonv1.SecretRef{ SecretName: "my-cert", }, }, @@ -104,13 +104,13 @@ func mkService() corev1.Service { } } -func mkAPMServer(httpConf commonv1beta1.HTTPConfig) v1beta1.ApmServer { - return v1beta1.ApmServer{ +func mkAPMServer(httpConf commonv1.HTTPConfig) apmv1.ApmServer { + return apmv1.ApmServer{ ObjectMeta: metav1.ObjectMeta{ Name: "apm-test", Namespace: "test", }, - Spec: v1beta1.ApmServerSpec{ + Spec: apmv1.ApmServerSpec{ HTTP: httpConf, }, } diff --git a/pkg/controller/apmserver/state.go b/pkg/controller/apmserver/state.go index c10c4570c41..3a98e49dfd4 100644 --- a/pkg/controller/apmserver/state.go +++ b/pkg/controller/apmserver/state.go @@ -5,25 +5,26 @@ package apmserver import ( - "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1beta1" v1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "sigs.k8s.io/controller-runtime/pkg/reconcile" + + apmv1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1" ) // State holds the accumulated state during the reconcile loop including the response and a pointer to an ApmServer // resource for status updates. type State struct { - ApmServer *v1beta1.ApmServer + ApmServer *apmv1.ApmServer Result reconcile.Result Request reconcile.Request - originalApmServer *v1beta1.ApmServer + originalApmServer *apmv1.ApmServer } // NewState creates a new reconcile state based on the given request and ApmServer resource with the resource // state reset to empty. -func NewState(request reconcile.Request, as *v1beta1.ApmServer) State { +func NewState(request reconcile.Request, as *apmv1.ApmServer) State { return State{Request: request, ApmServer: as, originalApmServer: as.DeepCopy()} } @@ -31,10 +32,10 @@ func NewState(request reconcile.Request, as *v1beta1.ApmServer) State { func (s State) UpdateApmServerState(deployment v1.Deployment, apmServerSecret corev1.Secret) { s.ApmServer.Status.SecretTokenSecretName = apmServerSecret.Name s.ApmServer.Status.AvailableNodes = deployment.Status.AvailableReplicas - s.ApmServer.Status.Health = v1beta1.ApmServerRed + s.ApmServer.Status.Health = apmv1.ApmServerRed for _, c := range deployment.Status.Conditions { if c.Type == v1.DeploymentAvailable && c.Status == corev1.ConditionTrue { - s.ApmServer.Status.Health = v1beta1.ApmServerGreen + s.ApmServer.Status.Health = apmv1.ApmServerGreen } } } diff --git a/pkg/controller/apmserverelasticsearchassociation/apmserverelasticsearchassociation_controller.go b/pkg/controller/apmserverelasticsearchassociation/apmserverelasticsearchassociation_controller.go index db19eb71bab..4e63bcc8970 100644 --- a/pkg/controller/apmserverelasticsearchassociation/apmserverelasticsearchassociation_controller.go +++ b/pkg/controller/apmserverelasticsearchassociation/apmserverelasticsearchassociation_controller.go @@ -8,20 +8,6 @@ import ( "reflect" "time" - apmtype "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1beta1" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - estype "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/apmserver/labels" - "github.com/elastic/cloud-on-k8s/pkg/controller/common" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/annotation" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/association" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates/http" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/events" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/operator" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/user" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/watches" - "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/services" - "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -36,6 +22,21 @@ import ( "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" + + apmv1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/apmserver/labels" + "github.com/elastic/cloud-on-k8s/pkg/controller/common" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/annotation" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/association" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates/http" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/events" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/operator" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/user" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/watches" + "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/services" + "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" ) const ( @@ -84,12 +85,12 @@ func add(mgr manager.Manager, r reconcile.Reconciler) (controller.Controller, er func addWatches(c controller.Controller, r *ReconcileApmServerElasticsearchAssociation) error { // Watch for changes to ApmServers - if err := c.Watch(&source.Kind{Type: &apmtype.ApmServer{}}, &handler.EnqueueRequestForObject{}); err != nil { + if err := c.Watch(&source.Kind{Type: &apmv1.ApmServer{}}, &handler.EnqueueRequestForObject{}); err != nil { return err } // Watch Elasticsearch cluster objects - if err := c.Watch(&source.Kind{Type: &estype.Elasticsearch{}}, r.watches.ElasticsearchClusters); err != nil { + if err := c.Watch(&source.Kind{Type: &esv1.Elasticsearch{}}, r.watches.ElasticsearchClusters); err != nil { return err } @@ -100,7 +101,7 @@ func addWatches(c controller.Controller, r *ReconcileApmServerElasticsearchAssoc // Watch Secrets owned by an ApmServer resource if err := c.Watch(&source.Kind{Type: &corev1.Secret{}}, &handler.EnqueueRequestForOwner{ - OwnerType: &apmtype.ApmServer{}, + OwnerType: &apmv1.ApmServer{}, IsController: true, }); err != nil { return err @@ -135,7 +136,7 @@ func (r *ReconcileApmServerElasticsearchAssociation) onDelete(obj types.Namespac func (r *ReconcileApmServerElasticsearchAssociation) Reconcile(request reconcile.Request) (reconcile.Result, error) { defer common.LogReconciliationRun(log, request, &r.iteration)() - var apmServer apmtype.ApmServer + var apmServer apmv1.ApmServer if ok, err := association.FetchWithAssociation(r.Client, request, &apmServer); !ok { if err != nil { return reconcile.Result{}, err @@ -193,16 +194,16 @@ func esCAWatchName(apm types.NamespacedName) string { return apm.Namespace + "-" + apm.Name + "-ca-watch" } -func resultFromStatus(status commonv1beta1.AssociationStatus) reconcile.Result { +func resultFromStatus(status commonv1.AssociationStatus) reconcile.Result { switch status { - case commonv1beta1.AssociationPending: + case commonv1.AssociationPending: return defaultRequeue // retry default: return reconcile.Result{} // we are done or there is not much we can do } } -func (r *ReconcileApmServerElasticsearchAssociation) isCompatible(apmServer *apmtype.ApmServer) (bool, error) { +func (r *ReconcileApmServerElasticsearchAssociation) isCompatible(apmServer *apmv1.ApmServer) (bool, error) { selector := map[string]string{labels.ApmServerNameLabelName: apmServer.Name} compat, err := annotation.ReconcileCompatibility(r.Client, apmServer, selector, r.OperatorInfo.BuildInfo.Version) if err != nil { @@ -211,11 +212,11 @@ func (r *ReconcileApmServerElasticsearchAssociation) isCompatible(apmServer *apm return compat, err } -func (r *ReconcileApmServerElasticsearchAssociation) reconcileInternal(apmServer *apmtype.ApmServer) (commonv1beta1.AssociationStatus, error) { +func (r *ReconcileApmServerElasticsearchAssociation) reconcileInternal(apmServer *apmv1.ApmServer) (commonv1.AssociationStatus, error) { // no auto-association nothing to do elasticsearchRef := apmServer.Spec.ElasticsearchRef if !elasticsearchRef.IsDefined() { - return commonv1beta1.AssociationUnknown, nil + return commonv1.AssociationUnknown, nil } if elasticsearchRef.Namespace == "" { // no namespace provided: default to the APM server namespace @@ -231,10 +232,10 @@ func (r *ReconcileApmServerElasticsearchAssociation) reconcileInternal(apmServer Watcher: assocKey, }) if err != nil { - return commonv1beta1.AssociationFailed, err + return commonv1.AssociationFailed, err } - var es estype.Elasticsearch + var es esv1.Elasticsearch err = r.Get(elasticsearchRef.NamespacedName(), &es) if err != nil { k8s.EmitErrorEvent(r.recorder, err, apmServer, events.EventAssociationError, @@ -243,12 +244,12 @@ func (r *ReconcileApmServerElasticsearchAssociation) reconcileInternal(apmServer // ES is not found, remove any existing backend configuration and retry in a bit. if err := association.RemoveAssociationConf(r.Client, apmServer); err != nil && !errors.IsConflict(err) { log.Error(err, "Failed to remove Elasticsearch output from APMServer object", "namespace", apmServer.Namespace, "name", apmServer.Name) - return commonv1beta1.AssociationPending, err + return commonv1.AssociationPending, err } - return commonv1beta1.AssociationPending, nil + return commonv1.AssociationPending, nil } - return commonv1beta1.AssociationFailed, err + return commonv1.AssociationFailed, err } if err := association.ReconcileEsUser( @@ -263,17 +264,17 @@ func (r *ReconcileApmServerElasticsearchAssociation) reconcileInternal(apmServer apmUserSuffix, es, ); err != nil { // TODO distinguish conflicts and non-recoverable errors here - return commonv1beta1.AssociationPending, err + return commonv1.AssociationPending, err } caSecret, err := r.reconcileElasticsearchCA(apmServer, elasticsearchRef.NamespacedName()) if err != nil { - return commonv1beta1.AssociationPending, err // maybe not created yet + return commonv1.AssociationPending, err // maybe not created yet } // construct the expected ES output configuration authSecretRef := association.ClearTextSecretKeySelector(apmServer, apmUserSuffix) - expectedAssocConf := &commonv1beta1.AssociationConf{ + expectedAssocConf := &commonv1.AssociationConf{ AuthSecretName: authSecretRef.Name, AuthSecretKey: authSecretRef.Key, CACertProvided: caSecret.CACertProvided, @@ -285,10 +286,10 @@ func (r *ReconcileApmServerElasticsearchAssociation) reconcileInternal(apmServer log.Info("Updating APMServer spec with Elasticsearch association configuration", "namespace", apmServer.Namespace, "name", apmServer.Name) if err := association.UpdateAssociationConf(r.Client, apmServer, expectedAssocConf); err != nil { if errors.IsConflict(err) { - return commonv1beta1.AssociationPending, nil + return commonv1.AssociationPending, nil } log.Error(err, "Failed to update APMServer association configuration", "namespace", apmServer.Namespace, "name", apmServer.Name) - return commonv1beta1.AssociationPending, err + return commonv1.AssociationPending, err } apmServer.SetAssociationConf(expectedAssocConf) } @@ -297,15 +298,15 @@ func (r *ReconcileApmServerElasticsearchAssociation) reconcileInternal(apmServer log.Error(err, "Error while trying to delete orphaned resources. Continuing.", "namespace", apmServer.Namespace, "as_name", apmServer.Name) } - return commonv1beta1.AssociationEstablished, nil + return commonv1.AssociationEstablished, nil } -func (r *ReconcileApmServerElasticsearchAssociation) reconcileElasticsearchCA(apm *apmtype.ApmServer, es types.NamespacedName) (association.CASecret, error) { +func (r *ReconcileApmServerElasticsearchAssociation) reconcileElasticsearchCA(apm *apmv1.ApmServer, es types.NamespacedName) (association.CASecret, error) { apmKey := k8s.ExtractNamespacedName(apm) // watch ES CA secret to reconcile on any change if err := r.watches.Secrets.AddHandler(watches.NamedWatch{ Name: esCAWatchName(apmKey), - Watched: []types.NamespacedName{http.PublicCertsSecretRef(estype.ESNamer, es)}, + Watched: []types.NamespacedName{http.PublicCertsSecretRef(esv1.ESNamer, es)}, Watcher: apmKey, }); err != nil { return association.CASecret{}, err @@ -327,7 +328,7 @@ func (r *ReconcileApmServerElasticsearchAssociation) reconcileElasticsearchCA(ap // attempts. If a user changes namespace on a vertex of an association the standard reconcile mechanism will not delete the // now redundant old user object/secret. This function lists all resources that don't match the current name/namespace // combinations and deletes them. -func deleteOrphanedResources(c k8s.Client, apm *apmtype.ApmServer) error { +func deleteOrphanedResources(c k8s.Client, apm *apmv1.ApmServer) error { var secrets corev1.SecretList ns := client.InNamespace(apm.Namespace) matchLabels := client.MatchingLabels(NewResourceLabels(apm.Name)) diff --git a/pkg/controller/apmserverelasticsearchassociation/apmserverelasticsearchassociation_controller_test.go b/pkg/controller/apmserverelasticsearchassociation/apmserverelasticsearchassociation_controller_test.go index 046e5e1051d..4860d569a81 100644 --- a/pkg/controller/apmserverelasticsearchassociation/apmserverelasticsearchassociation_controller_test.go +++ b/pkg/controller/apmserverelasticsearchassociation/apmserverelasticsearchassociation_controller_test.go @@ -7,8 +7,8 @@ package apmserverelasticsearchassociation import ( "testing" - apmtype "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1beta1" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" + apmv1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -25,7 +25,7 @@ const ( var t = true var ownerRefFixture = metav1.OwnerReference{ - APIVersion: "apmserver.k8s.elastic.co/v1beta1", + APIVersion: "apmserver.k8s.elastic.co/v1", Kind: "ApmServer", Name: "as", UID: "", @@ -34,13 +34,13 @@ var ownerRefFixture = metav1.OwnerReference{ } // apmFixture is a shared test fixture -var apmFixture = apmtype.ApmServer{ +var apmFixture = apmv1.ApmServer{ ObjectMeta: metav1.ObjectMeta{ Name: "as", Namespace: "default", }, - Spec: apmtype.ApmServerSpec{ - ElasticsearchRef: commonv1beta1.ObjectSelector{ + Spec: apmv1.ApmServerSpec{ + ElasticsearchRef: commonv1.ObjectSelector{ Name: "es", Namespace: "default", }, @@ -50,14 +50,14 @@ var apmFixture = apmtype.ApmServer{ func Test_deleteOrphanedResources(t *testing.T) { tests := []struct { name string - args apmtype.ApmServer + args apmv1.ApmServer initialObjects []runtime.Object postCondition func(c k8s.Client) wantErr bool }{ { name: "nothing to delete", - args: apmtype.ApmServer{}, + args: apmv1.ApmServer{}, wantErr: false, }, { @@ -90,12 +90,12 @@ func Test_deleteOrphanedResources(t *testing.T) { }, { name: "Orphaned objects exist", - args: apmtype.ApmServer{ + args: apmv1.ApmServer{ ObjectMeta: metav1.ObjectMeta{ Name: "as", Namespace: "default", }, - Spec: apmtype.ApmServerSpec{}, + Spec: apmv1.ApmServerSpec{}, }, initialObjects: []runtime.Object{ &corev1.Secret{ diff --git a/pkg/controller/common/annotation/association.go b/pkg/controller/common/annotation/association.go index cd032e66bfb..ac6d1d6acfc 100644 --- a/pkg/controller/common/annotation/association.go +++ b/pkg/controller/common/annotation/association.go @@ -5,8 +5,9 @@ package annotation import ( - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" ) const ( @@ -19,7 +20,7 @@ const ( ) // ForAssociationStatusChange constructs the annotation map for an association status change event. -func ForAssociationStatusChange(prevStatus, currStatus commonv1beta1.AssociationStatus) map[string]string { +func ForAssociationStatusChange(prevStatus, currStatus commonv1.AssociationStatus) map[string]string { return map[string]string{ CurrAssocStatusAnnotation: string(currStatus), PrevAssocStatusAnnotation: string(prevStatus), @@ -27,12 +28,12 @@ func ForAssociationStatusChange(prevStatus, currStatus commonv1beta1.Association } // ExtractAssociationStatus extracts the association status values from the provided meta object. -func ExtractAssociationStatus(obj metav1.ObjectMeta) (prevStatus, currStatus commonv1beta1.AssociationStatus) { +func ExtractAssociationStatus(obj metav1.ObjectMeta) (prevStatus, currStatus commonv1.AssociationStatus) { if obj.Annotations == nil { - return commonv1beta1.AssociationUnknown, commonv1beta1.AssociationUnknown + return commonv1.AssociationUnknown, commonv1.AssociationUnknown } - prevStatus = commonv1beta1.AssociationStatus(obj.Annotations[PrevAssocStatusAnnotation]) - currStatus = commonv1beta1.AssociationStatus(obj.Annotations[CurrAssocStatusAnnotation]) + prevStatus = commonv1.AssociationStatus(obj.Annotations[PrevAssocStatusAnnotation]) + currStatus = commonv1.AssociationStatus(obj.Annotations[CurrAssocStatusAnnotation]) return } diff --git a/pkg/controller/common/annotation/controller_version_test.go b/pkg/controller/common/annotation/controller_version_test.go index cb7af38884d..d11a8428766 100644 --- a/pkg/controller/common/annotation/controller_version_test.go +++ b/pkg/controller/common/annotation/controller_version_test.go @@ -7,20 +7,21 @@ package annotation import ( "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - kibanav1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" - "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" + + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" + "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" ) // Test UpdateControllerVersion updates annotation if there is an older version func TestAnnotationUpdated(t *testing.T) { - kibana := kibanav1beta1.Kibana{ + kibana := kbv1.Kibana{ ObjectMeta: metav1.ObjectMeta{ Namespace: "ns", Name: "kibana", @@ -38,7 +39,7 @@ func TestAnnotationUpdated(t *testing.T) { // Test UpdateControllerVersion creates an annotation even if there are no current annotations func TestAnnotationCreated(t *testing.T) { - kibana := kibanav1beta1.Kibana{ + kibana := kbv1.Kibana{ ObjectMeta: metav1.ObjectMeta{ Namespace: "ns", Name: "kibana", @@ -49,7 +50,7 @@ func TestAnnotationCreated(t *testing.T) { client := k8s.WrappedFakeClient(obj) err := UpdateControllerVersion(client, obj, "newversion") require.NoError(t, err) - actualKibana := &kibanav1beta1.Kibana{} + actualKibana := &kbv1.Kibana{} err = client.Get(types.NamespacedName{ Namespace: obj.Namespace, Name: obj.Name, @@ -63,7 +64,7 @@ func TestAnnotationCreated(t *testing.T) { // a previous operator version, and add an annotation indicating an old controller version func TestMissingAnnotationOldVersion(t *testing.T) { - es := &v1beta1.Elasticsearch{ + es := &esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Namespace: "ns", Name: "es", @@ -91,7 +92,7 @@ func TestMissingAnnotationOldVersion(t *testing.T) { // TestMissingAnnotationNewObject tests that we add an annotation for new objects func TestMissingAnnotationNewObject(t *testing.T) { - es := &v1beta1.Elasticsearch{ + es := &esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Namespace: "ns", Name: "es", @@ -120,7 +121,7 @@ func TestMissingAnnotationNewObject(t *testing.T) { // func TestSameAnnotation(t *testing.T) { - es := &v1beta1.Elasticsearch{ + es := &esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Namespace: "ns", Name: "es", @@ -138,7 +139,7 @@ func TestSameAnnotation(t *testing.T) { } func TestIncompatibleAnnotation(t *testing.T) { - es := &v1beta1.Elasticsearch{ + es := &esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Namespace: "ns", Name: "es", @@ -157,7 +158,7 @@ func TestIncompatibleAnnotation(t *testing.T) { } func TestNewerAnnotation(t *testing.T) { - es := &v1beta1.Elasticsearch{ + es := &esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Namespace: "ns", Name: "es", @@ -173,6 +174,6 @@ func TestNewerAnnotation(t *testing.T) { assert.True(t, compat) } -func getElasticsearchSelector(es *v1beta1.Elasticsearch) map[string]string { +func getElasticsearchSelector(es *esv1.Elasticsearch) map[string]string { return map[string]string{label.ClusterNameLabelName: es.Name} } diff --git a/pkg/controller/common/association/association.go b/pkg/controller/common/association/association.go index f14921085fe..3a61b1e2ef8 100644 --- a/pkg/controller/common/association/association.go +++ b/pkg/controller/common/association/association.go @@ -5,17 +5,18 @@ package association import ( - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" + + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" ) // ElasticsearchAuthSettings returns the user and the password to be used by an associated object to authenticate // against an Elasticsearch cluster. func ElasticsearchAuthSettings( c k8s.Client, - associated commonv1beta1.Associated, + associated commonv1.Associated, ) (username, password string, err error) { assocConf := associated.AssociationConf() if !assocConf.AuthIsConfigured() { diff --git a/pkg/controller/common/association/association_test.go b/pkg/controller/common/association/association_test.go index 7e0bbabe938..2744ecc7c53 100644 --- a/pkg/controller/common/association/association_test.go +++ b/pkg/controller/common/association/association_test.go @@ -7,30 +7,30 @@ package association import ( "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1beta1" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" + apmv1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func TestGetCredentials(t *testing.T) { - apmServer := &v1beta1.ApmServer{ + apmServer := &apmv1.ApmServer{ ObjectMeta: metav1.ObjectMeta{ Name: "apm-server-sample", Namespace: "default", }, - Spec: v1beta1.ApmServerSpec{}, + Spec: apmv1.ApmServerSpec{}, } - apmServer.SetAssociationConf(&commonv1beta1.AssociationConf{ + apmServer.SetAssociationConf(&commonv1.AssociationConf{ URL: "https://elasticsearch-sample-es-http.default.svc:9200", }) tests := []struct { name string client k8s.Client - assocConf commonv1beta1.AssociationConf + assocConf commonv1.AssociationConf wantUsername string wantPassword string wantErr bool @@ -44,7 +44,7 @@ func TestGetCredentials(t *testing.T) { }, Data: map[string][]byte{"elastic-internal-apm": []byte("a2s1Nmt0N3Nwdmg4cmpqdDlucWhsN3cy")}, }), - assocConf: commonv1beta1.AssociationConf{ + assocConf: commonv1.AssociationConf{ AuthSecretName: "apmelasticsearchassociation-sample-elastic-internal-apm", AuthSecretKey: "elastic-internal-apm", CASecretName: "ca-secret", @@ -62,7 +62,7 @@ func TestGetCredentials(t *testing.T) { }, Data: map[string][]byte{"elastic-internal-apm": []byte("a2s1Nmt0N3Nwdmg4cmpqdDlucWhsN3cy")}, }), - assocConf: commonv1beta1.AssociationConf{ + assocConf: commonv1.AssociationConf{ CASecretName: "ca-secret", URL: "https://elasticsearch-sample-es-http.default.svc:9200", }, @@ -76,7 +76,7 @@ func TestGetCredentials(t *testing.T) { }, Data: map[string][]byte{"elastic-internal-apm": []byte("a2s1Nmt0N3Nwdmg4cmpqdDlucWhsN3cy")}, }), - assocConf: commonv1beta1.AssociationConf{ + assocConf: commonv1.AssociationConf{ AuthSecretName: "apmelasticsearchassociation-sample-elastic-internal-apm", AuthSecretKey: "elastic-internal-apm", CASecretName: "ca-secret", diff --git a/pkg/controller/common/association/ca.go b/pkg/controller/common/association/ca.go index 51bf2dbc795..c1de9a6cddc 100644 --- a/pkg/controller/common/association/ca.go +++ b/pkg/controller/common/association/ca.go @@ -7,17 +7,18 @@ package association import ( "reflect" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates/http" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" - "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" + + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates/http" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" + "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" ) // CASecret is a container to hold information about the Elasticsearch CA secret. @@ -28,7 +29,7 @@ type CASecret struct { // ElasticsearchCACertSecretName returns the name of the secret holding the certificate chain used // by the associated resource to establish and validate a secured HTTP connection to Elasticsearch. -func ElasticsearchCACertSecretName(associated commonv1beta1.Associated, suffix string) string { +func ElasticsearchCACertSecretName(associated commonv1.Associated, suffix string) string { return associated.GetName() + "-" + suffix } @@ -37,12 +38,12 @@ func ElasticsearchCACertSecretName(associated commonv1beta1.Associated, suffix s func ReconcileCASecret( client k8s.Client, scheme *runtime.Scheme, - associated commonv1beta1.Associated, + associated commonv1.Associated, es types.NamespacedName, labels map[string]string, suffix string, ) (CASecret, error) { - publicESHTTPCertificatesNSN := http.PublicCertsSecretRef(v1beta1.ESNamer, es) + publicESHTTPCertificatesNSN := http.PublicCertsSecretRef(esv1.ESNamer, es) // retrieve the HTTP certificates from ES namespace var publicESHTTPCertificatesSecret corev1.Secret diff --git a/pkg/controller/common/association/ca_test.go b/pkg/controller/common/association/ca_test.go index df99aa8e475..5c897ad6008 100644 --- a/pkg/controller/common/association/ca_test.go +++ b/pkg/controller/common/association/ca_test.go @@ -7,8 +7,8 @@ package association import ( "testing" - estype "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - kbtype "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" "github.com/elastic/cloud-on-k8s/pkg/controller/common/watches" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" @@ -27,7 +27,7 @@ func TestReconcileAssociation_reconcileCASecret(t *testing.T) { require.NoError(t, w.Secrets.InjectScheme(scheme.Scheme)) // mock existing ES resource - es := estype.Elasticsearch{ + es := esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Namespace: esFixture.Namespace, Name: esFixture.Name, @@ -37,7 +37,7 @@ func TestReconcileAssociation_reconcileCASecret(t *testing.T) { esCA := corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Namespace: es.Namespace, - Name: certificates.PublicSecretName(estype.ESNamer, es.Name, certificates.HTTPCAType), + Name: certificates.PublicSecretName(esv1.ESNamer, es.Name, certificates.HTTPCAType), }, Data: map[string][]byte{ certificates.CertFileName: []byte("fake-cert"), @@ -47,7 +47,7 @@ func TestReconcileAssociation_reconcileCASecret(t *testing.T) { updatedEsCA := corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Namespace: es.Namespace, - Name: certificates.PublicSecretName(estype.ESNamer, es.Name, certificates.HTTPCAType), + Name: certificates.PublicSecretName(esv1.ESNamer, es.Name, certificates.HTTPCAType), }, Data: map[string][]byte{ certificates.CertFileName: []byte("updated-fake-cert"), @@ -78,7 +78,7 @@ func TestReconcileAssociation_reconcileCASecret(t *testing.T) { esEmptyCA := corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Namespace: es.Namespace, - Name: certificates.PublicSecretName(estype.ESNamer, es.Name, certificates.HTTPCAType), + Name: certificates.PublicSecretName(esv1.ESNamer, es.Name, certificates.HTTPCAType), }, Data: map[string][]byte{ certificates.CertFileName: []byte("fake-cert"), @@ -98,8 +98,8 @@ func TestReconcileAssociation_reconcileCASecret(t *testing.T) { tests := []struct { name string client k8s.Client - kibana kbtype.Kibana - es estype.Elasticsearch + kibana kbv1.Kibana + es esv1.Elasticsearch want string wantCA *corev1.Secret wantCACertProvided bool diff --git a/pkg/controller/common/association/conf.go b/pkg/controller/common/association/conf.go index aa403764a08..40b322ce919 100644 --- a/pkg/controller/common/association/conf.go +++ b/pkg/controller/common/association/conf.go @@ -9,18 +9,19 @@ import ( "reflect" "unsafe" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/annotation" - "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/pkg/errors" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/reconcile" + + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/annotation" + "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" ) // FetchWithAssociation retrieves an object and extracts its association configuration. -func FetchWithAssociation(client k8s.Client, request reconcile.Request, obj commonv1beta1.Associator) (bool, error) { +func FetchWithAssociation(client k8s.Client, request reconcile.Request, obj commonv1.Associator) (bool, error) { if err := client.Get(request.NamespacedName, obj); err != nil { if apierrors.IsNotFound(err) { return false, nil @@ -38,7 +39,7 @@ func FetchWithAssociation(client k8s.Client, request reconcile.Request, obj comm } // GetAssociationConf extracts the association configuration from the given object by reading the annotations. -func GetAssociationConf(obj runtime.Object) (*commonv1beta1.AssociationConf, error) { +func GetAssociationConf(obj runtime.Object) (*commonv1.AssociationConf, error) { accessor := meta.NewAccessor() annotations, err := accessor.Annotations(obj) if err != nil { @@ -48,12 +49,12 @@ func GetAssociationConf(obj runtime.Object) (*commonv1beta1.AssociationConf, err return extractAssociationConf(annotations) } -func extractAssociationConf(annotations map[string]string) (*commonv1beta1.AssociationConf, error) { +func extractAssociationConf(annotations map[string]string) (*commonv1.AssociationConf, error) { if len(annotations) == 0 { return nil, nil } - var assocConf commonv1beta1.AssociationConf + var assocConf commonv1.AssociationConf serializedConf, exists := annotations[annotation.AssociationConfAnnotation] if !exists || serializedConf == "" { return nil, nil @@ -91,7 +92,7 @@ func RemoveAssociationConf(client k8s.Client, obj runtime.Object) error { } // UpdateAssociationConf updates the association configuration annotation. -func UpdateAssociationConf(client k8s.Client, obj runtime.Object, wantConf *commonv1beta1.AssociationConf) error { +func UpdateAssociationConf(client k8s.Client, obj runtime.Object, wantConf *commonv1.AssociationConf) error { accessor := meta.NewAccessor() annotations, err := accessor.Annotations(obj) if err != nil { diff --git a/pkg/controller/common/association/conf_test.go b/pkg/controller/common/association/conf_test.go index 769309a3947..7c971314a10 100644 --- a/pkg/controller/common/association/conf_test.go +++ b/pkg/controller/common/association/conf_test.go @@ -7,9 +7,9 @@ package association import ( "testing" - apmv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1beta1" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - kbv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + apmv1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/annotation" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/stretchr/testify/require" @@ -26,18 +26,18 @@ func TestFetchWithAssociation(t *testing.T) { func testFetchAPMServer(t *testing.T) { testCases := []struct { name string - apmServer *apmv1beta1.ApmServer + apmServer *apmv1.ApmServer request reconcile.Request wantOK bool wantErr bool - wantAssocConf *commonv1beta1.AssociationConf + wantAssocConf *commonv1.AssociationConf }{ { name: "with association annotation", apmServer: mkAPMServer(true), request: reconcile.Request{NamespacedName: types.NamespacedName{Name: "apm-server-test", Namespace: "apm-ns"}}, wantOK: true, - wantAssocConf: &commonv1beta1.AssociationConf{ + wantAssocConf: &commonv1.AssociationConf{ AuthSecretName: "auth-secret", AuthSecretKey: "apm-user", CASecretName: "ca-secret", @@ -62,7 +62,7 @@ func testFetchAPMServer(t *testing.T) { t.Run(tc.name, func(t *testing.T) { client := k8s.WrappedFakeClient(tc.apmServer) - var got apmv1beta1.ApmServer + var got apmv1.ApmServer ok, err := FetchWithAssociation(client, tc.request, &got) if tc.wantErr { @@ -82,13 +82,13 @@ func testFetchAPMServer(t *testing.T) { } } -func mkAPMServer(withAnnotations bool) *apmv1beta1.ApmServer { - apmServer := &apmv1beta1.ApmServer{ +func mkAPMServer(withAnnotations bool) *apmv1.ApmServer { + apmServer := &apmv1.ApmServer{ ObjectMeta: metav1.ObjectMeta{ Name: "apm-server-test", Namespace: "apm-ns", }, - Spec: apmv1beta1.ApmServerSpec{ + Spec: apmv1.ApmServerSpec{ Image: "test-image", Count: 1, }, @@ -106,18 +106,18 @@ func mkAPMServer(withAnnotations bool) *apmv1beta1.ApmServer { func testFetchKibana(t *testing.T) { testCases := []struct { name string - kibana *kbv1beta1.Kibana + kibana *kbv1.Kibana request reconcile.Request wantOK bool wantErr bool - wantAssocConf *commonv1beta1.AssociationConf + wantAssocConf *commonv1.AssociationConf }{ { name: "with association annotation", kibana: mkKibana(true), request: reconcile.Request{NamespacedName: types.NamespacedName{Name: "kb-test", Namespace: "kb-ns"}}, wantOK: true, - wantAssocConf: &commonv1beta1.AssociationConf{ + wantAssocConf: &commonv1.AssociationConf{ AuthSecretName: "auth-secret", AuthSecretKey: "kb-user", CASecretName: "ca-secret", @@ -142,7 +142,7 @@ func testFetchKibana(t *testing.T) { t.Run(tc.name, func(t *testing.T) { client := k8s.WrappedFakeClient(tc.kibana) - var got kbv1beta1.Kibana + var got kbv1.Kibana ok, err := FetchWithAssociation(client, tc.request, &got) if tc.wantErr { @@ -162,13 +162,13 @@ func testFetchKibana(t *testing.T) { } } -func mkKibana(withAnnotations bool) *kbv1beta1.Kibana { - kb := &kbv1beta1.Kibana{ +func mkKibana(withAnnotations bool) *kbv1.Kibana { + kb := &kbv1.Kibana{ ObjectMeta: metav1.ObjectMeta{ Name: "kb-test", Namespace: "kb-ns", }, - Spec: kbv1beta1.KibanaSpec{ + Spec: kbv1.KibanaSpec{ Image: "test-image", Count: 1, }, @@ -188,7 +188,7 @@ func TestUpdateAssociationConf(t *testing.T) { request := reconcile.Request{NamespacedName: types.NamespacedName{Name: "kb-test", Namespace: "kb-ns"}} client := k8s.WrappedFakeClient(kb) - assocConf := &commonv1beta1.AssociationConf{ + assocConf := &commonv1.AssociationConf{ AuthSecretName: "auth-secret", AuthSecretKey: "kb-user", CASecretName: "ca-secret", @@ -196,7 +196,7 @@ func TestUpdateAssociationConf(t *testing.T) { } // check the existing values - var got kbv1beta1.Kibana + var got kbv1.Kibana ok, _ := FetchWithAssociation(client, request, &got) require.True(t, ok) require.Equal(t, "kb-test", got.Name) @@ -206,7 +206,7 @@ func TestUpdateAssociationConf(t *testing.T) { require.Equal(t, assocConf, got.AssociationConf()) // update and check the new values - newAssocConf := &commonv1beta1.AssociationConf{ + newAssocConf := &commonv1.AssociationConf{ AuthSecretName: "new-auth-secret", AuthSecretKey: "new-kb-user", CASecretName: "new-ca-secret", @@ -230,7 +230,7 @@ func TestRemoveAssociationConf(t *testing.T) { request := reconcile.Request{NamespacedName: types.NamespacedName{Name: "kb-test", Namespace: "kb-ns"}} client := k8s.WrappedFakeClient(kb) - assocConf := &commonv1beta1.AssociationConf{ + assocConf := &commonv1.AssociationConf{ AuthSecretName: "auth-secret", AuthSecretKey: "kb-user", CASecretName: "ca-secret", @@ -238,7 +238,7 @@ func TestRemoveAssociationConf(t *testing.T) { } // check the existing values - var got kbv1beta1.Kibana + var got kbv1.Kibana ok, _ := FetchWithAssociation(client, request, &got) require.True(t, ok) require.Equal(t, "kb-test", got.Name) diff --git a/pkg/controller/common/association/gc_test.go b/pkg/controller/common/association/gc_test.go index c3463715413..9cab87976c0 100644 --- a/pkg/controller/common/association/gc_test.go +++ b/pkg/controller/common/association/gc_test.go @@ -7,14 +7,15 @@ package association import ( "testing" - apmtype "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1beta1" - kibanatype "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + apmv1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common" "github.com/elastic/cloud-on-k8s/pkg/controller/common/user" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/stretchr/testify/assert" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" @@ -54,20 +55,20 @@ func TestUsersGarbageCollector_GC(t *testing.T) { newUserSecret("es", "ns1-kb-kibana2-fy8i-kibana-user", KibanaAssociationLabelNamespace, KibanaAssociationLabelName, "ns2", "kibana2"), newUserSecret("es", "ns1-kb-orphaned-xxxx-apm-user", ApmAssociationLabelNamespace, ApmAssociationLabelName, "ns1", "orphaned-apm"), newUserSecret("es", "ns1-kb-apm1-yrfa-apm-user", ApmAssociationLabelNamespace, ApmAssociationLabelName, "ns1", "apm1"), - &kibanatype.Kibana{ - ObjectMeta: v1.ObjectMeta{ + &kbv1.Kibana{ + ObjectMeta: metav1.ObjectMeta{ Name: "kibana1", Namespace: "ns1", }, }, - &kibanatype.Kibana{ - ObjectMeta: v1.ObjectMeta{ + &kbv1.Kibana{ + ObjectMeta: metav1.ObjectMeta{ Name: "kibana2", Namespace: "ns2", }, }, - &apmtype.ApmServer{ - ObjectMeta: v1.ObjectMeta{ + &apmv1.ApmServer{ + ObjectMeta: metav1.ObjectMeta{ Name: "apm1", Namespace: "ns1", }, @@ -80,8 +81,8 @@ func TestUsersGarbageCollector_GC(t *testing.T) { } // register some resources - ugc.For(&apmtype.ApmServerList{}, ApmAssociationLabelNamespace, ApmAssociationLabelName) - ugc.For(&kibanatype.KibanaList{}, KibanaAssociationLabelNamespace, KibanaAssociationLabelName) + ugc.For(&apmv1.ApmServerList{}, ApmAssociationLabelNamespace, ApmAssociationLabelName) + ugc.For(&kbv1.KibanaList{}, KibanaAssociationLabelNamespace, KibanaAssociationLabelName) err := ugc.DoGarbageCollection() if err != nil { diff --git a/pkg/controller/common/association/user.go b/pkg/controller/common/association/user.go index 2b19d8f611d..5f044009418 100644 --- a/pkg/controller/common/association/user.go +++ b/pkg/controller/common/association/user.go @@ -7,20 +7,21 @@ package association import ( "bytes" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" - commonuser "github.com/elastic/cloud-on-k8s/pkg/controller/common/user" - "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "golang.org/x/crypto/bcrypt" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" + + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" + commonuser "github.com/elastic/cloud-on-k8s/pkg/controller/common/user" + "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" ) // elasticsearchUserName identifies the associated user in Elasticsearch namespace. -func elasticsearchUserName(associated commonv1beta1.Associated, userSuffix string) string { +func elasticsearchUserName(associated commonv1.Associated, userSuffix string) string { // must be namespace-aware since we might have several associated instances running in // different namespaces with the same name: we need one user for each // in the Elasticsearch namespace @@ -28,13 +29,13 @@ func elasticsearchUserName(associated commonv1beta1.Associated, userSuffix strin } // userSecretObjectName identifies the associated secret object. -func userSecretObjectName(associated commonv1beta1.Associated, userSuffix string) string { +func userSecretObjectName(associated commonv1.Associated, userSuffix string) string { // does not need to be namespace aware, since it lives in associated object namespace. return associated.GetName() + "-" + userSuffix } // UserKey is the namespaced name to identify the user resource created by the controller. -func UserKey(associated commonv1beta1.Associated, userSuffix string) types.NamespacedName { +func UserKey(associated commonv1.Associated, userSuffix string) types.NamespacedName { esNamespace := associated.ElasticsearchRef().Namespace if esNamespace == "" { // no namespace given, default to the associated object's one @@ -49,7 +50,7 @@ func UserKey(associated commonv1beta1.Associated, userSuffix string) types.Names // secretKey is the namespaced name to identify the secret containing the password for the user. // It uses the same resource name as the associated user. -func secretKey(associated commonv1beta1.Associated, userSuffix string) types.NamespacedName { +func secretKey(associated commonv1.Associated, userSuffix string) types.NamespacedName { return types.NamespacedName{ Namespace: associated.GetNamespace(), Name: userSecretObjectName(associated, userSuffix), @@ -57,7 +58,7 @@ func secretKey(associated commonv1beta1.Associated, userSuffix string) types.Nam } // ClearTextSecretKeySelector creates a SecretKeySelector for the associated user secret -func ClearTextSecretKeySelector(associated commonv1beta1.Associated, userSuffix string) *corev1.SecretKeySelector { +func ClearTextSecretKeySelector(associated commonv1.Associated, userSuffix string) *corev1.SecretKeySelector { return &corev1.SecretKeySelector{ LocalObjectReference: corev1.LocalObjectReference{ Name: userSecretObjectName(associated, userSuffix), @@ -70,11 +71,11 @@ func ClearTextSecretKeySelector(associated commonv1beta1.Associated, userSuffix func ReconcileEsUser( c k8s.Client, s *runtime.Scheme, - associated commonv1beta1.Associated, + associated commonv1.Associated, labels map[string]string, userRoles string, userObjectSuffix string, - es v1beta1.Elasticsearch, + es esv1.Elasticsearch, ) error { pw := commonuser.RandomPasswordBytes() diff --git a/pkg/controller/common/association/user_test.go b/pkg/controller/common/association/user_test.go index 68a8f6b5f2d..2d636e6b876 100644 --- a/pkg/controller/common/association/user_test.go +++ b/pkg/controller/common/association/user_test.go @@ -9,9 +9,9 @@ import ( "k8s.io/client-go/kubernetes/scheme" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - estype "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - kbtype "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common" "github.com/elastic/cloud-on-k8s/pkg/controller/common/user" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" @@ -34,7 +34,7 @@ const ( associationLabelNamespace = "association.k8s.elastic.co/namespace" ) -var esFixture = estype.Elasticsearch{ +var esFixture = esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Name: "es-foo", Namespace: "default", @@ -50,10 +50,10 @@ var kibanaFixtureObjectMeta = metav1.ObjectMeta{ UID: kibanaFixtureUID, } -var kibanaFixture = kbtype.Kibana{ +var kibanaFixture = kbv1.Kibana{ ObjectMeta: kibanaFixtureObjectMeta, - Spec: kbtype.KibanaSpec{ - ElasticsearchRef: commonv1beta1.ObjectSelector{ + Spec: kbv1.KibanaSpec{ + ElasticsearchRef: commonv1.ObjectSelector{ Name: esFixture.Name, Namespace: esFixture.Namespace, }, @@ -63,8 +63,8 @@ var kibanaFixture = kbtype.Kibana{ func Test_reconcileEsUser(t *testing.T) { type args struct { initialObjects []runtime.Object - kibana kbtype.Kibana - es estype.Elasticsearch + kibana kbv1.Kibana + es esv1.Elasticsearch } tests := []struct { name string @@ -219,13 +219,13 @@ func Test_reconcileEsUser(t *testing.T) { { name: "Reconcile is namespace aware", args: args{ - kibana: kbtype.Kibana{ + kibana: kbv1.Kibana{ ObjectMeta: metav1.ObjectMeta{ Name: "kibana-foo", Namespace: "ns-2", }, - Spec: kbtype.KibanaSpec{ - ElasticsearchRef: commonv1beta1.ObjectSelector{ + Spec: kbv1.KibanaSpec{ + ElasticsearchRef: commonv1.ObjectSelector{ Name: esFixture.Name, Namespace: esFixture.Namespace, }, diff --git a/pkg/controller/common/certificates/ca_reconcile_test.go b/pkg/controller/common/certificates/ca_reconcile_test.go index 8a52ff6caa8..8e3f1024053 100644 --- a/pkg/controller/common/certificates/ca_reconcile_test.go +++ b/pkg/controller/common/certificates/ca_reconcile_test.go @@ -12,7 +12,7 @@ import ( "testing" "time" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/name" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/stretchr/testify/assert" @@ -33,7 +33,7 @@ var testNamer = name.Namer{ var ( testNamespace = "test-namespace" testName = "test-name" - testCluster = v1beta1.Elasticsearch{ + testCluster = esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Namespace: testNamespace, Name: testName, @@ -144,7 +144,7 @@ func Test_canReuseCA(t *testing.T) { func checkCASecrets( t *testing.T, client k8s.Client, - cluster v1beta1.Elasticsearch, + cluster esv1.Elasticsearch, caType CAType, ca *CA, expectedCa *CA, diff --git a/pkg/controller/common/certificates/http/certificates_secret.go b/pkg/controller/common/certificates/http/certificates_secret.go index 9b23f45e350..871f8ebcbe0 100644 --- a/pkg/controller/common/certificates/http/certificates_secret.go +++ b/pkg/controller/common/certificates/http/certificates_secret.go @@ -7,7 +7,7 @@ package http import ( "fmt" - "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" v1 "k8s.io/api/core/v1" @@ -71,7 +71,7 @@ func (s CertificatesSecret) Validate() error { func GetCustomCertificates( c k8s.Client, owner types.NamespacedName, - tls v1beta1.TLSOptions, + tls commonv1.TLSOptions, ) (*CertificatesSecret, error) { secretName := tls.Certificate.SecretName if secretName == "" { diff --git a/pkg/controller/common/certificates/http/dynamic_watches.go b/pkg/controller/common/certificates/http/dynamic_watches.go index e39e5682728..3045de9ced8 100644 --- a/pkg/controller/common/certificates/http/dynamic_watches.go +++ b/pkg/controller/common/certificates/http/dynamic_watches.go @@ -5,7 +5,7 @@ package http import ( - "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/name" "github.com/elastic/cloud-on-k8s/pkg/controller/common/watches" "k8s.io/apimachinery/pkg/types" @@ -17,7 +17,7 @@ func CertificateWatchKey(namer name.Namer, ownerName string) string { } // reconcileDynamicWatches reconciles the dynamic watches needed by the HTTP certificates. -func reconcileDynamicWatches(dynamicWatches watches.DynamicWatches, owner types.NamespacedName, namer name.Namer, tls v1beta1.TLSOptions) error { +func reconcileDynamicWatches(dynamicWatches watches.DynamicWatches, owner types.NamespacedName, namer name.Namer, tls commonv1.TLSOptions) error { // watch the Secret specified in es.Spec.HTTP.TLS.Certificate because if it changes we should reconcile the new // user provided certificates. httpCertificateWatch := watches.NamedWatch{ diff --git a/pkg/controller/common/certificates/http/public_secret_test.go b/pkg/controller/common/certificates/http/public_secret_test.go index 5c592b07b1c..879087ea7e6 100644 --- a/pkg/controller/common/certificates/http/public_secret_test.go +++ b/pkg/controller/common/certificates/http/public_secret_test.go @@ -8,7 +8,7 @@ import ( "encoding/json" "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" @@ -24,7 +24,7 @@ func TestReconcileHTTPCertsPublicSecret(t *testing.T) { tls := loadFileBytes("tls.crt") key := loadFileBytes("tls.key") - owner := &v1beta1.Elasticsearch{ + owner := &esv1.Elasticsearch{ ObjectMeta: v1.ObjectMeta{Name: "test-es-name", Namespace: "test-namespace"}, } @@ -36,7 +36,7 @@ func TestReconcileHTTPCertsPublicSecret(t *testing.T) { }, } - namespacedSecretName := PublicCertsSecretRef(v1beta1.ESNamer, k8s.ExtractNamespacedName(owner)) + namespacedSecretName := PublicCertsSecretRef(esv1.ESNamer, k8s.ExtractNamespacedName(owner)) mkClient := func(t *testing.T, objs ...runtime.Object) k8s.Client { t.Helper() @@ -126,7 +126,7 @@ func TestReconcileHTTPCertsPublicSecret(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { client := tt.client(t) - err := ReconcileHTTPCertsPublicSecret(client, scheme.Scheme, owner, v1beta1.ESNamer, certificate) + err := ReconcileHTTPCertsPublicSecret(client, scheme.Scheme, owner, esv1.ESNamer, certificate) if tt.wantErr { require.Error(t, err, "Failed to reconcile") return diff --git a/pkg/controller/common/certificates/http/reconcile.go b/pkg/controller/common/certificates/http/reconcile.go index f806d6f8a2f..c979bc02de9 100644 --- a/pkg/controller/common/certificates/http/reconcile.go +++ b/pkg/controller/common/certificates/http/reconcile.go @@ -14,7 +14,7 @@ import ( "strings" "time" - "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" "github.com/elastic/cloud-on-k8s/pkg/controller/common/driver" "github.com/elastic/cloud-on-k8s/pkg/controller/common/name" @@ -39,7 +39,7 @@ func ReconcileHTTPCertificates( owner metav1.Object, namer name.Namer, ca *certificates.CA, - tls v1beta1.TLSOptions, + tls commonv1.TLSOptions, labels map[string]string, services []corev1.Service, rotationParams certificates.RotationParams, @@ -70,7 +70,7 @@ func reconcileHTTPInternalCertificatesSecret( scheme *runtime.Scheme, owner metav1.Object, namer name.Namer, - tls v1beta1.TLSOptions, + tls commonv1.TLSOptions, labels map[string]string, svcs []corev1.Service, customCertificates *CertificatesSecret, @@ -166,7 +166,7 @@ func ensureInternalSelfSignedCertificateSecretContents( secret *corev1.Secret, owner types.NamespacedName, namer name.Namer, - tls v1beta1.TLSOptions, + tls commonv1.TLSOptions, svcs []corev1.Service, ca *certificates.CA, rotationParam certificates.RotationParams, @@ -249,7 +249,7 @@ func ensureInternalSelfSignedCertificateSecretContents( func shouldIssueNewHTTPCertificate( owner types.NamespacedName, namer name.Namer, - tls v1beta1.TLSOptions, + tls commonv1.TLSOptions, secret *corev1.Secret, svcs []corev1.Service, ca *certificates.CA, @@ -328,7 +328,7 @@ func shouldIssueNewHTTPCertificate( func createValidatedHTTPCertificateTemplate( owner types.NamespacedName, namer name.Namer, - tls v1beta1.TLSOptions, + tls commonv1.TLSOptions, svcs []corev1.Service, csr *x509.CertificateRequest, certValidity time.Duration, diff --git a/pkg/controller/common/certificates/http/reconcile_test.go b/pkg/controller/common/certificates/http/reconcile_test.go index 6b4a426d98f..623793f6b0c 100644 --- a/pkg/controller/common/certificates/http/reconcile_test.go +++ b/pkg/controller/common/certificates/http/reconcile_test.go @@ -14,8 +14,8 @@ import ( "testing" "time" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" "github.com/elastic/cloud-on-k8s/pkg/controller/common/driver" "github.com/elastic/cloud-on-k8s/pkg/controller/common/watches" @@ -52,7 +52,7 @@ var ( testCA *certificates.CA testRSAPrivateKey *rsa.PrivateKey pemCert []byte - testES = v1beta1.Elasticsearch{ObjectMeta: v1.ObjectMeta{Name: "test-es-name", Namespace: "test-namespace"}} + testES = esv1.Elasticsearch{ObjectMeta: v1.ObjectMeta{Name: "test-es-name", Namespace: "test-namespace"}} testSvc = corev1.Service{ ObjectMeta: v1.ObjectMeta{ Name: "test-service", @@ -85,7 +85,7 @@ func init() { testCSR, _ := x509.ParseCertificateRequest(testCSRBytes) validatedCertificateTemplate := createValidatedHTTPCertificateTemplate( - k8s.ExtractNamespacedName(&testES), v1beta1.ESNamer, testES.Spec.HTTP.TLS, []corev1.Service{testSvc}, testCSR, certificates.DefaultCertValidity, + k8s.ExtractNamespacedName(&testES), esv1.ESNamer, testES.Spec.HTTP.TLS, []corev1.Service{testSvc}, testCSR, certificates.DefaultCertValidity, ) certData, err := testCA.CreateCertificate(*validatedCertificateTemplate) @@ -102,7 +102,7 @@ func TestReconcileHTTPCertificates(t *testing.T) { type args struct { c k8s.Client - es v1beta1.Elasticsearch + es esv1.Elasticsearch ca *certificates.CA services []corev1.Service } @@ -134,12 +134,12 @@ func TestReconcileHTTPCertificates(t *testing.T) { certificates.KeyFileName: key, }, }), - es: v1beta1.Elasticsearch{ + es: esv1.Elasticsearch{ ObjectMeta: v1.ObjectMeta{Name: "test-es-name", Namespace: "test-namespace"}, - Spec: v1beta1.ElasticsearchSpec{ - HTTP: commonv1beta1.HTTPConfig{ - TLS: commonv1beta1.TLSOptions{ - Certificate: commonv1beta1.SecretRef{ + Spec: esv1.ElasticsearchSpec{ + HTTP: commonv1.HTTPConfig{ + TLS: commonv1.TLSOptions{ + Certificate: commonv1.SecretRef{ SecretName: "my-cert", }, }, @@ -165,7 +165,7 @@ func TestReconcileHTTPCertificates(t *testing.T) { } got, err := ReconcileHTTPCertificates( - testDriver, &tt.args.es, v1beta1.ESNamer, tt.args.ca, tt.args.es.Spec.HTTP.TLS, map[string]string{}, tt.args.services, + testDriver, &tt.args.es, esv1.ESNamer, tt.args.ca, tt.args.es.Spec.HTTP.TLS, map[string]string{}, tt.args.services, certificates.RotationParams{ Validity: certificates.DefaultCertValidity, RotateBefore: certificates.DefaultRotateBefore, @@ -187,7 +187,7 @@ func Test_createValidatedHTTPCertificateTemplate(t *testing.T) { sanIPv6 := "2001:db8:0:85a3:0:0:ac1f:8001" type args struct { - es v1beta1.Elasticsearch + es esv1.Elasticsearch svcs []corev1.Service certValidity time.Duration } @@ -199,13 +199,13 @@ func Test_createValidatedHTTPCertificateTemplate(t *testing.T) { { name: "with svcs and user-provided SANs", args: args{ - es: v1beta1.Elasticsearch{ + es: esv1.Elasticsearch{ ObjectMeta: v1.ObjectMeta{Namespace: "test", Name: "test"}, - Spec: v1beta1.ElasticsearchSpec{ - HTTP: commonv1beta1.HTTPConfig{ - TLS: commonv1beta1.TLSOptions{ - SelfSignedCertificate: &commonv1beta1.SelfSignedCertificate{ - SubjectAlternativeNames: []commonv1beta1.SubjectAlternativeName{ + Spec: esv1.ElasticsearchSpec{ + HTTP: commonv1.HTTPConfig{ + TLS: commonv1.TLSOptions{ + SelfSignedCertificate: &commonv1.SelfSignedCertificate{ + SubjectAlternativeNames: []commonv1.SubjectAlternativeName{ { DNS: sanDNS1, }, @@ -252,7 +252,7 @@ func Test_createValidatedHTTPCertificateTemplate(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got := createValidatedHTTPCertificateTemplate( k8s.ExtractNamespacedName(&tt.args.es), - v1beta1.ESNamer, + esv1.ESNamer, tt.args.es.Spec.HTTP.TLS, tt.args.svcs, &x509.CertificateRequest{}, @@ -267,10 +267,10 @@ func Test_createValidatedHTTPCertificateTemplate(t *testing.T) { func Test_shouldIssueNewCertificate(t *testing.T) { esWithSAN := testES.DeepCopy() - esWithSAN.Spec.HTTP = commonv1beta1.HTTPConfig{ - TLS: commonv1beta1.TLSOptions{ - SelfSignedCertificate: &commonv1beta1.SelfSignedCertificate{ - SubjectAlternativeNames: []commonv1beta1.SubjectAlternativeName{ + esWithSAN.Spec.HTTP = commonv1.HTTPConfig{ + TLS: commonv1.TLSOptions{ + SelfSignedCertificate: &commonv1.SelfSignedCertificate{ + SubjectAlternativeNames: []commonv1.SubjectAlternativeName{ { DNS: "search.example.com", }, @@ -279,7 +279,7 @@ func Test_shouldIssueNewCertificate(t *testing.T) { }, } type args struct { - es v1beta1.Elasticsearch + es esv1.Elasticsearch secret corev1.Secret rotateBefore time.Duration } @@ -354,7 +354,7 @@ func Test_shouldIssueNewCertificate(t *testing.T) { t.Run(tt.name, func(t *testing.T) { if got := shouldIssueNewHTTPCertificate( k8s.ExtractNamespacedName(&tt.args.es), - v1beta1.ESNamer, + esv1.ESNamer, tt.args.es.Spec.HTTP.TLS, &tt.args.secret, []corev1.Service{testSvc}, diff --git a/pkg/controller/common/deployment/reconcile_test.go b/pkg/controller/common/deployment/reconcile_test.go index 2df434ccdb3..8bec5861f8f 100644 --- a/pkg/controller/common/deployment/reconcile_test.go +++ b/pkg/controller/common/deployment/reconcile_test.go @@ -7,7 +7,7 @@ package deployment import ( "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/hash" commonscheme "github.com/elastic/cloud-on-k8s/pkg/controller/common/scheme" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" @@ -61,7 +61,7 @@ func TestReconcile(t *testing.T) { Replicas: pointer.Int32(2), }, } - owner := v1beta1.Elasticsearch{} // can be any type + owner := esv1.Elasticsearch{} // can be any type // should create a new deployment reconciled, err := Reconcile(k8sClient, scheme.Scheme, expected, &owner) diff --git a/pkg/controller/common/finalizer/finalizers_test.go b/pkg/controller/common/finalizer/finalizers_test.go index 36e2822f3a8..dae4af5496c 100644 --- a/pkg/controller/common/finalizer/finalizers_test.go +++ b/pkg/controller/common/finalizer/finalizers_test.go @@ -7,17 +7,17 @@ package finalizer import ( "testing" - kibanatype "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/stretchr/testify/assert" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" ) func TestRemoveAll(t *testing.T) { - sampleObject := &kibanatype.Kibana{ - ObjectMeta: v1.ObjectMeta{ + sampleObject := &kbv1.Kibana{ + ObjectMeta: metav1.ObjectMeta{ Name: "foo", Namespace: "bar", Finalizers: []string{ @@ -46,14 +46,14 @@ func TestRemoveAll(t *testing.T) { { name: "No Finalizers", args: args{ - c: k8s.WrappedFakeClient(&kibanatype.Kibana{ - ObjectMeta: v1.ObjectMeta{ + c: k8s.WrappedFakeClient(&kbv1.Kibana{ + ObjectMeta: metav1.ObjectMeta{ Name: "foo", Namespace: "bar", }, }), - obj: &kibanatype.Kibana{ - ObjectMeta: v1.ObjectMeta{ + obj: &kbv1.Kibana{ + ObjectMeta: metav1.ObjectMeta{ Name: "foo", Namespace: "bar", }, @@ -78,7 +78,7 @@ func TestRemoveAll(t *testing.T) { if err := RemoveAll(tt.args.c, tt.args.obj); (err != nil) != tt.wantErr { t.Errorf("RemoveAll() error = %v, wantErr %v", err, tt.wantErr) } - savedObject := &kibanatype.Kibana{} + savedObject := &kbv1.Kibana{} err := tt.args.c.Get(types.NamespacedName{ Namespace: "bar", Name: "foo", diff --git a/pkg/controller/common/keystore/resources.go b/pkg/controller/common/keystore/resources.go index dfc10be1c5a..6b5de6e2f96 100644 --- a/pkg/controller/common/keystore/resources.go +++ b/pkg/controller/common/keystore/resources.go @@ -7,13 +7,14 @@ package keystore import ( "strings" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/driver" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/name" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" logf "sigs.k8s.io/controller-runtime/pkg/log" + + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/driver" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/name" ) var log = logf.Log.WithName("keystore") @@ -33,7 +34,7 @@ type Resources struct { type HasKeystore interface { metav1.Object runtime.Object - SecureSettings() []commonv1beta1.SecretSource + SecureSettings() []commonv1.SecretSource } // NewResources optionally returns a volume and init container to include in pods, diff --git a/pkg/controller/common/keystore/resources_test.go b/pkg/controller/common/keystore/resources_test.go index 65d82510705..e27aeb7864e 100644 --- a/pkg/controller/common/keystore/resources_test.go +++ b/pkg/controller/common/keystore/resources_test.go @@ -7,8 +7,8 @@ package keystore import ( "testing" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/driver" watches2 "github.com/elastic/cloud-on-k8s/pkg/controller/common/watches" "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/name" @@ -39,22 +39,22 @@ var ( "key1": []byte("value1"), }, } - testSecureSettingsSecretRef = commonv1beta1.SecretSource{ + testSecureSettingsSecretRef = commonv1.SecretSource{ SecretName: testSecureSettingsSecretName, } - testKibana = v1beta1.Kibana{ + testKibana = kbv1.Kibana{ ObjectMeta: metav1.ObjectMeta{ Namespace: "namespace", Name: "kibana", }, } - testKibanaWithSecureSettings = v1beta1.Kibana{ + testKibanaWithSecureSettings = kbv1.Kibana{ TypeMeta: metav1.TypeMeta{ Kind: "kibana", }, ObjectMeta: testKibana.ObjectMeta, - Spec: v1beta1.KibanaSpec{ - SecureSettings: []commonv1beta1.SecretSource{testSecureSettingsSecretRef}, + Spec: kbv1.KibanaSpec{ + SecureSettings: []commonv1.SecretSource{testSecureSettingsSecretRef}, }, } ) @@ -64,7 +64,7 @@ func TestResources(t *testing.T) { tests := []struct { name string client k8s.Client - kb v1beta1.Kibana + kb kbv1.Kibana wantNil bool wantContainers *corev1.Container wantVersion string diff --git a/pkg/controller/common/keystore/user_secret.go b/pkg/controller/common/keystore/user_secret.go index c330bacf09e..cf8fce0ca1c 100644 --- a/pkg/controller/common/keystore/user_secret.go +++ b/pkg/controller/common/keystore/user_secret.go @@ -8,7 +8,14 @@ import ( "fmt" "reflect" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" + corev1 "k8s.io/api/core/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/types" + "k8s.io/client-go/tools/record" + + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/driver" "github.com/elastic/cloud-on-k8s/pkg/controller/common/events" "github.com/elastic/cloud-on-k8s/pkg/controller/common/name" @@ -16,12 +23,6 @@ import ( "github.com/elastic/cloud-on-k8s/pkg/controller/common/volume" "github.com/elastic/cloud-on-k8s/pkg/controller/common/watches" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" - corev1 "k8s.io/api/core/v1" - apierrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/types" - "k8s.io/client-go/tools/record" ) const secureSettingsSecretSuffix = "secure-settings" @@ -139,7 +140,7 @@ func retrieveUserSecrets(c k8s.Client, recorder record.EventRecorder, hasKeystor return userSecrets, nil } -func retrieveUserSecret(c k8s.Client, recorder record.EventRecorder, hasKeystore HasKeystore, secretSrc commonv1beta1.SecretSource) (*corev1.Secret, bool, error) { +func retrieveUserSecret(c k8s.Client, recorder record.EventRecorder, hasKeystore HasKeystore, secretSrc commonv1.SecretSource) (*corev1.Secret, bool, error) { namespace := hasKeystore.GetNamespace() secretName := secretSrc.SecretName @@ -204,7 +205,7 @@ func SecureSettingsWatchName(namespacedName types.NamespacedName) string { // Only one watch per cluster is registered: // - if it already exists with a different secret, it is replaced to watch the new secret. // - if the given user secret is nil, the watch is removed. -func watchSecureSettings(watched watches.DynamicWatches, secureSettingsRef []commonv1beta1.SecretSource, nn types.NamespacedName) error { +func watchSecureSettings(watched watches.DynamicWatches, secureSettingsRef []commonv1.SecretSource, nn types.NamespacedName) error { watchName := SecureSettingsWatchName(nn) if secureSettingsRef == nil { watched.Secrets.RemoveHandlerForKey(watchName) diff --git a/pkg/controller/common/keystore/user_secret_test.go b/pkg/controller/common/keystore/user_secret_test.go index 00347ae52bf..295be417668 100644 --- a/pkg/controller/common/keystore/user_secret_test.go +++ b/pkg/controller/common/keystore/user_secret_test.go @@ -8,21 +8,23 @@ import ( "reflect" "testing" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/driver" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/name" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/volume" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/watches" - kbname "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/name" - "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/go-test/deep" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes/scheme" + clientgoscheme "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/tools/record" + + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/driver" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/name" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/volume" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/watches" + kbname "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/name" + "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" ) func Test_secureSettingsWatchName(t *testing.T) { @@ -49,7 +51,7 @@ func Test_secureSettingsVolume(t *testing.T) { name string c k8s.Client w watches.DynamicWatches - kb v1beta1.Kibana + kb kbv1.Kibana wantVolume *volume.SecretVolume wantVersion string wantWatches []string @@ -130,14 +132,13 @@ func Test_secureSettingsVolume(t *testing.T) { func Test_reconcileSecureSettings(t *testing.T) { true := true - type args struct { c k8s.Client hasKeystore HasKeystore userSecrets []corev1.Secret namer name.Namer } - kibanaFixture := &v1beta1.Kibana{ + kibanaFixture := &kbv1.Kibana{ ObjectMeta: metav1.ObjectMeta{ Name: "kb", Namespace: "ns", @@ -148,7 +149,7 @@ func Test_reconcileSecureSettings(t *testing.T) { Namespace: "ns", OwnerReferences: []metav1.OwnerReference{ { - APIVersion: "kibana.k8s.elastic.co/v1beta1", + APIVersion: "kibana.k8s.elastic.co/v1", Kind: "Kibana", Name: "kb", UID: "", @@ -307,7 +308,7 @@ func Test_reconcileSecureSettings(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := reconcileSecureSettings(tt.args.c, scheme.Scheme, tt.args.hasKeystore, tt.args.userSecrets, tt.args.namer, nil) + got, err := reconcileSecureSettings(tt.args.c, clientgoscheme.Scheme, tt.args.hasKeystore, tt.args.userSecrets, tt.args.namer, nil) if (err != nil) != tt.wantErr { t.Errorf("reconcileSecureSettings() error = %v, wantErr %v", err, tt.wantErr) return @@ -330,25 +331,25 @@ func Test_retrieveUserSecrets(t *testing.T) { "key3": []byte("value3"), }, } - testKibana := &v1beta1.Kibana{ + testKibana := &kbv1.Kibana{ ObjectMeta: metav1.ObjectMeta{ Name: "kb", Namespace: "ns", }, - Spec: v1beta1.KibanaSpec{ - SecureSettings: []commonv1beta1.SecretSource{}, + Spec: kbv1.KibanaSpec{ + SecureSettings: []commonv1.SecretSource{}, }, } tests := []struct { name string - args []commonv1beta1.SecretSource + args []commonv1.SecretSource want []corev1.Secret wantErr bool }{ { name: "secure settings secret with only secret name should be retrieved", - args: []commonv1beta1.SecretSource{ + args: []commonv1.SecretSource{ { SecretName: testSecretName, }, @@ -358,10 +359,10 @@ func Test_retrieveUserSecrets(t *testing.T) { }, { name: "secure settings secret with empty items should fail", - args: []commonv1beta1.SecretSource{ + args: []commonv1.SecretSource{ { SecretName: testSecretName, - Entries: []commonv1beta1.KeyToPath{}, + Entries: []commonv1.KeyToPath{}, }, }, want: nil, @@ -369,10 +370,10 @@ func Test_retrieveUserSecrets(t *testing.T) { }, { name: "secure settings secret with invalid key should fail", - args: []commonv1beta1.SecretSource{ + args: []commonv1.SecretSource{ { SecretName: testSecretName, - Entries: []commonv1beta1.KeyToPath{ + Entries: []commonv1.KeyToPath{ {Key: "unknown"}, }, }, @@ -382,10 +383,10 @@ func Test_retrieveUserSecrets(t *testing.T) { }, { name: "secure settings secret with valid key should be retrieved", - args: []commonv1beta1.SecretSource{ + args: []commonv1.SecretSource{ { SecretName: testSecretName, - Entries: []commonv1beta1.KeyToPath{ + Entries: []commonv1.KeyToPath{ {Key: "key2"}, }, }, @@ -403,10 +404,10 @@ func Test_retrieveUserSecrets(t *testing.T) { }, { name: "secure settings secret with valid key and path should be retrieved", - args: []commonv1beta1.SecretSource{ + args: []commonv1.SecretSource{ { SecretName: testSecretName, - Entries: []commonv1beta1.KeyToPath{ + Entries: []commonv1.KeyToPath{ {Key: "key1"}, {Key: "key3", Path: "newKey"}, }, diff --git a/pkg/controller/common/scheme/scheme.go b/pkg/controller/common/scheme/scheme.go index d29ea30c1cc..650ea964963 100644 --- a/pkg/controller/common/scheme/scheme.go +++ b/pkg/controller/common/scheme/scheme.go @@ -5,11 +5,12 @@ package scheme import ( - apmv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1beta1" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - esv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - kbv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" clientgoscheme "k8s.io/client-go/kubernetes/scheme" + + apmv1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" ) // SetupScheme sets up a scheme with all of the relevant types. This is only needed once for the manager but is often used for tests @@ -19,18 +20,18 @@ func SetupScheme() error { if err != nil { return err } - err = apmv1beta1.AddToScheme(clientgoscheme.Scheme) + err = apmv1.AddToScheme(clientgoscheme.Scheme) if err != nil { return err } - err = commonv1beta1.AddToScheme(clientgoscheme.Scheme) + err = commonv1.AddToScheme(clientgoscheme.Scheme) if err != nil { return err } - err = esv1beta1.AddToScheme(clientgoscheme.Scheme) + err = esv1.AddToScheme(clientgoscheme.Scheme) if err != nil { return err } - err = kbv1beta1.AddToScheme(clientgoscheme.Scheme) + err = kbv1.AddToScheme(clientgoscheme.Scheme) return err } diff --git a/pkg/controller/common/service_control_test.go b/pkg/controller/common/service_control_test.go index 2ee5e9c795f..5078985adf0 100644 --- a/pkg/controller/common/service_control_test.go +++ b/pkg/controller/common/service_control_test.go @@ -7,7 +7,7 @@ package common import ( "testing" - kbtype "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/utils/compare" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/stretchr/testify/require" @@ -17,7 +17,7 @@ import ( ) func TestReconcileService(t *testing.T) { - owner := &kbtype.Kibana{ + owner := &kbv1.Kibana{ ObjectMeta: metav1.ObjectMeta{ Name: "owner-obj", Namespace: "test", diff --git a/pkg/controller/common/user/label.go b/pkg/controller/common/user/label.go index 169dcf054f4..ed0d14653ea 100644 --- a/pkg/controller/common/user/label.go +++ b/pkg/controller/common/user/label.go @@ -5,14 +5,15 @@ package user import ( - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/common" - "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" - "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/reconcile" + + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/common" + "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" + "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" ) const ( @@ -22,7 +23,7 @@ const ( // NewLabelSelectorForElasticsearch returns a labels.Selector that matches the labels as constructed by // NewLabels for the provided cluster name and of for a resource of type "user" -func NewLabelSelectorForElasticsearch(es v1beta1.Elasticsearch) client.MatchingLabels { +func NewLabelSelectorForElasticsearch(es esv1.Elasticsearch) client.MatchingLabels { return client.MatchingLabels(NewLabels(k8s.ExtractNamespacedName(&es))) } diff --git a/pkg/controller/elasticsearch/certificates/ca_reconcile.go b/pkg/controller/elasticsearch/certificates/ca_reconcile.go index 9f3ba510626..3db49e48c29 100644 --- a/pkg/controller/elasticsearch/certificates/ca_reconcile.go +++ b/pkg/controller/elasticsearch/certificates/ca_reconcile.go @@ -8,7 +8,7 @@ import ( "crypto/x509" "time" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates/http" "github.com/elastic/cloud-on-k8s/pkg/controller/common/driver" @@ -34,7 +34,7 @@ type CertificateResources struct { // reconcileGenericResources reconciles the expected generic resources of a cluster. func Reconcile( driver driver.Interface, - es v1beta1.Elasticsearch, + es esv1.Elasticsearch, services []corev1.Service, caRotation certificates.RotationParams, certRotation certificates.RotationParams, @@ -46,7 +46,7 @@ func Reconcile( httpCA, err := certificates.ReconcileCAForOwner( driver.K8sClient(), driver.Scheme(), - v1beta1.ESNamer, + esv1.ESNamer, &es, labels, certificates.HTTPCAType, @@ -65,7 +65,7 @@ func Reconcile( httpCertificates, err := http.ReconcileHTTPCertificates( driver, &es, - v1beta1.ESNamer, + esv1.ESNamer, httpCA, es.Spec.HTTP.TLS, labels, @@ -77,14 +77,14 @@ func Reconcile( } // reconcile http public certs secret: - if err := http.ReconcileHTTPCertsPublicSecret(driver.K8sClient(), driver.Scheme(), &es, v1beta1.ESNamer, httpCertificates); err != nil { + if err := http.ReconcileHTTPCertsPublicSecret(driver.K8sClient(), driver.Scheme(), &es, esv1.ESNamer, httpCertificates); err != nil { return nil, results.WithError(err) } transportCA, err := certificates.ReconcileCAForOwner( driver.K8sClient(), driver.Scheme(), - v1beta1.ESNamer, + esv1.ESNamer, &es, labels, certificates.TransportCAType, diff --git a/pkg/controller/elasticsearch/certificates/transport/csr.go b/pkg/controller/elasticsearch/certificates/transport/csr.go index 46390ce16f2..aea28b608b4 100644 --- a/pkg/controller/elasticsearch/certificates/transport/csr.go +++ b/pkg/controller/elasticsearch/certificates/transport/csr.go @@ -11,17 +11,18 @@ import ( "net" "time" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" - netutil "github.com/elastic/cloud-on-k8s/pkg/utils/net" "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" + + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" + netutil "github.com/elastic/cloud-on-k8s/pkg/utils/net" ) // createValidatedCertificateTemplate validates a CSR and creates a certificate template. func createValidatedCertificateTemplate( pod corev1.Pod, - cluster v1beta1.Elasticsearch, + cluster esv1.Elasticsearch, csr *x509.CertificateRequest, certValidity time.Duration, ) (*certificates.ValidatedCertificateTemplate, error) { @@ -62,7 +63,7 @@ func createValidatedCertificateTemplate( } func buildGeneralNames( - cluster v1beta1.Elasticsearch, + cluster esv1.Elasticsearch, pod corev1.Pod, ) ([]certificates.GeneralName, error) { podIP := net.ParseIP(pod.Status.PodIP) diff --git a/pkg/controller/elasticsearch/certificates/transport/csr_test.go b/pkg/controller/elasticsearch/certificates/transport/csr_test.go index f3a35b82b30..727284213ab 100644 --- a/pkg/controller/elasticsearch/certificates/transport/csr_test.go +++ b/pkg/controller/elasticsearch/certificates/transport/csr_test.go @@ -9,7 +9,7 @@ import ( "net" "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -73,7 +73,7 @@ func Test_buildGeneralNames(t *testing.T) { require.NoError(t, err) type args struct { - cluster v1beta1.Elasticsearch + cluster esv1.Elasticsearch pod corev1.Pod } tests := []struct { diff --git a/pkg/controller/elasticsearch/certificates/transport/pod_secret.go b/pkg/controller/elasticsearch/certificates/transport/pod_secret.go index ddaa72583f5..0e179c95224 100644 --- a/pkg/controller/elasticsearch/certificates/transport/pod_secret.go +++ b/pkg/controller/elasticsearch/certificates/transport/pod_secret.go @@ -13,9 +13,10 @@ import ( "reflect" "time" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" corev1 "k8s.io/api/core/v1" + + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" ) // PodKeyFileName returns the name of the private key entry for a specific pod in a transport certificates secret. @@ -31,7 +32,7 @@ func PodCertFileName(podName string) string { // ensureTransportCertificatesSecretContentsForPod ensures that the transport certificates secret has the correct // content for a specific pod func ensureTransportCertificatesSecretContentsForPod( - es v1beta1.Elasticsearch, + es esv1.Elasticsearch, secret *corev1.Secret, pod corev1.Pod, ca *certificates.CA, @@ -107,7 +108,7 @@ func ensureTransportCertificatesSecretContentsForPod( // - certificate has no SAN extra extension // - certificate SAN and IP does not match pod SAN and IP func shouldIssueNewCertificate( - es v1beta1.Elasticsearch, + es esv1.Elasticsearch, secret corev1.Secret, pod corev1.Pod, privateKey *rsa.PrivateKey, diff --git a/pkg/controller/elasticsearch/certificates/transport/public_secret.go b/pkg/controller/elasticsearch/certificates/transport/public_secret.go index c3d496b6c9b..a54e5904424 100644 --- a/pkg/controller/elasticsearch/certificates/transport/public_secret.go +++ b/pkg/controller/elasticsearch/certificates/transport/public_secret.go @@ -7,7 +7,7 @@ package transport import ( "reflect" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" @@ -23,7 +23,7 @@ import ( func ReconcileTransportCertsPublicSecret( c k8s.Client, scheme *runtime.Scheme, - es v1beta1.Elasticsearch, + es esv1.Elasticsearch, ca *certificates.CA, ) error { esNSN := k8s.ExtractNamespacedName(&es) @@ -67,7 +67,7 @@ func ReconcileTransportCertsPublicSecret( // PublicCertsSecretRef returns the NamespacedName for the Secret containing the publicly available transport CA. func PublicCertsSecretRef(es types.NamespacedName) types.NamespacedName { return types.NamespacedName{ - Name: certificates.PublicSecretName(v1beta1.ESNamer, es.Name, certificates.TransportCAType), + Name: certificates.PublicSecretName(esv1.ESNamer, es.Name, certificates.TransportCAType), Namespace: es.Namespace, } } diff --git a/pkg/controller/elasticsearch/certificates/transport/public_secret_test.go b/pkg/controller/elasticsearch/certificates/transport/public_secret_test.go index fc867117a90..1e14bf50467 100644 --- a/pkg/controller/elasticsearch/certificates/transport/public_secret_test.go +++ b/pkg/controller/elasticsearch/certificates/transport/public_secret_test.go @@ -14,7 +14,7 @@ import ( "testing" "time" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" @@ -27,7 +27,7 @@ import ( ) func TestReconcileTransportCertsPublicSecret(t *testing.T) { - owner := &v1beta1.Elasticsearch{ + owner := &esv1.Elasticsearch{ ObjectMeta: v1.ObjectMeta{Name: "test-es-name", Namespace: "test-namespace"}, } diff --git a/pkg/controller/elasticsearch/certificates/transport/reconcile.go b/pkg/controller/elasticsearch/certificates/transport/reconcile.go index 3c5a9f2eeca..9e380918db7 100644 --- a/pkg/controller/elasticsearch/certificates/transport/reconcile.go +++ b/pkg/controller/elasticsearch/certificates/transport/reconcile.go @@ -9,7 +9,7 @@ import ( "reflect" "strings" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/annotation" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" @@ -31,7 +31,7 @@ func ReconcileTransportCertificatesSecrets( c k8s.Client, scheme *runtime.Scheme, ca *certificates.CA, - es v1beta1.Elasticsearch, + es esv1.Elasticsearch, rotationParams certificates.RotationParams, ) (reconcile.Result, error) { var pods corev1.PodList @@ -110,12 +110,12 @@ func ReconcileTransportCertificatesSecrets( func ensureTransportCertificatesSecretExists( c k8s.Client, scheme *runtime.Scheme, - es v1beta1.Elasticsearch, + es esv1.Elasticsearch, ) (*corev1.Secret, error) { expected := corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Namespace: es.Namespace, - Name: v1beta1.TransportCertificatesSecret(es.Name), + Name: esv1.TransportCertificatesSecret(es.Name), Labels: map[string]string{ // a label showing which es these certificates belongs to diff --git a/pkg/controller/elasticsearch/certificates/transport/reconcile_test.go b/pkg/controller/elasticsearch/certificates/transport/reconcile_test.go index 05595ede629..0273c7eff46 100644 --- a/pkg/controller/elasticsearch/certificates/transport/reconcile_test.go +++ b/pkg/controller/elasticsearch/certificates/transport/reconcile_test.go @@ -7,7 +7,7 @@ package transport import ( "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/stretchr/testify/assert" @@ -21,7 +21,7 @@ import ( func Test_ensureTransportCertificateSecretExists(t *testing.T) { defaultSecret := &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ - Name: v1beta1.TransportCertificatesSecret(testES.Name), + Name: esv1.TransportCertificatesSecret(testES.Name), Namespace: testES.Namespace, Labels: map[string]string{ label.ClusterNameLabelName: testES.Name, @@ -39,7 +39,7 @@ func Test_ensureTransportCertificateSecretExists(t *testing.T) { type args struct { c k8s.Client scheme *runtime.Scheme - owner v1beta1.Elasticsearch + owner esv1.Elasticsearch } tests := []struct { name string diff --git a/pkg/controller/elasticsearch/certificates/transport/transport_fixtures_test.go b/pkg/controller/elasticsearch/certificates/transport/transport_fixtures_test.go index c4f805b1cac..070d4c8ca62 100644 --- a/pkg/controller/elasticsearch/certificates/transport/transport_fixtures_test.go +++ b/pkg/controller/elasticsearch/certificates/transport/transport_fixtures_test.go @@ -11,7 +11,7 @@ import ( "crypto/x509/pkix" "encoding/pem" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -27,7 +27,7 @@ var ( certData []byte pemCert []byte testIP = "1.2.3.4" - testES = v1beta1.Elasticsearch{ + testES = esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{Name: "test-es-name", Namespace: "test-namespace"}, } testPod = corev1.Pod{ diff --git a/pkg/controller/elasticsearch/cleanup/resources.go b/pkg/controller/elasticsearch/cleanup/resources.go index 7b51170e634..1eea7eeb10e 100644 --- a/pkg/controller/elasticsearch/cleanup/resources.go +++ b/pkg/controller/elasticsearch/cleanup/resources.go @@ -7,9 +7,6 @@ package cleanup import ( "time" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" - "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" @@ -18,6 +15,10 @@ import ( "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" logf "sigs.k8s.io/controller-runtime/pkg/log" + + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" + "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" ) var log = logf.Log.WithName("cleanup") @@ -35,7 +36,7 @@ func IsTooYoungForGC(object metav1.Object) bool { } // DeleteOrphanedSecrets cleans up secrets that are not needed anymore for the given es cluster. -func DeleteOrphanedSecrets(c k8s.Client, es v1beta1.Elasticsearch) error { +func DeleteOrphanedSecrets(c k8s.Client, es esv1.Elasticsearch) error { var secrets corev1.SecretList ns := client.InNamespace(es.Namespace) matchLabels := label.NewLabelSelectorForElasticsearch(es) diff --git a/pkg/controller/elasticsearch/cleanup/resources_test.go b/pkg/controller/elasticsearch/cleanup/resources_test.go index ca80e5dd6f2..d3d7ce3a2fa 100644 --- a/pkg/controller/elasticsearch/cleanup/resources_test.go +++ b/pkg/controller/elasticsearch/cleanup/resources_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/stretchr/testify/require" @@ -70,7 +70,7 @@ func TestDeleteOrphanedSecrets(t *testing.T) { now := time.Now() whileAgo := time.Now().Add(-DeleteAfter).Add(-1 * time.Minute) - es := v1beta1.Elasticsearch{ + es := esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Namespace: "ns1", Name: "es1", @@ -89,7 +89,7 @@ func TestDeleteOrphanedSecrets(t *testing.T) { tests := []struct { name string client k8s.Client - es v1beta1.Elasticsearch + es esv1.Elasticsearch secretsAfterCleanup []*corev1.Secret }{ { diff --git a/pkg/controller/elasticsearch/configmap/configmap.go b/pkg/controller/elasticsearch/configmap/configmap.go index 86f0b23c9c9..5ea296a814f 100644 --- a/pkg/controller/elasticsearch/configmap/configmap.go +++ b/pkg/controller/elasticsearch/configmap/configmap.go @@ -5,15 +5,16 @@ package configmap import ( - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/initcontainer" - "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" - "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/nodespec" - "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" + + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/initcontainer" + "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" + "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/nodespec" + "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" ) // NewConfigMapWithData constructs a new config map with the given data @@ -30,14 +31,14 @@ func NewConfigMapWithData(es types.NamespacedName, data map[string]string) corev // ReconcileScriptsConfigMap reconciles a configmap containing scripts used by // init containers and readiness probe. -func ReconcileScriptsConfigMap(c k8s.Client, scheme *runtime.Scheme, es v1beta1.Elasticsearch) error { +func ReconcileScriptsConfigMap(c k8s.Client, scheme *runtime.Scheme, es esv1.Elasticsearch) error { fsScript, err := initcontainer.RenderPrepareFsScript() if err != nil { return err } scriptsConfigMap := NewConfigMapWithData( - types.NamespacedName{Namespace: es.Namespace, Name: v1beta1.ScriptsConfigMap(es.Name)}, + types.NamespacedName{Namespace: es.Namespace, Name: esv1.ScriptsConfigMap(es.Name)}, map[string]string{ nodespec.ReadinessProbeScriptConfigKey: nodespec.ReadinessProbeScript, initcontainer.PrepareFsScriptConfigKey: fsScript, diff --git a/pkg/controller/elasticsearch/configmap/configmap_control.go b/pkg/controller/elasticsearch/configmap/configmap_control.go index 4faff37037e..9f197ab9006 100644 --- a/pkg/controller/elasticsearch/configmap/configmap_control.go +++ b/pkg/controller/elasticsearch/configmap/configmap_control.go @@ -7,18 +7,19 @@ package configmap import ( "reflect" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" - "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" + + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" + "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" ) // ReconcileConfigMap checks for an existing config map and updates it or creates one if it does not exist. func ReconcileConfigMap( c k8s.Client, scheme *runtime.Scheme, - es v1beta1.Elasticsearch, + es esv1.Elasticsearch, expected corev1.ConfigMap, ) error { reconciled := &corev1.ConfigMap{} diff --git a/pkg/controller/elasticsearch/driver/bootstrap.go b/pkg/controller/elasticsearch/driver/bootstrap.go index 4b8d8d2a525..a875e67c365 100644 --- a/pkg/controller/elasticsearch/driver/bootstrap.go +++ b/pkg/controller/elasticsearch/driver/bootstrap.go @@ -5,7 +5,7 @@ package driver import ( - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/observer" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/sset" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/version/zen2" @@ -19,12 +19,12 @@ const ( ) // AnnotatedForBootstrap returns true if the cluster has been annotated with the UUID already. -func AnnotatedForBootstrap(cluster v1beta1.Elasticsearch) bool { +func AnnotatedForBootstrap(cluster esv1.Elasticsearch) bool { _, bootstrapped := cluster.Annotations[ClusterUUIDAnnotationName] return bootstrapped } -func ReconcileClusterUUID(c k8s.Client, cluster *v1beta1.Elasticsearch, observedState observer.State) error { +func ReconcileClusterUUID(c k8s.Client, cluster *esv1.Elasticsearch, observedState observer.State) error { reBootstrap, err := clusterNeedsReBootstrap(c, cluster) if err != nil { return err @@ -50,7 +50,7 @@ func ReconcileClusterUUID(c k8s.Client, cluster *v1beta1.Elasticsearch, observed return nil } -func removeUUIDAnnotation(client k8s.Client, es *v1beta1.Elasticsearch) error { +func removeUUIDAnnotation(client k8s.Client, es *esv1.Elasticsearch) error { annotations := es.Annotations if annotations == nil { return nil @@ -62,7 +62,7 @@ func removeUUIDAnnotation(client k8s.Client, es *v1beta1.Elasticsearch) error { // clusterNeedsReBootstrap is true if we are updating a single master cluster from 6.x to 7.x // because we lose the 'cluster' when rolling the single master node. // Invariant: no grow and shrink -func clusterNeedsReBootstrap(client k8s.Client, es *v1beta1.Elasticsearch) (bool, error) { +func clusterNeedsReBootstrap(client k8s.Client, es *esv1.Elasticsearch) (bool, error) { initialZen2Upgrade, err := zen2.IsInitialZen2Upgrade(client, *es) if err != nil { return false, err @@ -82,7 +82,7 @@ func clusterIsBootstrapped(observedState observer.State) bool { } // annotateWithUUID annotates the cluster with its UUID, to mark it as "bootstrapped". -func annotateWithUUID(cluster *v1beta1.Elasticsearch, observedState observer.State, c k8s.Client) error { +func annotateWithUUID(cluster *esv1.Elasticsearch, observedState observer.State, c k8s.Client) error { log.Info("Annotating bootstrapped cluster with its UUID", "namespace", cluster.Namespace, "es_name", cluster.Name) if cluster.Annotations == nil { cluster.Annotations = make(map[string]string) diff --git a/pkg/controller/elasticsearch/driver/bootstrap_test.go b/pkg/controller/elasticsearch/driver/bootstrap_test.go index 2b9fba9d20b..bb8de94d2ac 100644 --- a/pkg/controller/elasticsearch/driver/bootstrap_test.go +++ b/pkg/controller/elasticsearch/driver/bootstrap_test.go @@ -7,7 +7,7 @@ package driver import ( "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" esclient "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/observer" @@ -18,20 +18,20 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -func bootstrappedES() *v1beta1.Elasticsearch { - return &v1beta1.Elasticsearch{ +func bootstrappedES() *esv1.Elasticsearch { + return &esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster", Annotations: map[string]string{ClusterUUIDAnnotationName: "uuid"}, }, - Spec: v1beta1.ElasticsearchSpec{Version: "7.3.0"}, + Spec: esv1.ElasticsearchSpec{Version: "7.3.0"}, } } -func bootstrappedESWithChangeBudget(maxSurge, maxUnavailable *int32) *v1beta1.Elasticsearch { +func bootstrappedESWithChangeBudget(maxSurge, maxUnavailable *int32) *esv1.Elasticsearch { es := bootstrappedES() - es.Spec.UpdateStrategy = v1beta1.UpdateStrategy{ - ChangeBudget: v1beta1.ChangeBudget{ + es.Spec.UpdateStrategy = esv1.UpdateStrategy{ + ChangeBudget: esv1.ChangeBudget{ MaxSurge: maxSurge, MaxUnavailable: maxUnavailable, }, @@ -40,20 +40,20 @@ func bootstrappedESWithChangeBudget(maxSurge, maxUnavailable *int32) *v1beta1.El return es } -func notBootstrappedES() *v1beta1.Elasticsearch { - return &v1beta1.Elasticsearch{ +func notBootstrappedES() *esv1.Elasticsearch { + return &esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{Name: "cluster"}, - Spec: v1beta1.ElasticsearchSpec{Version: "7.3.0"}, + Spec: esv1.ElasticsearchSpec{Version: "7.3.0"}, } } -func reBootstrappingES() *v1beta1.Elasticsearch { - return &v1beta1.Elasticsearch{ +func reBootstrappingES() *esv1.Elasticsearch { + return &esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster", Annotations: map[string]string{}, }, - Spec: v1beta1.ElasticsearchSpec{Version: "7.3.0"}, + Spec: esv1.ElasticsearchSpec{Version: "7.3.0"}, } } @@ -71,7 +71,7 @@ func Test_annotateWithUUID(t *testing.T) { require.NoError(t, err) require.True(t, AnnotatedForBootstrap(*cluster)) - var retrieved v1beta1.Elasticsearch + var retrieved esv1.Elasticsearch err = k8sClient.Get(k8s.ExtractNamespacedName(cluster), &retrieved) require.NoError(t, err) require.True(t, AnnotatedForBootstrap(retrieved)) @@ -116,9 +116,9 @@ func TestReconcileClusterUUID(t *testing.T) { tests := []struct { name string c k8s.Client - cluster *v1beta1.Elasticsearch + cluster *esv1.Elasticsearch observedState observer.State - wantCluster *v1beta1.Elasticsearch + wantCluster *esv1.Elasticsearch }{ { name: "already annotated", diff --git a/pkg/controller/elasticsearch/driver/downscale.go b/pkg/controller/elasticsearch/driver/downscale.go index d3e54af4463..60b9ac54d93 100644 --- a/pkg/controller/elasticsearch/driver/downscale.go +++ b/pkg/controller/elasticsearch/driver/downscale.go @@ -5,7 +5,7 @@ package driver import ( - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/events" "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" esclient "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" @@ -72,7 +72,7 @@ func HandleDownscale( } // deleteStatefulSets deletes the given StatefulSets along with their associated resources. -func deleteStatefulSets(toDelete sset.StatefulSetList, k8sClient k8s.Client, es v1beta1.Elasticsearch) error { +func deleteStatefulSets(toDelete sset.StatefulSetList, k8sClient k8s.Client, es esv1.Elasticsearch) error { for _, toDelete := range toDelete { if err := deleteStatefulSetResources(k8sClient, es, toDelete); err != nil { return err @@ -153,7 +153,7 @@ func attemptDownscale( // deleteStatefulSetResources deletes the given StatefulSet along with the corresponding // headless service and configuration secret. -func deleteStatefulSetResources(k8sClient k8s.Client, es v1beta1.Elasticsearch, statefulSet appsv1.StatefulSet) error { +func deleteStatefulSetResources(k8sClient k8s.Client, es esv1.Elasticsearch, statefulSet appsv1.StatefulSet) error { headlessSvc := nodespec.HeadlessService(k8s.ExtractNamespacedName(&es), statefulSet.Name) err := k8sClient.Delete(&headlessSvc) if err != nil && !apierrors.IsNotFound(err) { @@ -240,7 +240,7 @@ func doDownscale(downscaleCtx downscaleContext, downscale ssetDownscale, actualS func updateZenSettingsForDownscale( c k8s.Client, esClient esclient.Client, - es v1beta1.Elasticsearch, + es esv1.Elasticsearch, reconcileState *reconcile.State, actualStatefulSets sset.StatefulSetList, excludeNodes ...string, @@ -261,7 +261,7 @@ func updateZenSettingsForDownscale( func maybeUpdateZen1ForDownscale( c k8s.Client, esClient esclient.Client, - es v1beta1.Elasticsearch, + es esv1.Elasticsearch, reconcileState *reconcile.State, actualStatefulSets sset.StatefulSetList) error { // Check if we have at least one Zen1 compatible pod or StatefulSet in flight. diff --git a/pkg/controller/elasticsearch/driver/downscale_invariants.go b/pkg/controller/elasticsearch/driver/downscale_invariants.go index 9065a968eba..33a9401e8be 100644 --- a/pkg/controller/elasticsearch/driver/downscale_invariants.go +++ b/pkg/controller/elasticsearch/driver/downscale_invariants.go @@ -5,12 +5,13 @@ package driver import ( - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + appsv1 "k8s.io/api/apps/v1" + + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/reconcile" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/sset" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" - appsv1 "k8s.io/api/apps/v1" ) const ( @@ -51,7 +52,7 @@ type downscaleState struct { } // newDownscaleState creates a new downscaleState. -func newDownscaleState(c k8s.Client, es v1beta1.Elasticsearch) (*downscaleState, error) { +func newDownscaleState(c k8s.Client, es esv1.Elasticsearch) (*downscaleState, error) { // retrieve the number of masters running ready actualPods, err := sset.GetActualPodsForCluster(c, es) if err != nil { diff --git a/pkg/controller/elasticsearch/driver/downscale_invariants_test.go b/pkg/controller/elasticsearch/driver/downscale_invariants_test.go index 5c06f0d7593..e7269c5af03 100644 --- a/pkg/controller/elasticsearch/driver/downscale_invariants_test.go +++ b/pkg/controller/elasticsearch/driver/downscale_invariants_test.go @@ -8,7 +8,7 @@ import ( "reflect" "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/pkg/utils/pointer" @@ -20,9 +20,9 @@ import ( ) func Test_newDownscaleState(t *testing.T) { - es := v1beta1.Elasticsearch{ + es := esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{Namespace: ssetMaster3Replicas.Namespace, Name: "name"}, - Spec: v1beta1.ElasticsearchSpec{NodeSets: []v1beta1.NodeSet{{Count: 4}}}, + Spec: esv1.ElasticsearchSpec{NodeSets: []esv1.NodeSet{{Count: 4}}}, } tests := []struct { diff --git a/pkg/controller/elasticsearch/driver/downscale_test.go b/pkg/controller/elasticsearch/driver/downscale_test.go index 837b3ccef9d..5b950b3e624 100644 --- a/pkg/controller/elasticsearch/driver/downscale_test.go +++ b/pkg/controller/elasticsearch/driver/downscale_test.go @@ -8,7 +8,7 @@ import ( "reflect" "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/expectations" "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" commonscheme "github.com/elastic/cloud-on-k8s/pkg/controller/common/scheme" @@ -139,14 +139,14 @@ func TestHandleDownscale(t *testing.T) { downscaleCtx := downscaleContext{ k8sClient: k8sClient, expectations: expectations.NewExpectations(k8sClient), - reconcileState: reconcile.NewState(v1beta1.Elasticsearch{}), + reconcileState: reconcile.NewState(esv1.Elasticsearch{}), shardLister: migration.NewFakeShardLister( esclient.Shards{ {Index: "index-1", Shard: "0", State: esclient.STARTED, NodeName: "ssetData4Replicas-2"}, }, ), esClient: esClient, - es: v1beta1.Elasticsearch{ + es: esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Name: clusterName, Namespace: "ns", @@ -719,7 +719,7 @@ func Test_attemptDownscale(t *testing.T) { downscaleCtx := downscaleContext{ k8sClient: k8sClient, expectations: expectations.NewExpectations(k8sClient), - reconcileState: reconcile.NewState(v1beta1.Elasticsearch{}), + reconcileState: reconcile.NewState(esv1.Elasticsearch{}), shardLister: migration.NewFakeShardLister(esclient.Shards{}), esClient: &fakeESClient{}, } @@ -824,7 +824,7 @@ func Test_doDownscale_zen2VotingConfigExclusions(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - es := v1beta1.Elasticsearch{ + es := esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Namespace: ssetMasters.Namespace, Name: "es", @@ -847,7 +847,7 @@ func Test_doDownscale_zen2VotingConfigExclusions(t *testing.T) { downscaleCtx := downscaleContext{ k8sClient: k8sClient, expectations: expectations.NewExpectations(k8sClient), - reconcileState: reconcile.NewState(v1beta1.Elasticsearch{}), + reconcileState: reconcile.NewState(esv1.Elasticsearch{}), esClient: esClient, es: es, } @@ -865,7 +865,7 @@ func Test_doDownscale_zen2VotingConfigExclusions(t *testing.T) { func Test_doDownscale_zen1MinimumMasterNodes(t *testing.T) { require.NoError(t, commonscheme.SetupScheme()) - es := v1beta1.Elasticsearch{ObjectMeta: metav1.ObjectMeta{Namespace: ssetMaster3Replicas.Namespace, Name: "es"}} + es := esv1.Elasticsearch{ObjectMeta: metav1.ObjectMeta{Namespace: ssetMaster3Replicas.Namespace, Name: "es"}} ssetMasters := sset.TestSset{Name: "masters", Version: "6.8.0", Replicas: 3, Master: true, Data: false}.Build() masterPods := []corev1.Pod{ sset.TestPod{ @@ -945,7 +945,7 @@ func Test_doDownscale_zen1MinimumMasterNodes(t *testing.T) { downscaleCtx := downscaleContext{ k8sClient: k8sClient, expectations: expectations.NewExpectations(k8sClient), - reconcileState: reconcile.NewState(v1beta1.Elasticsearch{}), + reconcileState: reconcile.NewState(esv1.Elasticsearch{}), esClient: esClient, es: es, } @@ -962,7 +962,7 @@ func Test_doDownscale_zen1MinimumMasterNodes(t *testing.T) { } func Test_deleteStatefulSetResources(t *testing.T) { - es := v1beta1.Elasticsearch{ObjectMeta: metav1.ObjectMeta{Namespace: "ns", Name: "cluster"}} + es := esv1.Elasticsearch{ObjectMeta: metav1.ObjectMeta{Namespace: "ns", Name: "cluster"}} sset := sset.TestSset{Namespace: "ns", Name: "sset", ClusterName: es.Name}.Build() cfg := settings.ConfigSecret(es, sset.Name, []byte("fake config data")) svc := nodespec.HeadlessService(k8s.ExtractNamespacedName(&es), sset.Name) @@ -994,7 +994,7 @@ func Test_deleteStatefulSetResources(t *testing.T) { } func Test_deleteStatefulSets(t *testing.T) { - es := v1beta1.Elasticsearch{ObjectMeta: metav1.ObjectMeta{Namespace: "ns", Name: "cluster"}} + es := esv1.Elasticsearch{ObjectMeta: metav1.ObjectMeta{Namespace: "ns", Name: "cluster"}} tests := []struct { name string toDelete sset.StatefulSetList diff --git a/pkg/controller/elasticsearch/driver/downscale_utils.go b/pkg/controller/elasticsearch/driver/downscale_utils.go index 652f5105933..dbac45da223 100644 --- a/pkg/controller/elasticsearch/driver/downscale_utils.go +++ b/pkg/controller/elasticsearch/driver/downscale_utils.go @@ -5,7 +5,7 @@ package driver import ( - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/expectations" esclient "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/observer" @@ -28,7 +28,7 @@ type downscaleContext struct { reconcileState *reconcile.State expectations *expectations.Expectations // ES cluster - es v1beta1.Elasticsearch + es esv1.Elasticsearch } func newDownscaleContext( @@ -39,7 +39,7 @@ func newDownscaleContext( reconcileState *reconcile.State, expectations *expectations.Expectations, // ES cluster - es v1beta1.Elasticsearch, + es esv1.Elasticsearch, ) downscaleContext { return downscaleContext{ k8sClient: k8sClient, diff --git a/pkg/controller/elasticsearch/driver/driver.go b/pkg/controller/elasticsearch/driver/driver.go index 9433149fad2..9caf56705e7 100644 --- a/pkg/controller/elasticsearch/driver/driver.go +++ b/pkg/controller/elasticsearch/driver/driver.go @@ -9,7 +9,7 @@ import ( "fmt" "time" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common" commondriver "github.com/elastic/cloud-on-k8s/pkg/controller/common/driver" "github.com/elastic/cloud-on-k8s/pkg/controller/common/events" @@ -61,7 +61,7 @@ type DefaultDriverParameters struct { OperatorParameters operator.Parameters // ES is the Elasticsearch resource to reconcile - ES v1beta1.Elasticsearch + ES esv1.Elasticsearch // SupportedVersions verifies whether we can support upgrading from the current pods. SupportedVersions esversion.LowestHighestSupportedVersions @@ -220,7 +220,7 @@ func (d *defaultDriver) Reconcile() *reconciler.Results { keystoreResources, err := keystore.NewResources( d, &d.ES, - v1beta1.ESNamer, + esv1.ESNamer, label.NewLabels(k8s.ExtractNamespacedName(&d.ES)), initcontainer.KeystoreParams, ) diff --git a/pkg/controller/elasticsearch/driver/esstate.go b/pkg/controller/elasticsearch/driver/esstate.go index 2a24a27f020..265dab949c1 100644 --- a/pkg/controller/elasticsearch/driver/esstate.go +++ b/pkg/controller/elasticsearch/driver/esstate.go @@ -8,7 +8,7 @@ import ( "context" "sync" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" esclient "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" "github.com/elastic/cloud-on-k8s/pkg/utils/stringsutil" ) @@ -126,7 +126,7 @@ func (h *memoizingGreenHealth) initialize() error { if err != nil { return err } - h.greenHealth = health.Status == string(v1beta1.ElasticsearchGreenHealth) + h.greenHealth = health.Status == string(esv1.ElasticsearchGreenHealth) return nil } diff --git a/pkg/controller/elasticsearch/driver/esstate_test.go b/pkg/controller/elasticsearch/driver/esstate_test.go index 84dd757807a..f8c63612821 100644 --- a/pkg/controller/elasticsearch/driver/esstate_test.go +++ b/pkg/controller/elasticsearch/driver/esstate_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" esclient "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" ) @@ -153,7 +153,7 @@ func Test_memoizingShardsAllocationEnabled_ShardAllocationsEnabled(t *testing.T) } func Test_memoizingGreenHealth_GreenHealth(t *testing.T) { - esClient := &fakeESClient{health: esclient.Health{Status: string(v1beta1.ElasticsearchGreenHealth)}} + esClient := &fakeESClient{health: esclient.Health{Status: string(esv1.ElasticsearchGreenHealth)}} h := &memoizingGreenHealth{esClient: esClient} green, err := h.GreenHealth() @@ -168,7 +168,7 @@ func Test_memoizingGreenHealth_GreenHealth(t *testing.T) { require.True(t, green) // simulate yellow health - esClient = &fakeESClient{health: esclient.Health{Status: string(v1beta1.ElasticsearchYellowHealth)}} + esClient = &fakeESClient{health: esclient.Health{Status: string(esv1.ElasticsearchYellowHealth)}} h = &memoizingGreenHealth{esClient: esClient} green, err = h.GreenHealth() require.NoError(t, err) diff --git a/pkg/controller/elasticsearch/driver/expectations_test.go b/pkg/controller/elasticsearch/driver/expectations_test.go index 216f4d9b1bd..54700cb85e6 100644 --- a/pkg/controller/elasticsearch/driver/expectations_test.go +++ b/pkg/controller/elasticsearch/driver/expectations_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/expectations" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/sset" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" @@ -19,7 +19,7 @@ import ( func Test_defaultDriver_expectationSatisfied(t *testing.T) { client := k8s.WrappedFakeClient() - es := v1beta1.Elasticsearch{ + es := esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Namespace: "ns", Name: "cluster", diff --git a/pkg/controller/elasticsearch/driver/fixtures.go b/pkg/controller/elasticsearch/driver/fixtures.go index 5553fe7d625..ac55c4efbbe 100644 --- a/pkg/controller/elasticsearch/driver/fixtures.go +++ b/pkg/controller/elasticsearch/driver/fixtures.go @@ -5,16 +5,17 @@ package driver import ( - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" - "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/sset" - "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" - "github.com/elastic/cloud-on-k8s/pkg/utils/pointer" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/uuid" + + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" + "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/sset" + "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" + "github.com/elastic/cloud-on-k8s/pkg/utils/pointer" ) const ( @@ -104,15 +105,15 @@ func newUpgradeTestPods(pods ...testPod) upgradeTestPods { return result } -func (u upgradeTestPods) toES(maxUnavailable int) v1beta1.Elasticsearch { - return v1beta1.Elasticsearch{ +func (u upgradeTestPods) toES(maxUnavailable int) esv1.Elasticsearch { + return esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Name: TestEsName, Namespace: TestEsNamespace, }, - Spec: v1beta1.ElasticsearchSpec{ - UpdateStrategy: v1beta1.UpdateStrategy{ - ChangeBudget: v1beta1.ChangeBudget{ + Spec: esv1.ElasticsearchSpec{ + UpdateStrategy: esv1.UpdateStrategy{ + ChangeBudget: esv1.ChangeBudget{ MaxUnavailable: pointer.Int32(int32(maxUnavailable)), }, }, diff --git a/pkg/controller/elasticsearch/driver/pvc.go b/pkg/controller/elasticsearch/driver/pvc.go index efc17733d7d..2e7304a34b6 100644 --- a/pkg/controller/elasticsearch/driver/pvc.go +++ b/pkg/controller/elasticsearch/driver/pvc.go @@ -8,7 +8,7 @@ import ( corev1 "k8s.io/api/core/v1" "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/sset" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" @@ -24,7 +24,7 @@ import ( // * leftover PVCs created for StatefulSets replicas that don't exist anymore (eg. downscale from 5 to 3 nodes) func GarbageCollectPVCs( k8sClient k8s.Client, - es v1beta1.Elasticsearch, + es esv1.Elasticsearch, actualStatefulSets sset.StatefulSetList, expectedStatefulSets sset.StatefulSetList, ) error { diff --git a/pkg/controller/elasticsearch/driver/pvc_test.go b/pkg/controller/elasticsearch/driver/pvc_test.go index 38f56980b97..c98cbc8a8d8 100644 --- a/pkg/controller/elasticsearch/driver/pvc_test.go +++ b/pkg/controller/elasticsearch/driver/pvc_test.go @@ -8,15 +8,16 @@ import ( "reflect" "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" - "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/sset" - "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/stretchr/testify/require" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" + "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/sset" + "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" ) func buildSsetWithClaims(name string, replicas int32, claims ...string) appsv1.StatefulSet { @@ -132,7 +133,7 @@ func Test_pvcsToRemove(t *testing.T) { func TestGarbageCollectPVCs(t *testing.T) { // Test_pvcsToRemove covers most of the testing logic, // let's just check everything is correctly plugged to the k8s api here. - es := v1beta1.Elasticsearch{ObjectMeta: metav1.ObjectMeta{Namespace: "ns", Name: "es"}} + es := esv1.Elasticsearch{ObjectMeta: metav1.ObjectMeta{Namespace: "ns", Name: "es"}} existingPVCS := []runtime.Object{ buildPVCPtr("claim1-sset1-0"), // should not be removed buildPVCPtr("claim1-oldsset-0"), // should be removed diff --git a/pkg/controller/elasticsearch/driver/upgrade.go b/pkg/controller/elasticsearch/driver/upgrade.go index ed7037a7b4c..1f73024df1c 100644 --- a/pkg/controller/elasticsearch/driver/upgrade.go +++ b/pkg/controller/elasticsearch/driver/upgrade.go @@ -7,7 +7,7 @@ package driver import ( "context" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/expectations" "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" esclient "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" @@ -89,7 +89,7 @@ func (d *defaultDriver) handleRollingUpgrades( type rollingUpgradeCtx struct { client k8s.Client - ES v1beta1.Elasticsearch + ES esv1.Elasticsearch statefulSets sset.StatefulSetList esClient esclient.Client shardLister esclient.ShardLister @@ -218,7 +218,7 @@ func disableShardsAllocation(esClient esclient.Client) error { return esClient.DisableReplicaShardsAllocation(ctx) } -func doSyncFlush(es v1beta1.Elasticsearch, esClient esclient.Client) error { +func doSyncFlush(es esv1.Elasticsearch, esClient esclient.Client) error { ctx, cancel := context.WithTimeout(context.Background(), esclient.DefaultReqTimeout) defer cancel() err := esClient.SyncedFlush(ctx) diff --git a/pkg/controller/elasticsearch/driver/upgrade_forced.go b/pkg/controller/elasticsearch/driver/upgrade_forced.go index 1a95e2d9f45..4ef511afa78 100644 --- a/pkg/controller/elasticsearch/driver/upgrade_forced.go +++ b/pkg/controller/elasticsearch/driver/upgrade_forced.go @@ -9,7 +9,7 @@ import ( corev1 "k8s.io/api/core/v1" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/sset" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" @@ -105,7 +105,7 @@ func allPodsBootlooping(pods []corev1.Pod) bool { return false } for _, containerStatus := range p.Status.ContainerStatuses { - if containerStatus.Name == v1beta1.ElasticsearchContainerName && + if containerStatus.Name == esv1.ElasticsearchContainerName && containerStatus.RestartCount == 0 { // the Pod may not be healthy, but it has not restarted (yet) return false diff --git a/pkg/controller/elasticsearch/driver/upgrade_pods_deletion.go b/pkg/controller/elasticsearch/driver/upgrade_pods_deletion.go index 3a196bce143..a2871561a6c 100644 --- a/pkg/controller/elasticsearch/driver/upgrade_pods_deletion.go +++ b/pkg/controller/elasticsearch/driver/upgrade_pods_deletion.go @@ -7,14 +7,15 @@ package driver import ( "sort" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + corev1 "k8s.io/api/core/v1" + "sigs.k8s.io/controller-runtime/pkg/client" + + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/expectations" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/sset" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/pkg/utils/stringsutil" - corev1 "k8s.io/api/core/v1" - "sigs.k8s.io/controller-runtime/pkg/client" ) // Delete runs through a list of potential candidates and select the ones that can be deleted. @@ -153,7 +154,7 @@ func (ctx *rollingUpgradeCtx) handleMasterScaleChange(pod corev1.Pod) error { return nil } -func deletePod(k8sClient k8s.Client, es v1beta1.Elasticsearch, pod corev1.Pod, expectations *expectations.Expectations) error { +func deletePod(k8sClient k8s.Client, es esv1.Elasticsearch, pod corev1.Pod, expectations *expectations.Expectations) error { log.Info("Deleting pod for rolling upgrade", "es_name", es.Name, "namespace", es.Namespace, "pod_name", pod.Name, "pod_uid", pod.UID) // The name of the Pod we want to delete is not enough as it may have been already deleted/recreated. // The uid of the Pod we want to delete is used as a precondition to check that we actually delete the right one. diff --git a/pkg/controller/elasticsearch/driver/upgrade_predicates.go b/pkg/controller/elasticsearch/driver/upgrade_predicates.go index 6c5c00e7e95..fb4717f3790 100644 --- a/pkg/controller/elasticsearch/driver/upgrade_predicates.go +++ b/pkg/controller/elasticsearch/driver/upgrade_predicates.go @@ -5,7 +5,7 @@ package driver import ( - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" "github.com/elastic/cloud-on-k8s/pkg/utils/stringsutil" @@ -13,7 +13,7 @@ import ( ) type PredicateContext struct { - es v1beta1.Elasticsearch + es esv1.Elasticsearch masterNodesNames []string actualMasters []corev1.Pod healthyPods map[string]corev1.Pod @@ -48,7 +48,7 @@ func groupByPredicates(fp failedPredicates) map[string][]string { } func NewPredicateContext( - es v1beta1.Elasticsearch, + es esv1.Elasticsearch, state ESState, shardLister client.ShardLister, healthyPods map[string]corev1.Pod, diff --git a/pkg/controller/elasticsearch/driver/upgrade_predicates_test.go b/pkg/controller/elasticsearch/driver/upgrade_predicates_test.go index 29366612ffd..5b330a602d3 100644 --- a/pkg/controller/elasticsearch/driver/upgrade_predicates_test.go +++ b/pkg/controller/elasticsearch/driver/upgrade_predicates_test.go @@ -8,7 +8,7 @@ import ( "reflect" "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/expectations" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/migration" @@ -21,7 +21,7 @@ import ( func TestUpgradePodsDeletion_WithNodeTypeMutations(t *testing.T) { type fields struct { upgradeTestPods upgradeTestPods - ES v1beta1.Elasticsearch + ES esv1.Elasticsearch green bool mutation mutation maxUnavailable int @@ -140,7 +140,7 @@ func TestUpgradePodsDeletion_WithNodeTypeMutations(t *testing.T) { shardLister: migration.NewFakeShardLister(client.Shards{}), esState: esState, expectations: expectations.NewExpectations(k8sClient), - reconcileState: reconcile.NewState(v1beta1.Elasticsearch{}), + reconcileState: reconcile.NewState(esv1.Elasticsearch{}), expectedMasters: tt.fields.upgradeTestPods.toMasters(tt.fields.mutation), actualMasters: tt.fields.upgradeTestPods.toMasterPods(), podsToUpgrade: tt.fields.upgradeTestPods.toUpgrade(), @@ -167,7 +167,7 @@ func TestUpgradePodsDeletion_Delete(t *testing.T) { type fields struct { upgradeTestPods upgradeTestPods shardLister client.ShardLister - ES v1beta1.Elasticsearch + ES esv1.Elasticsearch green bool maxUnavailable int podFilter filter diff --git a/pkg/controller/elasticsearch/driver/upscale.go b/pkg/controller/elasticsearch/driver/upscale.go index e8a204d9545..3119e23cdbb 100644 --- a/pkg/controller/elasticsearch/driver/upscale.go +++ b/pkg/controller/elasticsearch/driver/upscale.go @@ -5,11 +5,11 @@ package driver import ( + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/observer" appsv1 "k8s.io/api/apps/v1" "k8s.io/apimachinery/pkg/runtime" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" "github.com/elastic/cloud-on-k8s/pkg/controller/common" "github.com/elastic/cloud-on-k8s/pkg/controller/common/expectations" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/nodespec" @@ -22,7 +22,7 @@ import ( type upscaleCtx struct { k8sClient k8s.Client - es v1beta1.Elasticsearch + es esv1.Elasticsearch scheme *runtime.Scheme observedState observer.State esState ESState @@ -88,7 +88,7 @@ func adjustResources( return adjustedResources, nil } -func adjustZenConfig(k8sClient k8s.Client, es v1beta1.Elasticsearch, resources nodespec.ResourcesList) error { +func adjustZenConfig(k8sClient k8s.Client, es esv1.Elasticsearch, resources nodespec.ResourcesList) error { // patch configs to consider zen1 minimum master nodes if err := zen1.SetupMinimumMasterNodesConfig(k8sClient, es, resources); err != nil { return err diff --git a/pkg/controller/elasticsearch/driver/upscale_state_test.go b/pkg/controller/elasticsearch/driver/upscale_state_test.go index f60770e481f..9e8d33ff854 100644 --- a/pkg/controller/elasticsearch/driver/upscale_state_test.go +++ b/pkg/controller/elasticsearch/driver/upscale_state_test.go @@ -8,7 +8,7 @@ import ( "reflect" "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/nodespec" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/sset" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" @@ -311,7 +311,7 @@ func Test_newUpscaleStateWithChangeBudget(t *testing.T) { } } defaultTest := getTest(args{actual: []int{3}, expected: []int{3}, maxSurge: nil, createsAllowed: nil, name: "5 nodes present, 5 nodes target, n/a maxSurge - unbounded creates allowed"}) - defaultTest.ctx.es.Spec.UpdateStrategy = v1beta1.UpdateStrategy{} + defaultTest.ctx.es.Spec.UpdateStrategy = esv1.UpdateStrategy{} tests := []test{ getTest(args{actual: []int{3}, expected: []int{3}, maxSurge: pointer.Int32(0), createsAllowed: pointer.Int32(0), name: "3 nodes present, 3 nodes target - no creates allowed"}), diff --git a/pkg/controller/elasticsearch/driver/upscale_test.go b/pkg/controller/elasticsearch/driver/upscale_test.go index e7553203998..0436304e4d7 100644 --- a/pkg/controller/elasticsearch/driver/upscale_test.go +++ b/pkg/controller/elasticsearch/driver/upscale_test.go @@ -8,7 +8,7 @@ import ( "sync" "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/expectations" "github.com/elastic/cloud-on-k8s/pkg/controller/common/hash" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/nodespec" @@ -34,7 +34,7 @@ func init() { func TestHandleUpscaleAndSpecChanges(t *testing.T) { k8sClient := k8s.WrappedFakeClient() - es := v1beta1.Elasticsearch{ObjectMeta: metav1.ObjectMeta{Namespace: "ns", Name: "es"}} + es := esv1.Elasticsearch{ObjectMeta: metav1.ObjectMeta{Namespace: "ns", Name: "es"}} ctx := upscaleCtx{ k8sClient: k8sClient, es: es, @@ -113,8 +113,8 @@ func TestHandleUpscaleAndSpecChanges(t *testing.T) { require.NoError(t, k8sClient.Get(types.NamespacedName{Namespace: "ns", Name: nodespec.HeadlessServiceName("sset1")}, &corev1.Service{})) require.NoError(t, k8sClient.Get(types.NamespacedName{Namespace: "ns", Name: nodespec.HeadlessServiceName("sset2")}, &corev1.Service{})) // config should be created for both - require.NoError(t, k8sClient.Get(types.NamespacedName{Namespace: "ns", Name: v1beta1.ConfigSecret("sset1")}, &corev1.Secret{})) - require.NoError(t, k8sClient.Get(types.NamespacedName{Namespace: "ns", Name: v1beta1.ConfigSecret("sset2")}, &corev1.Secret{})) + require.NoError(t, k8sClient.Get(types.NamespacedName{Namespace: "ns", Name: esv1.ConfigSecret("sset1")}, &corev1.Secret{})) + require.NoError(t, k8sClient.Get(types.NamespacedName{Namespace: "ns", Name: esv1.ConfigSecret("sset2")}, &corev1.Secret{})) // upscale data nodes actualStatefulSets = sset.StatefulSetList{sset1, sset2} @@ -261,18 +261,18 @@ func Test_adjustStatefulSetReplicas(t *testing.T) { } func Test_adjustZenConfig(t *testing.T) { - bootstrappedES := v1beta1.Elasticsearch{ + bootstrappedES := esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Name: TestEsName, Namespace: TestEsNamespace, Annotations: map[string]string{ClusterUUIDAnnotationName: "uuid"}, }, } - notBootstrappedES := v1beta1.Elasticsearch{} + notBootstrappedES := esv1.Elasticsearch{} tests := []struct { name string - es v1beta1.Elasticsearch + es esv1.Elasticsearch statefulSet sset.TestSset pods []runtime.Object wantMinimumMasterNodesSet bool @@ -328,9 +328,9 @@ func Test_adjustZenConfig(t *testing.T) { err := adjustZenConfig(client, tt.es, resources) require.NoError(t, err) for _, res := range resources { - hasMinimumMasterNodes := len(res.Config.HasKeys([]string{v1beta1.DiscoveryZenMinimumMasterNodes})) > 0 + hasMinimumMasterNodes := len(res.Config.HasKeys([]string{esv1.DiscoveryZenMinimumMasterNodes})) > 0 require.Equal(t, tt.wantMinimumMasterNodesSet, hasMinimumMasterNodes) - hasInitialMasterNodes := len(res.Config.HasKeys([]string{v1beta1.ClusterInitialMasterNodes})) > 0 + hasInitialMasterNodes := len(res.Config.HasKeys([]string{esv1.ClusterInitialMasterNodes})) > 0 require.Equal(t, tt.wantInitialMasterNodesSet, hasInitialMasterNodes) } }) diff --git a/pkg/controller/elasticsearch/elasticsearch_controller.go b/pkg/controller/elasticsearch/elasticsearch_controller.go index 217a839ef6d..0f5353a94df 100644 --- a/pkg/controller/elasticsearch/elasticsearch_controller.go +++ b/pkg/controller/elasticsearch/elasticsearch_controller.go @@ -8,7 +8,7 @@ import ( "fmt" "sync/atomic" - elasticsearchv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common" "github.com/elastic/cloud-on-k8s/pkg/controller/common/annotation" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates/http" @@ -83,7 +83,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler) (controller.Controller, er func addWatches(c controller.Controller, r *ReconcileElasticsearch) error { // Watch for changes to Elasticsearch if err := c.Watch( - &source.Kind{Type: &elasticsearchv1beta1.Elasticsearch{}}, &handler.EnqueueRequestForObject{}, + &source.Kind{Type: &esv1.Elasticsearch{}}, &handler.EnqueueRequestForObject{}, ); err != nil { return err } @@ -92,7 +92,7 @@ func addWatches(c controller.Controller, r *ReconcileElasticsearch) error { if err := c.Watch( &source.Kind{Type: &appsv1.StatefulSet{}}, &handler.EnqueueRequestForOwner{ IsController: true, - OwnerType: &elasticsearchv1beta1.Elasticsearch{}, + OwnerType: &esv1.Elasticsearch{}, }, ); err != nil { return err @@ -124,7 +124,7 @@ func addWatches(c controller.Controller, r *ReconcileElasticsearch) error { // Watch services if err := c.Watch(&source.Kind{Type: &corev1.Service{}}, &handler.EnqueueRequestForOwner{ IsController: true, - OwnerType: &elasticsearchv1beta1.Elasticsearch{}, + OwnerType: &esv1.Elasticsearch{}, }); err != nil { return err } @@ -136,7 +136,7 @@ func addWatches(c controller.Controller, r *ReconcileElasticsearch) error { if err := r.dynamicWatches.Secrets.AddHandler(&watches.OwnerWatch{ EnqueueRequestForOwner: handler.EnqueueRequestForOwner{ IsController: true, - OwnerType: &elasticsearchv1beta1.Elasticsearch{}, + OwnerType: &esv1.Elasticsearch{}, }, }); err != nil { return err @@ -177,7 +177,7 @@ func (r *ReconcileElasticsearch) Reconcile(request reconcile.Request) (reconcile defer common.LogReconciliationRun(log, request, &r.iteration)() // Fetch the Elasticsearch instance - es := elasticsearchv1beta1.Elasticsearch{} + es := esv1.Elasticsearch{} err := r.Get(request.NamespacedName, &es) if err != nil { if apierrors.IsNotFound(err) { @@ -233,7 +233,7 @@ func (r *ReconcileElasticsearch) Reconcile(request reconcile.Request) (reconcile } func (r *ReconcileElasticsearch) internalReconcile( - es elasticsearchv1beta1.Elasticsearch, + es esv1.Elasticsearch, reconcileState *esreconcile.State, ) *reconciler.Results { results := &reconciler.Results{} @@ -292,7 +292,7 @@ func (r *ReconcileElasticsearch) internalReconcile( } func (r *ReconcileElasticsearch) updateStatus( - es elasticsearchv1beta1.Elasticsearch, + es esv1.Elasticsearch, reconcileState *esreconcile.State, ) error { log.Info("Updating status", "iteration", atomic.LoadUint64(&r.iteration), "namespace", es.Namespace, "es_name", es.Name) @@ -312,5 +312,5 @@ func (r *ReconcileElasticsearch) onDelete(es types.NamespacedName) { r.expectations.RemoveCluster(es) r.esObservers.StopObserving(es) r.dynamicWatches.Secrets.RemoveHandlerForKey(keystore.SecureSettingsWatchName(es)) - r.dynamicWatches.Secrets.RemoveHandlerForKey(http.CertificateWatchKey(elasticsearchv1beta1.ESNamer, es.Name)) + r.dynamicWatches.Secrets.RemoveHandlerForKey(http.CertificateWatchKey(esv1.ESNamer, es.Name)) } diff --git a/pkg/controller/elasticsearch/initcontainer/prepare_fs.go b/pkg/controller/elasticsearch/initcontainer/prepare_fs.go index f8ff9501c05..e90418440a5 100644 --- a/pkg/controller/elasticsearch/initcontainer/prepare_fs.go +++ b/pkg/controller/elasticsearch/initcontainer/prepare_fs.go @@ -7,7 +7,7 @@ package initcontainer import ( "path" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/defaults" "github.com/elastic/cloud-on-k8s/pkg/controller/common/volume" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/settings" @@ -107,7 +107,7 @@ func NewPrepareFSInitContainer( certificatesVolumeMount.MountPath = initContainerTransportCertificatesVolumeMountPath scriptsVolume := volume.NewConfigMapVolumeWithMode( - v1beta1.ScriptsConfigMap(clusterName), + esv1.ScriptsConfigMap(clusterName), esvolume.ScriptsVolumeName, esvolume.ScriptsVolumeMountPath, 0755) diff --git a/pkg/controller/elasticsearch/label/label.go b/pkg/controller/elasticsearch/label/label.go index 84caeeffb55..f7bceae44e4 100644 --- a/pkg/controller/elasticsearch/label/label.go +++ b/pkg/controller/elasticsearch/label/label.go @@ -7,7 +7,7 @@ package label import ( "fmt" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common" "github.com/elastic/cloud-on-k8s/pkg/controller/common/version" "github.com/pkg/errors" @@ -111,7 +111,7 @@ func NewPodLabels( es types.NamespacedName, ssetName string, version version.Version, - nodeRoles v1beta1.Node, + nodeRoles esv1.Node, configHash string, scheme string, ) (map[string]string, error) { @@ -151,7 +151,7 @@ func NewStatefulSetLabels(es types.NamespacedName, ssetName string) map[string]s } // NewLabelSelectorForElasticsearch returns a labels.Selector that matches the labels as constructed by NewLabels -func NewLabelSelectorForElasticsearch(es v1beta1.Elasticsearch) client.MatchingLabels { +func NewLabelSelectorForElasticsearch(es esv1.Elasticsearch) client.MatchingLabels { return NewLabelSelectorForElasticsearchClusterName(es.Name) } diff --git a/pkg/controller/elasticsearch/license/apply.go b/pkg/controller/elasticsearch/license/apply.go index 53095f73ddf..515e206ab3a 100644 --- a/pkg/controller/elasticsearch/license/apply.go +++ b/pkg/controller/elasticsearch/license/apply.go @@ -9,7 +9,7 @@ import ( "encoding/json" "fmt" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" commonlicense "github.com/elastic/cloud-on-k8s/pkg/controller/common/license" esclient "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" @@ -41,7 +41,7 @@ func applyLinkedLicense( err := c.Get( types.NamespacedName{ Namespace: esCluster.Namespace, - Name: v1beta1.LicenseSecretName(esCluster.Name), + Name: esv1.LicenseSecretName(esCluster.Name), }, &license, ) diff --git a/pkg/controller/elasticsearch/license/apply_test.go b/pkg/controller/elasticsearch/license/apply_test.go index 85ae3907fc6..899c52c7b73 100644 --- a/pkg/controller/elasticsearch/license/apply_test.go +++ b/pkg/controller/elasticsearch/license/apply_test.go @@ -9,11 +9,6 @@ import ( "net/http" "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/version" - esclient "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" - fixtures "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client/test_fixtures" - "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/pkg/errors" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" @@ -21,6 +16,12 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" + + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/version" + esclient "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" + fixtures "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client/test_fixtures" + "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" ) func Test_updateLicense(t *testing.T) { @@ -118,7 +119,7 @@ func Test_applyLinkedLicense(t *testing.T) { initialObjs: []runtime.Object{ &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ - Name: v1beta1.LicenseSecretName("test"), + Name: esv1.LicenseSecretName("test"), Namespace: "default", }, Data: map[string][]byte{ @@ -140,7 +141,7 @@ func Test_applyLinkedLicense(t *testing.T) { initialObjs: []runtime.Object{ &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ - Name: v1beta1.LicenseSecretName("test"), + Name: esv1.LicenseSecretName("test"), Namespace: "default", }, }, @@ -152,7 +153,7 @@ func Test_applyLinkedLicense(t *testing.T) { initialObjs: []runtime.Object{ &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ - Name: v1beta1.LicenseSecretName("test"), + Name: esv1.LicenseSecretName("test"), Namespace: "default", }, Data: map[string][]byte{ @@ -167,7 +168,7 @@ func Test_applyLinkedLicense(t *testing.T) { errors: map[client.ObjectKey]error{ types.NamespacedName{ Namespace: clusterName.Namespace, - Name: v1beta1.LicenseSecretName("test"), + Name: esv1.LicenseSecretName("test"), }: errors.New("boom"), }, }, diff --git a/pkg/controller/elasticsearch/license/reconcile.go b/pkg/controller/elasticsearch/license/reconcile.go index 0054cdcaec3..66108678e48 100644 --- a/pkg/controller/elasticsearch/license/reconcile.go +++ b/pkg/controller/elasticsearch/license/reconcile.go @@ -5,7 +5,7 @@ package license import ( - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" esclient "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" ) @@ -13,7 +13,7 @@ import ( // Reconcile reconciles the current Elasticsearch license with the desired one. func Reconcile( c k8s.Client, - esCluster v1beta1.Elasticsearch, + esCluster esv1.Elasticsearch, clusterClient esclient.Client, current *esclient.License, ) error { diff --git a/pkg/controller/elasticsearch/nodespec/defaults.go b/pkg/controller/elasticsearch/nodespec/defaults.go index b92611efc6f..582edf2286a 100644 --- a/pkg/controller/elasticsearch/nodespec/defaults.go +++ b/pkg/controller/elasticsearch/nodespec/defaults.go @@ -7,11 +7,11 @@ package nodespec import ( "path" - "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/defaults" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/network" @@ -51,7 +51,7 @@ var ( ) // DefaultEnvVars are environment variables injected into Elasticsearch pods. -func DefaultEnvVars(httpCfg v1beta1.HTTPConfig) []corev1.EnvVar { +func DefaultEnvVars(httpCfg commonv1.HTTPConfig) []corev1.EnvVar { return append( defaults.PodDownwardEnvVars, []corev1.EnvVar{ diff --git a/pkg/controller/elasticsearch/nodespec/podspec.go b/pkg/controller/elasticsearch/nodespec/podspec.go index 3b9291ba131..d8a27a45e88 100644 --- a/pkg/controller/elasticsearch/nodespec/podspec.go +++ b/pkg/controller/elasticsearch/nodespec/podspec.go @@ -10,7 +10,7 @@ import ( corev1 "k8s.io/api/core/v1" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/defaults" "github.com/elastic/cloud-on-k8s/pkg/controller/common/hash" "github.com/elastic/cloud-on-k8s/pkg/controller/common/keystore" @@ -26,8 +26,8 @@ import ( // BuildPodTemplateSpec builds a new PodTemplateSpec for an Elasticsearch node. func BuildPodTemplateSpec( - es v1beta1.Elasticsearch, - nodeSet v1beta1.NodeSet, + es esv1.Elasticsearch, + nodeSet esv1.NodeSet, cfg settings.CanonicalConfig, keystoreResources *keystore.Resources, ) (corev1.PodTemplateSpec, error) { @@ -37,7 +37,7 @@ func BuildPodTemplateSpec( return corev1.PodTemplateSpec{}, err } - builder := defaults.NewPodTemplateBuilder(nodeSet.PodTemplate, v1beta1.ElasticsearchContainerName). + builder := defaults.NewPodTemplateBuilder(nodeSet.PodTemplate, esv1.ElasticsearchContainerName). WithDockerImage(es.Spec.Image, stringsutil.Concat(DefaultImageRepository, ":", es.Spec.Version)) initContainers, err := initcontainer.NewInitContainers( @@ -68,16 +68,16 @@ func BuildPodTemplateSpec( func transportCertificatesVolume(esName string) volume.SecretVolume { return volume.NewSecretVolumeWithMountPath( - v1beta1.TransportCertificatesSecret(esName), + esv1.TransportCertificatesSecret(esName), esvolume.TransportCertificatesSecretVolumeName, esvolume.TransportCertificatesSecretVolumeMountPath, ) } func buildLabels( - es v1beta1.Elasticsearch, + es esv1.Elasticsearch, cfg settings.CanonicalConfig, - nodeSet v1beta1.NodeSet, + nodeSet esv1.NodeSet, keystoreResources *keystore.Resources, ) (map[string]string, error) { // label with a hash of the config to rotate the pod on config changes @@ -96,7 +96,7 @@ func buildLabels( podLabels, err := label.NewPodLabels( k8s.ExtractNamespacedName(&es), - v1beta1.StatefulSet(es.Name, nodeSet.Name), + esv1.StatefulSet(es.Name, nodeSet.Name), *ver, nodeRoles, cfgHash, es.Spec.HTTP.Protocol(), ) if err != nil { diff --git a/pkg/controller/elasticsearch/nodespec/podspec_test.go b/pkg/controller/elasticsearch/nodespec/podspec_test.go index 6fa37dcda95..7d113d81018 100644 --- a/pkg/controller/elasticsearch/nodespec/podspec_test.go +++ b/pkg/controller/elasticsearch/nodespec/podspec_test.go @@ -8,8 +8,8 @@ import ( "sort" "testing" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/defaults" "github.com/elastic/cloud-on-k8s/pkg/controller/common/version" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/certificates" @@ -22,7 +22,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -var sampleES = v1beta1.Elasticsearch{ +var sampleES = esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Namespace: "namespace", Name: "name", @@ -33,13 +33,13 @@ var sampleES = v1beta1.Elasticsearch{ "cluster-annotation-name": "cluster-annotation-value", }, }, - Spec: v1beta1.ElasticsearchSpec{ + Spec: esv1.ElasticsearchSpec{ Version: "7.2.0", - NodeSets: []v1beta1.NodeSet{ + NodeSets: []esv1.NodeSet{ { Name: "nodeset-1", Count: 2, - Config: &commonv1beta1.Config{ + Config: &commonv1.Config{ Data: map[string]interface{}{ "node.attr.foo": "bar", "node.master": "true", diff --git a/pkg/controller/elasticsearch/nodespec/resources.go b/pkg/controller/elasticsearch/nodespec/resources.go index 7e145d6da43..72e0d012650 100644 --- a/pkg/controller/elasticsearch/nodespec/resources.go +++ b/pkg/controller/elasticsearch/nodespec/resources.go @@ -9,8 +9,8 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/keystore" "github.com/elastic/cloud-on-k8s/pkg/controller/common/version" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/certificates" @@ -38,7 +38,7 @@ func (l ResourcesList) StatefulSets() sset.StatefulSetList { } func BuildExpectedResources( - es v1beta1.Elasticsearch, + es esv1.Elasticsearch, keystoreResources *keystore.Resources, scheme *runtime.Scheme, certResources *certificates.CertificateResources, @@ -53,7 +53,7 @@ func BuildExpectedResources( for _, nodeSpec := range es.Spec.NodeSets { // build es config - userCfg := commonv1beta1.Config{} + userCfg := commonv1.Config{} if nodeSpec.Config != nil { userCfg = *nodeSpec.Config } diff --git a/pkg/controller/elasticsearch/nodespec/statefulset.go b/pkg/controller/elasticsearch/nodespec/statefulset.go index 0c9682fcc7f..678c50d1b06 100644 --- a/pkg/controller/elasticsearch/nodespec/statefulset.go +++ b/pkg/controller/elasticsearch/nodespec/statefulset.go @@ -5,7 +5,13 @@ package nodespec import ( - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/types" + + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/defaults" "github.com/elastic/cloud-on-k8s/pkg/controller/common/hash" "github.com/elastic/cloud-on-k8s/pkg/controller/common/keystore" @@ -15,11 +21,6 @@ import ( "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/sset" esvolume "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/volume" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" - appsv1 "k8s.io/api/apps/v1" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/types" ) var ( @@ -49,14 +50,14 @@ func HeadlessService(es types.NamespacedName, ssetName string) corev1.Service { } func BuildStatefulSet( - es v1beta1.Elasticsearch, - nodeSet v1beta1.NodeSet, + es esv1.Elasticsearch, + nodeSet esv1.NodeSet, cfg settings.CanonicalConfig, keystoreResources *keystore.Resources, existingStatefulSets sset.StatefulSetList, scheme *runtime.Scheme, ) (appsv1.StatefulSet, error) { - statefulSetName := v1beta1.StatefulSet(es.Name, nodeSet.Name) + statefulSetName := esv1.StatefulSet(es.Name, nodeSet.Name) // ssetSelector is used to match the sset pods ssetSelector := label.NewStatefulSetLabels(k8s.ExtractNamespacedName(&es), statefulSetName) @@ -124,7 +125,7 @@ func BuildStatefulSet( func setVolumeClaimsControllerReference( persistentVolumeClaims []corev1.PersistentVolumeClaim, existingClaims []corev1.PersistentVolumeClaim, - es v1beta1.Elasticsearch, + es esv1.Elasticsearch, scheme *runtime.Scheme, ) ([]corev1.PersistentVolumeClaim, error) { // set the owner reference of all volume claims to the ES resource, diff --git a/pkg/controller/elasticsearch/nodespec/statefulset_test.go b/pkg/controller/elasticsearch/nodespec/statefulset_test.go index ee3e2c27539..2ce72d59f6e 100644 --- a/pkg/controller/elasticsearch/nodespec/statefulset_test.go +++ b/pkg/controller/elasticsearch/nodespec/statefulset_test.go @@ -8,24 +8,22 @@ import ( "reflect" "testing" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" ) func Test_setVolumeClaimsControllerReference(t *testing.T) { varTrue := true varFalse := false - es := v1beta1.Elasticsearch{ - TypeMeta: v1.TypeMeta{ + es := esv1.Elasticsearch{ + TypeMeta: metav1.TypeMeta{ Kind: "Elasticsearch", - APIVersion: "elasticsearch.k8s.elastic.co/v1beta1", + APIVersion: "elasticsearch.k8s.elastic.co/v1", }, - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "es1", Namespace: "default", UID: "ABCDEF", @@ -40,14 +38,14 @@ func Test_setVolumeClaimsControllerReference(t *testing.T) { { name: "should set the ownerRef when building a new StatefulSet", persistentVolumeClaims: []corev1.PersistentVolumeClaim{ - {ObjectMeta: v1.ObjectMeta{Name: "elasticsearch-data"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "elasticsearch-data"}}, }, existingClaims: nil, wantClaims: []corev1.PersistentVolumeClaim{ { - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "elasticsearch-data", - OwnerReferences: []v1.OwnerReference{ + OwnerReferences: []metav1.OwnerReference{ { APIVersion: es.APIVersion, Kind: es.Kind, @@ -64,15 +62,15 @@ func Test_setVolumeClaimsControllerReference(t *testing.T) { { name: "should set the ownerRef on user-provided claims when building a new StatefulSet", persistentVolumeClaims: []corev1.PersistentVolumeClaim{ - {ObjectMeta: v1.ObjectMeta{Name: "elasticsearch-data"}}, - {ObjectMeta: v1.ObjectMeta{Name: "user-provided"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "elasticsearch-data"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "user-provided"}}, }, existingClaims: nil, wantClaims: []corev1.PersistentVolumeClaim{ { - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "elasticsearch-data", - OwnerReferences: []v1.OwnerReference{ + OwnerReferences: []metav1.OwnerReference{ { APIVersion: es.APIVersion, Kind: es.Kind, @@ -85,9 +83,9 @@ func Test_setVolumeClaimsControllerReference(t *testing.T) { }, }, { - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "user-provided", - OwnerReferences: []v1.OwnerReference{ + OwnerReferences: []metav1.OwnerReference{ { APIVersion: es.APIVersion, Kind: es.Kind, @@ -104,14 +102,14 @@ func Test_setVolumeClaimsControllerReference(t *testing.T) { { name: "should inherit existing claim ownerRefs that may have a different apiVersion", persistentVolumeClaims: []corev1.PersistentVolumeClaim{ - {ObjectMeta: v1.ObjectMeta{Name: "elasticsearch-data"}}, - {ObjectMeta: v1.ObjectMeta{Name: "user-provided"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "elasticsearch-data"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "user-provided"}}, }, existingClaims: []corev1.PersistentVolumeClaim{ { - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "elasticsearch-data", - OwnerReferences: []v1.OwnerReference{ + OwnerReferences: []metav1.OwnerReference{ { // claim already exists, with a different apiVersion APIVersion: "elasticsearch.k8s.elastic.co/v1alpha1", @@ -125,9 +123,9 @@ func Test_setVolumeClaimsControllerReference(t *testing.T) { }, }, { - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "user-provided", - OwnerReferences: []v1.OwnerReference{ + OwnerReferences: []metav1.OwnerReference{ { // claim already exists, with a different apiVersion APIVersion: "elasticsearch.k8s.elastic.co/v1alpha1", @@ -144,9 +142,9 @@ func Test_setVolumeClaimsControllerReference(t *testing.T) { // existing claims should be preserved wantClaims: []corev1.PersistentVolumeClaim{ { - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "elasticsearch-data", - OwnerReferences: []v1.OwnerReference{ + OwnerReferences: []metav1.OwnerReference{ { APIVersion: "elasticsearch.k8s.elastic.co/v1alpha1", Kind: es.Kind, @@ -159,9 +157,9 @@ func Test_setVolumeClaimsControllerReference(t *testing.T) { }, }, { - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "user-provided", - OwnerReferences: []v1.OwnerReference{ + OwnerReferences: []metav1.OwnerReference{ { APIVersion: "elasticsearch.k8s.elastic.co/v1alpha1", Kind: es.Kind, diff --git a/pkg/controller/elasticsearch/nodespec/volumes.go b/pkg/controller/elasticsearch/nodespec/volumes.go index ffe458ea8ae..24c26f8b3fe 100644 --- a/pkg/controller/elasticsearch/nodespec/volumes.go +++ b/pkg/controller/elasticsearch/nodespec/volumes.go @@ -7,7 +7,7 @@ package nodespec import ( corev1 "k8s.io/api/core/v1" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" "github.com/elastic/cloud-on-k8s/pkg/controller/common/keystore" "github.com/elastic/cloud-on-k8s/pkg/controller/common/volume" @@ -17,21 +17,21 @@ import ( esvolume "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/volume" ) -func buildVolumes(esName string, nodeSpec v1beta1.NodeSet, keystoreResources *keystore.Resources) ([]corev1.Volume, []corev1.VolumeMount) { +func buildVolumes(esName string, nodeSpec esv1.NodeSet, keystoreResources *keystore.Resources) ([]corev1.Volume, []corev1.VolumeMount) { - configVolume := settings.ConfigSecretVolume(v1beta1.StatefulSet(esName, nodeSpec.Name)) + configVolume := settings.ConfigSecretVolume(esv1.StatefulSet(esName, nodeSpec.Name)) probeSecret := volume.NewSelectiveSecretVolumeWithMountPath( user.ElasticInternalUsersSecretName(esName), esvolume.ProbeUserVolumeName, esvolume.ProbeUserSecretMountPath, []string{user.InternalProbeUserName}, ) httpCertificatesVolume := volume.NewSecretVolumeWithMountPath( - certificates.HTTPCertsInternalSecretName(v1beta1.ESNamer, esName), + certificates.HTTPCertsInternalSecretName(esv1.ESNamer, esName), esvolume.HTTPCertificatesSecretVolumeName, esvolume.HTTPCertificatesSecretVolumeMountPath, ) transportCertificatesVolume := transportCertificatesVolume(esName) unicastHostsVolume := volume.NewConfigMapVolume( - v1beta1.UnicastHostsConfigMap(esName), esvolume.UnicastHostsVolumeName, esvolume.UnicastHostsVolumeMountPath, + esv1.UnicastHostsConfigMap(esName), esvolume.UnicastHostsVolumeName, esvolume.UnicastHostsVolumeMountPath, ) usersSecretVolume := volume.NewSecretVolumeWithMountPath( user.XPackFileRealmSecretName(esName), @@ -39,7 +39,7 @@ func buildVolumes(esName string, nodeSpec v1beta1.NodeSet, keystoreResources *ke esvolume.XPackFileRealmVolumeMountPath, ) scriptsVolume := volume.NewConfigMapVolumeWithMode( - v1beta1.ScriptsConfigMap(esName), + esv1.ScriptsConfigMap(esName), esvolume.ScriptsVolumeName, esvolume.ScriptsVolumeMountPath, 0755) diff --git a/pkg/controller/elasticsearch/pdb/reconcile.go b/pkg/controller/elasticsearch/pdb/reconcile.go index dc15e25a7b9..b96052b5fd3 100644 --- a/pkg/controller/elasticsearch/pdb/reconcile.go +++ b/pkg/controller/elasticsearch/pdb/reconcile.go @@ -5,26 +5,27 @@ package pdb import ( - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - esv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/defaults" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/hash" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" - "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" - "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/sset" - "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "k8s.io/api/policy/v1beta1" "k8s.io/apimachinery/pkg/api/errors" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/intstr" + + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/defaults" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/hash" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" + "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" + "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/sset" + "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" ) // Reconcile ensures that a PodDisruptionBudget exists for this cluster, inheriting the spec content. // The default PDB we setup dynamically adapts MinAvailable to the number of nodes in the cluster. // If the spec has disabled the default PDB, it will ensure none exist. -func Reconcile(k8sClient k8s.Client, scheme *runtime.Scheme, es esv1beta1.Elasticsearch, statefulSets sset.StatefulSetList) error { +func Reconcile(k8sClient k8s.Client, scheme *runtime.Scheme, es esv1.Elasticsearch, statefulSets sset.StatefulSetList) error { expected, err := expectedPDB(es, statefulSets, scheme) if err != nil { return err @@ -58,13 +59,13 @@ func Reconcile(k8sClient k8s.Client, scheme *runtime.Scheme, es esv1beta1.Elasti } // deleteDefaultPDB deletes the default pdb if it exists. -func deleteDefaultPDB(k8sClient k8s.Client, es esv1beta1.Elasticsearch) error { +func deleteDefaultPDB(k8sClient k8s.Client, es esv1.Elasticsearch) error { // we do this by getting first because that is a local cache read, // versus a Delete call, which would hit the API. pdb := v1beta1.PodDisruptionBudget{ ObjectMeta: metav1.ObjectMeta{ Namespace: es.Namespace, - Name: esv1beta1.DefaultPodDisruptionBudget(es.Name), + Name: esv1.DefaultPodDisruptionBudget(es.Name), }, } if err := k8sClient.Get(k8s.ExtractNamespacedName(&pdb), &pdb); err != nil && !errors.IsNotFound(err) { @@ -81,13 +82,13 @@ func deleteDefaultPDB(k8sClient k8s.Client, es esv1beta1.Elasticsearch) error { // expectedPDB returns a PDB according to the given ES spec. // It may return nil if the PDB has been explicitly disabled in the ES spec. -func expectedPDB(es esv1beta1.Elasticsearch, statefulSets sset.StatefulSetList, scheme *runtime.Scheme) (*v1beta1.PodDisruptionBudget, error) { +func expectedPDB(es esv1.Elasticsearch, statefulSets sset.StatefulSetList, scheme *runtime.Scheme) (*v1beta1.PodDisruptionBudget, error) { template := es.Spec.PodDisruptionBudget.DeepCopy() if template.IsDisabled() { return nil, nil } if template == nil { - template = &commonv1beta1.PodDisruptionBudgetTemplate{} + template = &commonv1.PodDisruptionBudgetTemplate{} } expected := v1beta1.PodDisruptionBudget{ @@ -95,7 +96,7 @@ func expectedPDB(es esv1beta1.Elasticsearch, statefulSets sset.StatefulSetList, } // inherit user-provided ObjectMeta, but set our own name & namespace - expected.Name = esv1beta1.DefaultPodDisruptionBudget(es.Name) + expected.Name = esv1.DefaultPodDisruptionBudget(es.Name) expected.Namespace = es.Namespace // and append our labels expected.Labels = defaults.SetDefaultLabels(expected.Labels, label.NewLabels(k8s.ExtractNamespacedName(&es))) @@ -117,7 +118,7 @@ func expectedPDB(es esv1beta1.Elasticsearch, statefulSets sset.StatefulSetList, // buildPDBSpec returns a PDBSpec computed from the current StatefulSets, // considering the cluster health and topology. -func buildPDBSpec(es esv1beta1.Elasticsearch, statefulSets sset.StatefulSetList) v1beta1.PodDisruptionBudgetSpec { +func buildPDBSpec(es esv1.Elasticsearch, statefulSets sset.StatefulSetList) v1beta1.PodDisruptionBudgetSpec { // compute MinAvailable based on the maximum number of Pods we're supposed to have nodeCount := statefulSets.ExpectedNodeCount() // maybe allow some Pods to be disrupted @@ -140,8 +141,8 @@ func buildPDBSpec(es esv1beta1.Elasticsearch, statefulSets sset.StatefulSetList) } // allowedDisruptions returns the number of Pods that we allow to be disrupted while keeping the cluster healthy. -func allowedDisruptions(es esv1beta1.Elasticsearch, actualSsets sset.StatefulSetList) int32 { - if es.Status.Health != esv1beta1.ElasticsearchGreenHealth { +func allowedDisruptions(es esv1.Elasticsearch, actualSsets sset.StatefulSetList) int32 { + if es.Status.Health != esv1.ElasticsearchGreenHealth { // A non-green cluster may become red if we disrupt one node, don't allow it. // The health information we're using here may be out-of-date, that's best effort. return 0 diff --git a/pkg/controller/elasticsearch/pdb/reconcile_test.go b/pkg/controller/elasticsearch/pdb/reconcile_test.go index 554a88d3688..401f8a6c96a 100644 --- a/pkg/controller/elasticsearch/pdb/reconcile_test.go +++ b/pkg/controller/elasticsearch/pdb/reconcile_test.go @@ -8,8 +8,8 @@ import ( "reflect" "testing" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - esv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common" "github.com/elastic/cloud-on-k8s/pkg/controller/common/hash" "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" @@ -29,7 +29,7 @@ func TestReconcile(t *testing.T) { defaultPDB := func() *v1beta1.PodDisruptionBudget { return &v1beta1.PodDisruptionBudget{ ObjectMeta: metav1.ObjectMeta{ - Name: esv1beta1.DefaultPodDisruptionBudget("cluster"), + Name: esv1.DefaultPodDisruptionBudget("cluster"), Namespace: "ns", Labels: map[string]string{label.ClusterNameLabelName: "cluster", common.TypeLabelName: label.Type}, }, @@ -44,10 +44,10 @@ func TestReconcile(t *testing.T) { }, } } - defaultEs := esv1beta1.Elasticsearch{ObjectMeta: metav1.ObjectMeta{Name: "cluster", Namespace: "ns"}} + defaultEs := esv1.Elasticsearch{ObjectMeta: metav1.ObjectMeta{Name: "cluster", Namespace: "ns"}} type args struct { k8sClient k8s.Client - es esv1beta1.Elasticsearch + es esv1.Elasticsearch statefulSets sset.StatefulSetList } tests := []struct { @@ -82,7 +82,7 @@ func TestReconcile(t *testing.T) { }, wantPDB: &v1beta1.PodDisruptionBudget{ ObjectMeta: metav1.ObjectMeta{ - Name: esv1beta1.DefaultPodDisruptionBudget("cluster"), + Name: esv1.DefaultPodDisruptionBudget("cluster"), Namespace: "ns", Labels: map[string]string{label.ClusterNameLabelName: "cluster", common.TypeLabelName: label.Type}, }, @@ -101,9 +101,9 @@ func TestReconcile(t *testing.T) { name: "pdb disabled in the ES spec: should delete the existing one", args: args{ k8sClient: k8s.WrappedFakeClient(defaultPDB()), - es: esv1beta1.Elasticsearch{ + es: esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{Name: "cluster", Namespace: "ns"}, - Spec: esv1beta1.ElasticsearchSpec{PodDisruptionBudget: &commonv1beta1.PodDisruptionBudgetTemplate{}}, + Spec: esv1.ElasticsearchSpec{PodDisruptionBudget: &commonv1.PodDisruptionBudgetTemplate{}}, }, statefulSets: sset.StatefulSetList{sset.TestSset{Replicas: 3, Master: true, Data: true}.Build()}, }, @@ -114,7 +114,7 @@ func TestReconcile(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := Reconcile(tt.args.k8sClient, scheme.Scheme, tt.args.es, tt.args.statefulSets) require.NoError(t, err) - pdbNsn := types.NamespacedName{Namespace: tt.args.es.Namespace, Name: esv1beta1.DefaultPodDisruptionBudget(tt.args.es.Name)} + pdbNsn := types.NamespacedName{Namespace: tt.args.es.Namespace, Name: esv1.DefaultPodDisruptionBudget(tt.args.es.Name)} var retrieved v1beta1.PodDisruptionBudget err = tt.args.k8sClient.Get(pdbNsn, &retrieved) if tt.wantPDB == nil { @@ -134,7 +134,7 @@ func withHashLabel(pdb *v1beta1.PodDisruptionBudget) *v1beta1.PodDisruptionBudge return pdb } -func withOwnerRef(pdb *v1beta1.PodDisruptionBudget, es esv1beta1.Elasticsearch) *v1beta1.PodDisruptionBudget { +func withOwnerRef(pdb *v1beta1.PodDisruptionBudget, es esv1.Elasticsearch) *v1beta1.PodDisruptionBudget { if err := reconciler.SetControllerReference(&es, pdb, scheme.Scheme); err != nil { panic(err) } @@ -147,7 +147,7 @@ func intStrPtr(intStr intstr.IntOrString) *intstr.IntOrString { func Test_expectedPDB(t *testing.T) { type args struct { - es esv1beta1.Elasticsearch + es esv1.Elasticsearch statefulSets sset.StatefulSetList } tests := []struct { @@ -158,7 +158,7 @@ func Test_expectedPDB(t *testing.T) { { name: "PDB disabled in the spec", args: args{ - es: esv1beta1.Elasticsearch{Spec: esv1beta1.ElasticsearchSpec{PodDisruptionBudget: &commonv1beta1.PodDisruptionBudgetTemplate{}}}, + es: esv1.Elasticsearch{Spec: esv1.ElasticsearchSpec{PodDisruptionBudget: &commonv1.PodDisruptionBudgetTemplate{}}}, statefulSets: sset.StatefulSetList{sset.TestSset{Replicas: 3, Master: true, Data: true}.Build()}, }, want: nil, @@ -166,12 +166,12 @@ func Test_expectedPDB(t *testing.T) { { name: "Build default PDB", args: args{ - es: esv1beta1.Elasticsearch{ObjectMeta: metav1.ObjectMeta{Name: "cluster", Namespace: "ns"}}, + es: esv1.Elasticsearch{ObjectMeta: metav1.ObjectMeta{Name: "cluster", Namespace: "ns"}}, statefulSets: sset.StatefulSetList{sset.TestSset{Replicas: 3, Master: true, Data: true}.Build()}, }, want: &v1beta1.PodDisruptionBudget{ ObjectMeta: metav1.ObjectMeta{ - Name: esv1beta1.DefaultPodDisruptionBudget("cluster"), + Name: esv1.DefaultPodDisruptionBudget("cluster"), Namespace: "ns", Labels: map[string]string{label.ClusterNameLabelName: "cluster", common.TypeLabelName: label.Type}, }, @@ -189,10 +189,10 @@ func Test_expectedPDB(t *testing.T) { { name: "Inherit user-provided labels", args: args{ - es: esv1beta1.Elasticsearch{ + es: esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{Name: "cluster", Namespace: "ns"}, - Spec: esv1beta1.ElasticsearchSpec{ - PodDisruptionBudget: &commonv1beta1.PodDisruptionBudgetTemplate{ + Spec: esv1.ElasticsearchSpec{ + PodDisruptionBudget: &commonv1.PodDisruptionBudgetTemplate{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"a": "b", "c": "d"}, }}, @@ -202,7 +202,7 @@ func Test_expectedPDB(t *testing.T) { }, want: &v1beta1.PodDisruptionBudget{ ObjectMeta: metav1.ObjectMeta{ - Name: esv1beta1.DefaultPodDisruptionBudget("cluster"), + Name: esv1.DefaultPodDisruptionBudget("cluster"), Namespace: "ns", Labels: map[string]string{"a": "b", "c": "d", label.ClusterNameLabelName: "cluster", common.TypeLabelName: label.Type}, }, @@ -220,10 +220,10 @@ func Test_expectedPDB(t *testing.T) { { name: "Use user-provided PDB spec", args: args{ - es: esv1beta1.Elasticsearch{ + es: esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{Name: "cluster", Namespace: "ns"}, - Spec: esv1beta1.ElasticsearchSpec{ - PodDisruptionBudget: &commonv1beta1.PodDisruptionBudgetTemplate{ + Spec: esv1.ElasticsearchSpec{ + PodDisruptionBudget: &commonv1.PodDisruptionBudgetTemplate{ Spec: v1beta1.PodDisruptionBudgetSpec{MinAvailable: intStrPtr(intstr.FromInt(42))}}, }, }, @@ -231,7 +231,7 @@ func Test_expectedPDB(t *testing.T) { }, want: &v1beta1.PodDisruptionBudget{ ObjectMeta: metav1.ObjectMeta{ - Name: esv1beta1.DefaultPodDisruptionBudget("cluster"), + Name: esv1.DefaultPodDisruptionBudget("cluster"), Namespace: "ns", Labels: map[string]string{label.ClusterNameLabelName: "cluster", common.TypeLabelName: label.Type}, }, @@ -258,7 +258,7 @@ func Test_expectedPDB(t *testing.T) { func Test_allowedDisruptions(t *testing.T) { type args struct { - es esv1beta1.Elasticsearch + es esv1.Elasticsearch actualSsets sset.StatefulSetList } tests := []struct { @@ -269,7 +269,7 @@ func Test_allowedDisruptions(t *testing.T) { { name: "no health reported: no disruption allowed", args: args{ - es: esv1beta1.Elasticsearch{Status: esv1beta1.ElasticsearchStatus{}}, + es: esv1.Elasticsearch{Status: esv1.ElasticsearchStatus{}}, actualSsets: sset.StatefulSetList{sset.TestSset{Replicas: 3}.Build()}, }, want: 0, @@ -277,7 +277,7 @@ func Test_allowedDisruptions(t *testing.T) { { name: "yellow health: no disruption allowed", args: args{ - es: esv1beta1.Elasticsearch{Status: esv1beta1.ElasticsearchStatus{Health: esv1beta1.ElasticsearchYellowHealth}}, + es: esv1.Elasticsearch{Status: esv1.ElasticsearchStatus{Health: esv1.ElasticsearchYellowHealth}}, actualSsets: sset.StatefulSetList{sset.TestSset{Replicas: 3}.Build()}, }, want: 0, @@ -285,7 +285,7 @@ func Test_allowedDisruptions(t *testing.T) { { name: "red health: no disruption allowed", args: args{ - es: esv1beta1.Elasticsearch{Status: esv1beta1.ElasticsearchStatus{Health: esv1beta1.ElasticsearchRedHealth}}, + es: esv1.Elasticsearch{Status: esv1.ElasticsearchStatus{Health: esv1.ElasticsearchRedHealth}}, actualSsets: sset.StatefulSetList{sset.TestSset{Replicas: 3, Master: true, Data: true}.Build()}, }, want: 0, @@ -293,7 +293,7 @@ func Test_allowedDisruptions(t *testing.T) { { name: "unknown health: no disruption allowed", args: args{ - es: esv1beta1.Elasticsearch{Status: esv1beta1.ElasticsearchStatus{Health: esv1beta1.ElasticsearchUnknownHealth}}, + es: esv1.Elasticsearch{Status: esv1.ElasticsearchStatus{Health: esv1.ElasticsearchUnknownHealth}}, actualSsets: sset.StatefulSetList{sset.TestSset{Replicas: 3, Master: true, Data: true}.Build()}, }, want: 0, @@ -301,7 +301,7 @@ func Test_allowedDisruptions(t *testing.T) { { name: "green health: 1 disruption allowed", args: args{ - es: esv1beta1.Elasticsearch{Status: esv1beta1.ElasticsearchStatus{Health: esv1beta1.ElasticsearchGreenHealth}}, + es: esv1.Elasticsearch{Status: esv1.ElasticsearchStatus{Health: esv1.ElasticsearchGreenHealth}}, actualSsets: sset.StatefulSetList{sset.TestSset{Replicas: 3, Master: true, Data: true}.Build()}, }, want: 1, @@ -309,7 +309,7 @@ func Test_allowedDisruptions(t *testing.T) { { name: "green health but single-node cluster: 0 disruption allowed", args: args{ - es: esv1beta1.Elasticsearch{Status: esv1beta1.ElasticsearchStatus{Health: esv1beta1.ElasticsearchGreenHealth}}, + es: esv1.Elasticsearch{Status: esv1.ElasticsearchStatus{Health: esv1.ElasticsearchGreenHealth}}, actualSsets: sset.StatefulSetList{sset.TestSset{Replicas: 1, Master: true, Data: true}.Build()}, }, want: 0, @@ -317,7 +317,7 @@ func Test_allowedDisruptions(t *testing.T) { { name: "green health but only 1 master: 0 disruption allowed", args: args{ - es: esv1beta1.Elasticsearch{Status: esv1beta1.ElasticsearchStatus{Health: esv1beta1.ElasticsearchGreenHealth}}, + es: esv1.Elasticsearch{Status: esv1.ElasticsearchStatus{Health: esv1.ElasticsearchGreenHealth}}, actualSsets: sset.StatefulSetList{ sset.TestSset{Replicas: 1, Master: true, Data: false}.Build(), sset.TestSset{Replicas: 3, Master: false, Data: true}.Build(), @@ -328,7 +328,7 @@ func Test_allowedDisruptions(t *testing.T) { { name: "green health but only 1 data node: 0 disruption allowed", args: args{ - es: esv1beta1.Elasticsearch{Status: esv1beta1.ElasticsearchStatus{Health: esv1beta1.ElasticsearchGreenHealth}}, + es: esv1.Elasticsearch{Status: esv1.ElasticsearchStatus{Health: esv1.ElasticsearchGreenHealth}}, actualSsets: sset.StatefulSetList{ sset.TestSset{Replicas: 3, Master: true, Data: false}.Build(), sset.TestSset{Replicas: 1, Master: false, Data: true}.Build(), @@ -339,7 +339,7 @@ func Test_allowedDisruptions(t *testing.T) { { name: "green health but only 1 ingest node: 0 disruption allowed", args: args{ - es: esv1beta1.Elasticsearch{Status: esv1beta1.ElasticsearchStatus{Health: esv1beta1.ElasticsearchGreenHealth}}, + es: esv1.Elasticsearch{Status: esv1.ElasticsearchStatus{Health: esv1.ElasticsearchGreenHealth}}, actualSsets: sset.StatefulSetList{ sset.TestSset{Replicas: 3, Master: true, Data: true, Ingest: false}.Build(), sset.TestSset{Replicas: 1, Ingest: true, Data: true}.Build(), diff --git a/pkg/controller/elasticsearch/reconcile/resources_state.go b/pkg/controller/elasticsearch/reconcile/resources_state.go index 7cd9b11b349..9a02c281e10 100644 --- a/pkg/controller/elasticsearch/reconcile/resources_state.go +++ b/pkg/controller/elasticsearch/reconcile/resources_state.go @@ -8,7 +8,7 @@ import ( corev1 "k8s.io/api/core/v1" "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/services" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" @@ -30,7 +30,7 @@ type ResourcesState struct { } // NewResourcesStateFromAPI reflects the current ResourcesState from the API -func NewResourcesStateFromAPI(c k8s.Client, es v1beta1.Elasticsearch) (*ResourcesState, error) { +func NewResourcesStateFromAPI(c k8s.Client, es esv1.Elasticsearch) (*ResourcesState, error) { labelSelector := label.NewLabelSelectorForElasticsearch(es) allPods, err := getPods(c, es, labelSelector) @@ -78,7 +78,7 @@ func NewResourcesStateFromAPI(c k8s.Client, es v1beta1.Elasticsearch) (*Resource // getPods returns list of pods in the current namespace with a specific set of selectors. func getPods( c k8s.Client, - es v1beta1.Elasticsearch, + es esv1.Elasticsearch, labelSelector client.MatchingLabels, ) ([]corev1.Pod, error) { var podList corev1.PodList diff --git a/pkg/controller/elasticsearch/reconcile/state.go b/pkg/controller/elasticsearch/reconcile/state.go index 962f1d61254..531d3a49ec4 100644 --- a/pkg/controller/elasticsearch/reconcile/state.go +++ b/pkg/controller/elasticsearch/reconcile/state.go @@ -7,23 +7,24 @@ package reconcile import ( "reflect" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + corev1 "k8s.io/api/core/v1" + + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/events" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/observer" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" - corev1 "k8s.io/api/core/v1" ) // State holds the accumulated state during the reconcile loop including the response and a pointer to an // Elasticsearch resource for status updates. type State struct { *events.Recorder - cluster v1beta1.Elasticsearch - status v1beta1.ElasticsearchStatus + cluster esv1.Elasticsearch + status esv1.ElasticsearchStatus } // NewState creates a new reconcile state based on the given cluster -func NewState(c v1beta1.Elasticsearch) *State { +func NewState(c esv1.Elasticsearch) *State { return &State{Recorder: events.NewRecorder(), cluster: c, status: *c.Status.DeepCopy()} } @@ -39,16 +40,16 @@ func AvailableElasticsearchNodes(pods []corev1.Pod) []corev1.Pod { } func (s *State) updateWithPhase( - phase v1beta1.ElasticsearchOrchestrationPhase, + phase esv1.ElasticsearchOrchestrationPhase, resourcesState ResourcesState, observedState observer.State, ) *State { s.status.AvailableNodes = int32(len(AvailableElasticsearchNodes(resourcesState.CurrentPods))) s.status.Phase = phase - s.status.Health = v1beta1.ElasticsearchUnknownHealth + s.status.Health = esv1.ElasticsearchUnknownHealth if observedState.ClusterHealth != nil && observedState.ClusterHealth.Status != "" { - s.status.Health = v1beta1.ElasticsearchHealth(observedState.ClusterHealth.Status) + s.status.Health = esv1.ElasticsearchHealth(observedState.ClusterHealth.Status) } return s } @@ -66,19 +67,19 @@ func (s *State) UpdateElasticsearchReady( resourcesState ResourcesState, observedState observer.State, ) *State { - return s.updateWithPhase(v1beta1.ElasticsearchReadyPhase, resourcesState, observedState) + return s.updateWithPhase(esv1.ElasticsearchReadyPhase, resourcesState, observedState) } // IsElasticsearchReady reports if Elasticsearch is ready. func (s *State) IsElasticsearchReady(observedState observer.State) bool { - return s.status.Phase == v1beta1.ElasticsearchReadyPhase + return s.status.Phase == esv1.ElasticsearchReadyPhase } // UpdateElasticsearchApplyingChanges marks Elasticsearch as being the applying changes phase in the resource status. func (s *State) UpdateElasticsearchApplyingChanges(pods []corev1.Pod) *State { s.status.AvailableNodes = int32(len(AvailableElasticsearchNodes(pods))) - s.status.Phase = v1beta1.ElasticsearchApplyingChangesPhase - s.status.Health = v1beta1.ElasticsearchRedHealth + s.status.Phase = esv1.ElasticsearchApplyingChangesPhase + s.status.Health = esv1.ElasticsearchRedHealth return s } @@ -92,13 +93,13 @@ func (s *State) UpdateElasticsearchMigrating( events.EventReasonDelayed, "Requested topology change delayed by data migration", ) - return s.updateWithPhase(v1beta1.ElasticsearchMigratingDataPhase, resourcesState, observedState) + return s.updateWithPhase(esv1.ElasticsearchMigratingDataPhase, resourcesState, observedState) } // Apply takes the current Elasticsearch status, compares it to the previous status, and updates the status accordingly. // It returns the events to emit and an updated version of the Elasticsearch cluster resource with // the current status applied to its status sub-resource. -func (s *State) Apply() ([]events.Event, *v1beta1.Elasticsearch) { +func (s *State) Apply() ([]events.Event, *esv1.Elasticsearch) { previous := s.cluster.Status current := s.status if reflect.DeepEqual(previous, current) { @@ -112,6 +113,6 @@ func (s *State) Apply() ([]events.Event, *v1beta1.Elasticsearch) { } func (s *State) UpdateElasticsearchInvalid(err error) { - s.status.Phase = v1beta1.ElasticsearchResourceInvalid + s.status.Phase = esv1.ElasticsearchResourceInvalid s.AddEvent(corev1.EventTypeWarning, events.EventReasonValidation, err.Error()) } diff --git a/pkg/controller/elasticsearch/reconcile/state_test.go b/pkg/controller/elasticsearch/reconcile/state_test.go index 98960df2b4f..c44238950ee 100644 --- a/pkg/controller/elasticsearch/reconcile/state_test.go +++ b/pkg/controller/elasticsearch/reconcile/state_test.go @@ -9,14 +9,15 @@ import ( "testing" "time" - v1beta12 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/events" - "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" - "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/observer" "github.com/stretchr/testify/assert" corev1 "k8s.io/api/core/v1" "sigs.k8s.io/controller-runtime/pkg/reconcile" + + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/events" + "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" + "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/observer" ) func TestNodesAvailable(t *testing.T) { @@ -133,37 +134,37 @@ func TestNodesAvailable(t *testing.T) { func TestState_Apply(t *testing.T) { tests := []struct { name string - cluster v1beta1.Elasticsearch + cluster esv1.Elasticsearch effects func(s *State) wantEvents []events.Event - wantStatus *v1beta1.ElasticsearchStatus + wantStatus *esv1.ElasticsearchStatus }{ { name: "defaults", - cluster: v1beta1.Elasticsearch{}, + cluster: esv1.Elasticsearch{}, wantEvents: []events.Event{}, wantStatus: nil, }, { name: "no degraded health event on cluster formation", - cluster: v1beta1.Elasticsearch{}, + cluster: esv1.Elasticsearch{}, effects: func(s *State) { s.UpdateElasticsearchApplyingChanges([]corev1.Pod{}) }, wantEvents: []events.Event{}, - wantStatus: &v1beta1.ElasticsearchStatus{ - ReconcilerStatus: v1beta12.ReconcilerStatus{ + wantStatus: &esv1.ElasticsearchStatus{ + ReconcilerStatus: commonv1.ReconcilerStatus{ AvailableNodes: 0, }, - Health: v1beta1.ElasticsearchRedHealth, - Phase: v1beta1.ElasticsearchApplyingChangesPhase, + Health: esv1.ElasticsearchRedHealth, + Phase: esv1.ElasticsearchApplyingChangesPhase, }, }, { name: "no degraded health event when cluster info is unknown", - cluster: v1beta1.Elasticsearch{ - Status: v1beta1.ElasticsearchStatus{ - Health: v1beta1.ElasticsearchGreenHealth, + cluster: esv1.Elasticsearch{ + Status: esv1.ElasticsearchStatus{ + Health: esv1.ElasticsearchGreenHealth, }, }, effects: func(s *State) { @@ -173,31 +174,31 @@ func TestState_Apply(t *testing.T) { }) }, wantEvents: []events.Event{}, - wantStatus: &v1beta1.ElasticsearchStatus{ - ReconcilerStatus: v1beta12.ReconcilerStatus{ + wantStatus: &esv1.ElasticsearchStatus{ + ReconcilerStatus: commonv1.ReconcilerStatus{ AvailableNodes: 0, }, - Health: v1beta1.ElasticsearchUnknownHealth, + Health: esv1.ElasticsearchUnknownHealth, Phase: "", }, }, { name: "health degraded", - cluster: v1beta1.Elasticsearch{ - Status: v1beta1.ElasticsearchStatus{ - Health: v1beta1.ElasticsearchGreenHealth, + cluster: esv1.Elasticsearch{ + Status: esv1.ElasticsearchStatus{ + Health: esv1.ElasticsearchGreenHealth, }, }, effects: func(s *State) { s.UpdateElasticsearchApplyingChanges([]corev1.Pod{}) }, wantEvents: []events.Event{{EventType: corev1.EventTypeWarning, Reason: events.EventReasonUnhealthy, Message: "Elasticsearch cluster health degraded"}}, - wantStatus: &v1beta1.ElasticsearchStatus{ - ReconcilerStatus: v1beta12.ReconcilerStatus{ + wantStatus: &esv1.ElasticsearchStatus{ + ReconcilerStatus: commonv1.ReconcilerStatus{ AvailableNodes: 0, }, - Health: v1beta1.ElasticsearchRedHealth, - Phase: v1beta1.ElasticsearchApplyingChangesPhase, + Health: esv1.ElasticsearchRedHealth, + Phase: esv1.ElasticsearchApplyingChangesPhase, }, }, } @@ -211,7 +212,7 @@ func TestState_Apply(t *testing.T) { if !reflect.DeepEqual(events, tt.wantEvents) { t.Errorf("State.Apply() events = %v, wantEvents %v", events, tt.wantEvents) } - var actual *v1beta1.ElasticsearchStatus + var actual *esv1.ElasticsearchStatus if cluster != nil { actual = &cluster.Status } @@ -229,31 +230,31 @@ func TestState_UpdateElasticsearchState(t *testing.T) { } tests := []struct { name string - cluster v1beta1.Elasticsearch + cluster esv1.Elasticsearch args args stateAssertions func(s *State) }{ { name: "phase is not changed by default", - cluster: v1beta1.Elasticsearch{ - Status: v1beta1.ElasticsearchStatus{ - Phase: v1beta1.ElasticsearchApplyingChangesPhase, + cluster: esv1.Elasticsearch{ + Status: esv1.ElasticsearchStatus{ + Phase: esv1.ElasticsearchApplyingChangesPhase, }, }, stateAssertions: func(s *State) { - assert.EqualValues(t, v1beta1.ElasticsearchApplyingChangesPhase, s.status.Phase) + assert.EqualValues(t, esv1.ElasticsearchApplyingChangesPhase, s.status.Phase) }, }, { name: "health is unknown by default", - cluster: v1beta1.Elasticsearch{}, + cluster: esv1.Elasticsearch{}, stateAssertions: func(s *State) { - assert.EqualValues(t, v1beta1.ElasticsearchUnknownHealth, s.status.Health) + assert.EqualValues(t, esv1.ElasticsearchUnknownHealth, s.status.Health) }, }, { name: "health is set if returned by Elasticsearch", - cluster: v1beta1.Elasticsearch{}, + cluster: esv1.Elasticsearch{}, args: args{ observedState: observer.State{ ClusterHealth: &client.Health{Status: "green"}, @@ -284,18 +285,18 @@ func TestState_UpdateElasticsearchMigrating(t *testing.T) { } tests := []struct { name string - cluster v1beta1.Elasticsearch + cluster esv1.Elasticsearch args args stateAssertions func(s *State) }{ { name: "base case", - cluster: v1beta1.Elasticsearch{}, + cluster: esv1.Elasticsearch{}, args: args{ result: reconcile.Result{RequeueAfter: 10 * time.Minute}, }, stateAssertions: func(s *State) { - assert.EqualValues(t, v1beta1.ElasticsearchMigratingDataPhase, s.status.Phase) + assert.EqualValues(t, esv1.ElasticsearchMigratingDataPhase, s.status.Phase) assert.Equal(t, []events.Event{{EventType: corev1.EventTypeNormal, Reason: events.EventReasonDelayed, Message: "Requested topology change delayed by data migration"}}, s.Recorder.Events()) }, }, diff --git a/pkg/controller/elasticsearch/services/services.go b/pkg/controller/elasticsearch/services/services.go index 10914328b69..7051a77f993 100644 --- a/pkg/controller/elasticsearch/services/services.go +++ b/pkg/controller/elasticsearch/services/services.go @@ -12,7 +12,7 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/defaults" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/network" @@ -27,17 +27,17 @@ const ( // ExternalServiceName returns the name for the external service // associated to this cluster func ExternalServiceName(esName string) string { - return v1beta1.HTTPService(esName) + return esv1.HTTPService(esName) } // ExternalServiceURL returns the URL used to reach Elasticsearch's external endpoint -func ExternalServiceURL(es v1beta1.Elasticsearch) string { +func ExternalServiceURL(es esv1.Elasticsearch) string { return stringsutil.Concat(es.Spec.HTTP.Protocol(), "://", ExternalServiceName(es.Name), ".", es.Namespace, globalServiceSuffix, ":", strconv.Itoa(network.HTTPPort)) } // NewExternalService returns the external service associated to the given cluster // It is used by users to perform requests against one of the cluster nodes. -func NewExternalService(es v1beta1.Elasticsearch) *corev1.Service { +func NewExternalService(es esv1.Elasticsearch) *corev1.Service { nsn := k8s.ExtractNamespacedName(&es) svc := corev1.Service{ @@ -77,7 +77,7 @@ func IsServiceReady(c k8s.Client, service corev1.Service) (bool, error) { } // GetExternalService returns the external service associated to the given Elasticsearch cluster. -func GetExternalService(c k8s.Client, es v1beta1.Elasticsearch) (corev1.Service, error) { +func GetExternalService(c k8s.Client, es esv1.Elasticsearch) (corev1.Service, error) { var svc corev1.Service namespacedName := types.NamespacedName{ @@ -95,7 +95,7 @@ func GetExternalService(c k8s.Client, es v1beta1.Elasticsearch) (corev1.Service, // ElasticsearchURL calculates the base url for Elasticsearch, taking into account the currently running pods. // If there is an HTTP scheme mismatch between spec and pods we switch to requesting individual pods directly // otherwise this delegates to ExternalServiceURL. -func ElasticsearchURL(es v1beta1.Elasticsearch, pods []corev1.Pod) string { +func ElasticsearchURL(es esv1.Elasticsearch, pods []corev1.Pod) string { var schemeChange bool for _, p := range pods { scheme, exists := p.Labels[label.HTTPSchemeLabelName] diff --git a/pkg/controller/elasticsearch/services/services_test.go b/pkg/controller/elasticsearch/services/services_test.go index 43ea81a858f..fee36ac8436 100644 --- a/pkg/controller/elasticsearch/services/services_test.go +++ b/pkg/controller/elasticsearch/services/services_test.go @@ -7,8 +7,8 @@ package services import ( "testing" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/network" @@ -20,7 +20,7 @@ import ( func TestExternalServiceURL(t *testing.T) { type args struct { - es v1beta1.Elasticsearch + es esv1.Elasticsearch } tests := []struct { name string @@ -29,7 +29,7 @@ func TestExternalServiceURL(t *testing.T) { }{ { name: "A service URL", - args: args{es: v1beta1.Elasticsearch{ + args: args{es: esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Name: "an-es-name", Namespace: "default", @@ -39,7 +39,7 @@ func TestExternalServiceURL(t *testing.T) { }, { name: "Another Service URL", - args: args{es: v1beta1.Elasticsearch{ + args: args{es: esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Name: "another-es-name", Namespace: "default", @@ -58,7 +58,7 @@ func TestExternalServiceURL(t *testing.T) { func TestElasticsearchURL(t *testing.T) { type args struct { - es v1beta1.Elasticsearch + es esv1.Elasticsearch pods []corev1.Pod } tests := []struct { @@ -69,7 +69,7 @@ func TestElasticsearchURL(t *testing.T) { { name: "default: external service url", args: args{ - es: v1beta1.Elasticsearch{ + es: esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Name: "my-cluster", Namespace: "my-ns", @@ -90,7 +90,7 @@ func TestElasticsearchURL(t *testing.T) { { name: "scheme change in progress: random pod address", args: args{ - es: v1beta1.Elasticsearch{ + es: esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Name: "my-cluster", Namespace: "my-ns", @@ -114,7 +114,7 @@ func TestElasticsearchURL(t *testing.T) { { name: "unexpected: missing pod labels: fallback to service", args: args{ - es: v1beta1.Elasticsearch{ + es: esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Name: "my-cluster", Namespace: "my-ns", @@ -129,7 +129,7 @@ func TestElasticsearchURL(t *testing.T) { { name: "unexpected: partially missing pod labels: fallback to service", args: args{ - es: v1beta1.Elasticsearch{ + es: esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Name: "my-cluster", Namespace: "my-ns", @@ -160,14 +160,14 @@ func TestElasticsearchURL(t *testing.T) { func TestNewExternalService(t *testing.T) { testCases := []struct { name string - httpConf commonv1beta1.HTTPConfig + httpConf commonv1.HTTPConfig wantSvc func() corev1.Service }{ { name: "no TLS", - httpConf: commonv1beta1.HTTPConfig{ - TLS: commonv1beta1.TLSOptions{ - SelfSignedCertificate: &commonv1beta1.SelfSignedCertificate{ + httpConf: commonv1.HTTPConfig{ + TLS: commonv1.TLSOptions{ + SelfSignedCertificate: &commonv1.SelfSignedCertificate{ Disabled: true, }, }, @@ -176,10 +176,10 @@ func TestNewExternalService(t *testing.T) { }, { name: "self-signed certificate", - httpConf: commonv1beta1.HTTPConfig{ - TLS: commonv1beta1.TLSOptions{ - SelfSignedCertificate: &commonv1beta1.SelfSignedCertificate{ - SubjectAlternativeNames: []commonv1beta1.SubjectAlternativeName{ + httpConf: commonv1.HTTPConfig{ + TLS: commonv1.TLSOptions{ + SelfSignedCertificate: &commonv1.SelfSignedCertificate{ + SubjectAlternativeNames: []commonv1.SubjectAlternativeName{ { DNS: "elasticsearch-test.local", }, @@ -195,9 +195,9 @@ func TestNewExternalService(t *testing.T) { }, { name: "user-provided certificate", - httpConf: commonv1beta1.HTTPConfig{ - TLS: commonv1beta1.TLSOptions{ - Certificate: commonv1beta1.SecretRef{ + httpConf: commonv1.HTTPConfig{ + TLS: commonv1.TLSOptions{ + Certificate: commonv1.SecretRef{ SecretName: "my-cert", }, }, @@ -245,13 +245,13 @@ func mkService() corev1.Service { } } -func mkElasticsearch(httpConf commonv1beta1.HTTPConfig) v1beta1.Elasticsearch { - return v1beta1.Elasticsearch{ +func mkElasticsearch(httpConf commonv1.HTTPConfig) esv1.Elasticsearch { + return esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Name: "elasticsearch-test", Namespace: "test", }, - Spec: v1beta1.ElasticsearchSpec{ + Spec: esv1.ElasticsearchSpec{ HTTP: httpConf, }, } diff --git a/pkg/controller/elasticsearch/settings/canonical_config.go b/pkg/controller/elasticsearch/settings/canonical_config.go index c47fb79f87b..a17c70c9f22 100644 --- a/pkg/controller/elasticsearch/settings/canonical_config.go +++ b/pkg/controller/elasticsearch/settings/canonical_config.go @@ -5,7 +5,7 @@ package settings import ( - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" common "github.com/elastic/cloud-on-k8s/pkg/controller/common/settings" ) @@ -20,8 +20,8 @@ func NewCanonicalConfig() CanonicalConfig { } // Unpack returns a typed subset of Elasticsearch settings. -func (c CanonicalConfig) Unpack() (v1beta1.ElasticsearchSettings, error) { - cfg := v1beta1.DefaultCfg +func (c CanonicalConfig) Unpack() (esv1.ElasticsearchSettings, error) { + cfg := esv1.DefaultCfg err := c.CanonicalConfig.Unpack(&cfg) return cfg, err } diff --git a/pkg/controller/elasticsearch/settings/config_volume.go b/pkg/controller/elasticsearch/settings/config_volume.go index 2ae5291d048..47abe92b4aa 100644 --- a/pkg/controller/elasticsearch/settings/config_volume.go +++ b/pkg/controller/elasticsearch/settings/config_volume.go @@ -13,7 +13,7 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes/scheme" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" common "github.com/elastic/cloud-on-k8s/pkg/controller/common/settings" "github.com/elastic/cloud-on-k8s/pkg/controller/common/volume" @@ -30,7 +30,7 @@ const ( // ConfigSecretName is the name of the secret that holds the ES config for the given StatefulSet. func ConfigSecretName(ssetName string) string { - return v1beta1.ConfigSecret(ssetName) + return esv1.ConfigSecret(ssetName) } // ConfigSecretVolume returns a SecretVolume to hold the config of nodes in the given stateful set.. @@ -76,7 +76,7 @@ func GetESConfigSecret(client k8s.Client, namespace string, ssetName string) (co return secret, nil } -func ConfigSecret(es v1beta1.Elasticsearch, ssetName string, configData []byte) corev1.Secret { +func ConfigSecret(es esv1.Elasticsearch, ssetName string, configData []byte) corev1.Secret { return corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Namespace: es.Namespace, @@ -90,7 +90,7 @@ func ConfigSecret(es v1beta1.Elasticsearch, ssetName string, configData []byte) } // ReconcileConfig ensures the ES config for the pod is set in the apiserver. -func ReconcileConfig(client k8s.Client, es v1beta1.Elasticsearch, ssetName string, config CanonicalConfig) error { +func ReconcileConfig(client k8s.Client, es esv1.Elasticsearch, ssetName string, config CanonicalConfig) error { rendered, err := config.Render() if err != nil { return err diff --git a/pkg/controller/elasticsearch/settings/config_volume_test.go b/pkg/controller/elasticsearch/settings/config_volume_test.go index 6c7968ce115..21668016e21 100644 --- a/pkg/controller/elasticsearch/settings/config_volume_test.go +++ b/pkg/controller/elasticsearch/settings/config_volume_test.go @@ -8,7 +8,7 @@ import ( "reflect" "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" common "github.com/elastic/cloud-on-k8s/pkg/controller/common/settings" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" @@ -90,7 +90,7 @@ func TestGetESConfigContent(t *testing.T) { } func TestReconcileConfig(t *testing.T) { - es := v1beta1.Elasticsearch{ + es := esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Namespace: "ns", Name: "cluster", @@ -116,7 +116,7 @@ func TestReconcileConfig(t *testing.T) { tests := []struct { name string client k8s.Client - es v1beta1.Elasticsearch + es esv1.Elasticsearch ssetName string config CanonicalConfig wantErr bool diff --git a/pkg/controller/elasticsearch/settings/masters.go b/pkg/controller/elasticsearch/settings/masters.go index dd1a4629663..f4c820d1492 100644 --- a/pkg/controller/elasticsearch/settings/masters.go +++ b/pkg/controller/elasticsearch/settings/masters.go @@ -10,7 +10,7 @@ import ( "sort" "strings" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/annotation" "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" @@ -36,7 +36,7 @@ func Quorum(nMasters int) int { func UpdateSeedHostsConfigMap( c k8s.Client, scheme *runtime.Scheme, - es v1beta1.Elasticsearch, + es esv1.Elasticsearch, pods []corev1.Pod, ) error { // Get the masters from the pods @@ -66,7 +66,7 @@ func UpdateSeedHostsConfigMap( } expected := corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Name: v1beta1.UnicastHostsConfigMap(es.Name), + Name: esv1.UnicastHostsConfigMap(es.Name), Namespace: es.Namespace, Labels: label.NewLabels(k8s.ExtractNamespacedName(&es)), }, diff --git a/pkg/controller/elasticsearch/settings/masters_test.go b/pkg/controller/elasticsearch/settings/masters_test.go index f53fc759a2c..374099d700e 100644 --- a/pkg/controller/elasticsearch/settings/masters_test.go +++ b/pkg/controller/elasticsearch/settings/masters_test.go @@ -7,7 +7,7 @@ package settings import ( "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/volume" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" @@ -38,7 +38,7 @@ func newPodWithIP(name, ip string, master bool) corev1.Pod { } func TestUpdateSeedHostsConfigMap(t *testing.T) { - es := v1beta1.Elasticsearch{ + es := esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Name: "es1", Namespace: "ns1", @@ -47,7 +47,7 @@ func TestUpdateSeedHostsConfigMap(t *testing.T) { type args struct { c k8s.Client scheme *runtime.Scheme - es v1beta1.Elasticsearch + es esv1.Elasticsearch pods []corev1.Pod } tests := []struct { @@ -150,7 +150,7 @@ func TestUpdateSeedHostsConfigMap(t *testing.T) { if err := tt.args.c.Get( types.NamespacedName{ Namespace: "ns1", - Name: v1beta1.UnicastHostsConfigMap(es.Name), + Name: esv1.UnicastHostsConfigMap(es.Name), }, file); err != nil { t.Errorf("Error while getting the seed hosts configmap: %v", err) } diff --git a/pkg/controller/elasticsearch/settings/merged_config.go b/pkg/controller/elasticsearch/settings/merged_config.go index deee3915200..28d82cfbf25 100644 --- a/pkg/controller/elasticsearch/settings/merged_config.go +++ b/pkg/controller/elasticsearch/settings/merged_config.go @@ -7,8 +7,8 @@ package settings import ( "path" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - estype "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" common "github.com/elastic/cloud-on-k8s/pkg/controller/common/settings" "github.com/elastic/cloud-on-k8s/pkg/controller/common/version" @@ -21,8 +21,8 @@ import ( func NewMergedESConfig( clusterName string, ver version.Version, - httpConfig commonv1beta1.HTTPConfig, - userConfig commonv1beta1.Config, + httpConfig commonv1.HTTPConfig, + userConfig commonv1.Config, certResources *escerts.CertificateResources, ) (CanonicalConfig, error) { config, err := common.NewCanonicalConfigFrom(userConfig.Data) @@ -43,74 +43,74 @@ func NewMergedESConfig( func baseConfig(clusterName string, ver version.Version) *CanonicalConfig { cfg := map[string]interface{}{ // derive node name dynamically from the pod name, injected as env var - estype.NodeName: "${" + EnvPodName + "}", - estype.ClusterName: clusterName, + esv1.NodeName: "${" + EnvPodName + "}", + esv1.ClusterName: clusterName, // derive IP dynamically from the pod IP, injected as env var - estype.NetworkPublishHost: "${" + EnvPodIP + "}", - estype.NetworkHost: "0.0.0.0", + esv1.NetworkPublishHost: "${" + EnvPodIP + "}", + esv1.NetworkHost: "0.0.0.0", - estype.PathData: volume.ElasticsearchDataMountPath, - estype.PathLogs: volume.ElasticsearchLogsMountPath, + esv1.PathData: volume.ElasticsearchDataMountPath, + esv1.PathLogs: volume.ElasticsearchLogsMountPath, } // seed hosts setting name changed starting ES 7.X fileProvider := "file" if ver.Major < 7 { - cfg[estype.DiscoveryZenHostsProvider] = fileProvider + cfg[esv1.DiscoveryZenHostsProvider] = fileProvider } else { - cfg[estype.DiscoverySeedProviders] = fileProvider + cfg[esv1.DiscoverySeedProviders] = fileProvider } return &CanonicalConfig{common.MustCanonicalConfig(cfg)} } // xpackConfig returns the configuration bit related to XPack settings -func xpackConfig(ver version.Version, httpCfg commonv1beta1.HTTPConfig, certResources *escerts.CertificateResources) *CanonicalConfig { +func xpackConfig(ver version.Version, httpCfg commonv1.HTTPConfig, certResources *escerts.CertificateResources) *CanonicalConfig { // enable x-pack security, including TLS cfg := map[string]interface{}{ // x-pack security general settings - estype.XPackSecurityEnabled: "true", - estype.XPackSecurityAuthcReservedRealmEnabled: "false", - estype.XPackSecurityTransportSslVerificationMode: "certificate", + esv1.XPackSecurityEnabled: "true", + esv1.XPackSecurityAuthcReservedRealmEnabled: "false", + esv1.XPackSecurityTransportSslVerificationMode: "certificate", // x-pack security http settings - estype.XPackSecurityHttpSslEnabled: httpCfg.TLS.Enabled(), - estype.XPackSecurityHttpSslKey: path.Join(volume.HTTPCertificatesSecretVolumeMountPath, certificates.KeyFileName), - estype.XPackSecurityHttpSslCertificate: path.Join(volume.HTTPCertificatesSecretVolumeMountPath, certificates.CertFileName), + esv1.XPackSecurityHttpSslEnabled: httpCfg.TLS.Enabled(), + esv1.XPackSecurityHttpSslKey: path.Join(volume.HTTPCertificatesSecretVolumeMountPath, certificates.KeyFileName), + esv1.XPackSecurityHttpSslCertificate: path.Join(volume.HTTPCertificatesSecretVolumeMountPath, certificates.CertFileName), // x-pack security transport settings - estype.XPackSecurityTransportSslEnabled: "true", - estype.XPackSecurityTransportSslKey: path.Join( + esv1.XPackSecurityTransportSslEnabled: "true", + esv1.XPackSecurityTransportSslKey: path.Join( volume.ConfigVolumeMountPath, volume.NodeTransportCertificatePathSegment, volume.NodeTransportCertificateKeyFile, ), - estype.XPackSecurityTransportSslCertificate: path.Join( + esv1.XPackSecurityTransportSslCertificate: path.Join( volume.ConfigVolumeMountPath, volume.NodeTransportCertificatePathSegment, volume.NodeTransportCertificateCertFile, ), - estype.XPackSecurityTransportSslCertificateAuthorities: []string{ + esv1.XPackSecurityTransportSslCertificateAuthorities: []string{ path.Join(volume.TransportCertificatesSecretVolumeMountPath, certificates.CAFileName), }, } if certResources.HTTPCACertProvided { - cfg[estype.XPackSecurityHttpSslCertificateAuthorities] = path.Join(volume.HTTPCertificatesSecretVolumeMountPath, certificates.CAFileName) + cfg[esv1.XPackSecurityHttpSslCertificateAuthorities] = path.Join(volume.HTTPCertificatesSecretVolumeMountPath, certificates.CAFileName) } // always enable the built-in file and native internal realms for user auth, ordered as first if ver.Major < 7 { // 6.x syntax - cfg[estype.XPackSecurityAuthcRealmsFile1Type] = "file" - cfg[estype.XPackSecurityAuthcRealmsFile1Order] = -100 - cfg[estype.XPackSecurityAuthcRealmsNative1Type] = "native" - cfg[estype.XPackSecurityAuthcRealmsNative1Order] = -99 + cfg[esv1.XPackSecurityAuthcRealmsFile1Type] = "file" + cfg[esv1.XPackSecurityAuthcRealmsFile1Order] = -100 + cfg[esv1.XPackSecurityAuthcRealmsNative1Type] = "native" + cfg[esv1.XPackSecurityAuthcRealmsNative1Order] = -99 } else { // 7.x syntax - cfg[estype.XPackSecurityAuthcRealmsFileFile1Order] = -100 - cfg[estype.XPackSecurityAuthcRealmsNativeNative1Order] = -99 + cfg[esv1.XPackSecurityAuthcRealmsFileFile1Order] = -100 + cfg[esv1.XPackSecurityAuthcRealmsNativeNative1Order] = -99 } return &CanonicalConfig{common.MustCanonicalConfig(cfg)} diff --git a/pkg/controller/elasticsearch/settings/merged_config_test.go b/pkg/controller/elasticsearch/settings/merged_config_test.go index 13e3b2b17b6..5b02aef4df5 100644 --- a/pkg/controller/elasticsearch/settings/merged_config_test.go +++ b/pkg/controller/elasticsearch/settings/merged_config_test.go @@ -7,11 +7,12 @@ package settings import ( "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - estype "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + "github.com/stretchr/testify/require" + + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/version" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/certificates" - "github.com/stretchr/testify/require" ) func TestNewMergedESConfig(t *testing.T) { @@ -32,10 +33,10 @@ func TestNewMergedESConfig(t *testing.T) { cfgData: map[string]interface{}{}, assert: func(cfg CanonicalConfig) { require.Equal(t, 0, len(cfg.HasKeys([]string{nodeML}))) - require.Equal(t, 1, len(cfg.HasKeys([]string{estype.XPackSecurityAuthcRealmsFile1Type}))) - require.Equal(t, 1, len(cfg.HasKeys([]string{estype.XPackSecurityAuthcRealmsFile1Order}))) - require.Equal(t, 1, len(cfg.HasKeys([]string{estype.XPackSecurityAuthcRealmsNative1Type}))) - require.Equal(t, 1, len(cfg.HasKeys([]string{estype.XPackSecurityAuthcRealmsNative1Order}))) + require.Equal(t, 1, len(cfg.HasKeys([]string{esv1.XPackSecurityAuthcRealmsFile1Type}))) + require.Equal(t, 1, len(cfg.HasKeys([]string{esv1.XPackSecurityAuthcRealmsFile1Order}))) + require.Equal(t, 1, len(cfg.HasKeys([]string{esv1.XPackSecurityAuthcRealmsNative1Type}))) + require.Equal(t, 1, len(cfg.HasKeys([]string{esv1.XPackSecurityAuthcRealmsNative1Order}))) }, }, { @@ -46,10 +47,10 @@ func TestNewMergedESConfig(t *testing.T) { }, assert: func(cfg CanonicalConfig) { require.Equal(t, 1, len(cfg.HasKeys([]string{nodeML}))) - require.Equal(t, 1, len(cfg.HasKeys([]string{estype.XPackSecurityAuthcRealmsFile1Type}))) - require.Equal(t, 1, len(cfg.HasKeys([]string{estype.XPackSecurityAuthcRealmsFile1Order}))) - require.Equal(t, 1, len(cfg.HasKeys([]string{estype.XPackSecurityAuthcRealmsNative1Type}))) - require.Equal(t, 1, len(cfg.HasKeys([]string{estype.XPackSecurityAuthcRealmsNative1Order}))) + require.Equal(t, 1, len(cfg.HasKeys([]string{esv1.XPackSecurityAuthcRealmsFile1Type}))) + require.Equal(t, 1, len(cfg.HasKeys([]string{esv1.XPackSecurityAuthcRealmsFile1Order}))) + require.Equal(t, 1, len(cfg.HasKeys([]string{esv1.XPackSecurityAuthcRealmsNative1Type}))) + require.Equal(t, 1, len(cfg.HasKeys([]string{esv1.XPackSecurityAuthcRealmsNative1Order}))) }, }, { @@ -62,10 +63,10 @@ func TestNewMergedESConfig(t *testing.T) { }, assert: func(cfg CanonicalConfig) { require.Equal(t, 1, len(cfg.HasKeys([]string{nodeML}))) - require.Equal(t, 1, len(cfg.HasKeys([]string{estype.XPackSecurityAuthcRealmsFile1Type}))) - require.Equal(t, 1, len(cfg.HasKeys([]string{estype.XPackSecurityAuthcRealmsFile1Order}))) - require.Equal(t, 1, len(cfg.HasKeys([]string{estype.XPackSecurityAuthcRealmsNative1Type}))) - require.Equal(t, 1, len(cfg.HasKeys([]string{estype.XPackSecurityAuthcRealmsNative1Order}))) + require.Equal(t, 1, len(cfg.HasKeys([]string{esv1.XPackSecurityAuthcRealmsFile1Type}))) + require.Equal(t, 1, len(cfg.HasKeys([]string{esv1.XPackSecurityAuthcRealmsFile1Order}))) + require.Equal(t, 1, len(cfg.HasKeys([]string{esv1.XPackSecurityAuthcRealmsNative1Type}))) + require.Equal(t, 1, len(cfg.HasKeys([]string{esv1.XPackSecurityAuthcRealmsNative1Order}))) require.Equal(t, 1, len(cfg.HasKeys([]string{xPackSecurityAuthcRealmsAD1Type}))) require.Equal(t, 1, len(cfg.HasKeys([]string{xPackSecurityAuthcRealmsAD1Order}))) }, @@ -76,8 +77,8 @@ func TestNewMergedESConfig(t *testing.T) { cfgData: map[string]interface{}{}, assert: func(cfg CanonicalConfig) { require.Equal(t, 0, len(cfg.HasKeys([]string{nodeML}))) - require.Equal(t, 1, len(cfg.HasKeys([]string{estype.XPackSecurityAuthcRealmsFileFile1Order}))) - require.Equal(t, 1, len(cfg.HasKeys([]string{estype.XPackSecurityAuthcRealmsNativeNative1Order}))) + require.Equal(t, 1, len(cfg.HasKeys([]string{esv1.XPackSecurityAuthcRealmsFileFile1Order}))) + require.Equal(t, 1, len(cfg.HasKeys([]string{esv1.XPackSecurityAuthcRealmsNativeNative1Order}))) }, }, { @@ -88,8 +89,8 @@ func TestNewMergedESConfig(t *testing.T) { }, assert: func(cfg CanonicalConfig) { require.Equal(t, 1, len(cfg.HasKeys([]string{nodeML}))) - require.Equal(t, 1, len(cfg.HasKeys([]string{estype.XPackSecurityAuthcRealmsFileFile1Order}))) - require.Equal(t, 1, len(cfg.HasKeys([]string{estype.XPackSecurityAuthcRealmsNativeNative1Order}))) + require.Equal(t, 1, len(cfg.HasKeys([]string{esv1.XPackSecurityAuthcRealmsFileFile1Order}))) + require.Equal(t, 1, len(cfg.HasKeys([]string{esv1.XPackSecurityAuthcRealmsNativeNative1Order}))) }, }, { @@ -101,8 +102,8 @@ func TestNewMergedESConfig(t *testing.T) { }, assert: func(cfg CanonicalConfig) { require.Equal(t, 1, len(cfg.HasKeys([]string{nodeML}))) - require.Equal(t, 1, len(cfg.HasKeys([]string{estype.XPackSecurityAuthcRealmsFileFile1Order}))) - require.Equal(t, 1, len(cfg.HasKeys([]string{estype.XPackSecurityAuthcRealmsNativeNative1Order}))) + require.Equal(t, 1, len(cfg.HasKeys([]string{esv1.XPackSecurityAuthcRealmsFileFile1Order}))) + require.Equal(t, 1, len(cfg.HasKeys([]string{esv1.XPackSecurityAuthcRealmsNativeNative1Order}))) require.Equal(t, 1, len(cfg.HasKeys([]string{xPackSecurityAuthcRealmsActiveDirectoryAD1Order}))) }, }, @@ -111,8 +112,8 @@ func TestNewMergedESConfig(t *testing.T) { version: "6.8.0", cfgData: map[string]interface{}{}, assert: func(cfg CanonicalConfig) { - require.Equal(t, 1, len(cfg.HasKeys([]string{estype.DiscoveryZenHostsProvider}))) - require.Equal(t, 0, len(cfg.HasKeys([]string{estype.DiscoverySeedProviders}))) + require.Equal(t, 1, len(cfg.HasKeys([]string{esv1.DiscoveryZenHostsProvider}))) + require.Equal(t, 0, len(cfg.HasKeys([]string{esv1.DiscoverySeedProviders}))) }, }, { @@ -120,8 +121,8 @@ func TestNewMergedESConfig(t *testing.T) { version: "7.0.0", cfgData: map[string]interface{}{}, assert: func(cfg CanonicalConfig) { - require.Equal(t, 0, len(cfg.HasKeys([]string{estype.DiscoveryZenHostsProvider}))) - require.Equal(t, 1, len(cfg.HasKeys([]string{estype.DiscoverySeedProviders}))) + require.Equal(t, 0, len(cfg.HasKeys([]string{esv1.DiscoveryZenHostsProvider}))) + require.Equal(t, 1, len(cfg.HasKeys([]string{esv1.DiscoverySeedProviders}))) }, }, } @@ -132,8 +133,8 @@ func TestNewMergedESConfig(t *testing.T) { cfg, err := NewMergedESConfig( "clusterName", *ver, - v1beta1.HTTPConfig{}, - v1beta1.Config{Data: tt.cfgData}, + commonv1.HTTPConfig{}, + commonv1.Config{Data: tt.cfgData}, &certificates.CertificateResources{}, ) require.NoError(t, err) diff --git a/pkg/controller/elasticsearch/sset/fixtures.go b/pkg/controller/elasticsearch/sset/fixtures.go index 9c9439e98ec..f08cd3a9fbe 100644 --- a/pkg/controller/elasticsearch/sset/fixtures.go +++ b/pkg/controller/elasticsearch/sset/fixtures.go @@ -5,13 +5,14 @@ package sset import ( - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/hash" - "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/hash" + "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" ) type TestSset struct { @@ -130,7 +131,7 @@ func (t TestPod) Build() corev1.Pod { } status.ContainerStatuses = []corev1.ContainerStatus{ { - Name: v1beta1.ElasticsearchContainerName, + Name: esv1.ElasticsearchContainerName, RestartCount: t.RestartCount, Ready: t.Ready, }, diff --git a/pkg/controller/elasticsearch/sset/pod.go b/pkg/controller/elasticsearch/sset/pod.go index 8053b1f1f25..aa39a18c577 100644 --- a/pkg/controller/elasticsearch/sset/pod.go +++ b/pkg/controller/elasticsearch/sset/pod.go @@ -9,14 +9,15 @@ import ( "strconv" "strings" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" - "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" - "github.com/elastic/cloud-on-k8s/pkg/utils/stringsutil" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" + + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" + "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" + "github.com/elastic/cloud-on-k8s/pkg/utils/stringsutil" ) // PodName returns the name of the pod with the given ordinal for this StatefulSet. @@ -53,7 +54,7 @@ func GetActualPodsForStatefulSet(c k8s.Client, sset types.NamespacedName) ([]cor } // GetActualPodsForCluster return the existing pods associated to this cluster. -func GetActualPodsForCluster(c k8s.Client, es v1beta1.Elasticsearch) ([]corev1.Pod, error) { +func GetActualPodsForCluster(c k8s.Client, es esv1.Elasticsearch) ([]corev1.Pod, error) { var pods corev1.PodList ns := client.InNamespace(es.Namespace) @@ -67,7 +68,7 @@ func GetActualPodsForCluster(c k8s.Client, es v1beta1.Elasticsearch) ([]corev1.P } // GetActualMastersForCluster returns the list of existing master-eligible pods for the cluster. -func GetActualMastersForCluster(c k8s.Client, es v1beta1.Elasticsearch) ([]corev1.Pod, error) { +func GetActualMastersForCluster(c k8s.Client, es esv1.Elasticsearch) ([]corev1.Pod, error) { var pods corev1.PodList ns := client.InNamespace(es.Namespace) diff --git a/pkg/controller/elasticsearch/sset/pod_test.go b/pkg/controller/elasticsearch/sset/pod_test.go index e91e2131818..68ac96b9533 100644 --- a/pkg/controller/elasticsearch/sset/pod_test.go +++ b/pkg/controller/elasticsearch/sset/pod_test.go @@ -7,7 +7,7 @@ package sset import ( "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/pkg/utils/pointer" "github.com/stretchr/testify/assert" @@ -108,7 +108,7 @@ func TestGetActualMastersForCluster(t *testing.T) { } c := k8s.WrappedFakeClient(objs...) - es := v1beta1.Elasticsearch{ + es := esv1.Elasticsearch{ ObjectMeta: v1.ObjectMeta{ Name: "clus0", }, diff --git a/pkg/controller/elasticsearch/sset/reconcile.go b/pkg/controller/elasticsearch/sset/reconcile.go index a09b1a17b1a..c500e853fb2 100644 --- a/pkg/controller/elasticsearch/sset/reconcile.go +++ b/pkg/controller/elasticsearch/sset/reconcile.go @@ -5,17 +5,18 @@ package sset import ( - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + appsv1 "k8s.io/api/apps/v1" + "k8s.io/apimachinery/pkg/runtime" + + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/expectations" "github.com/elastic/cloud-on-k8s/pkg/controller/common/hash" "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" - appsv1 "k8s.io/api/apps/v1" - "k8s.io/apimachinery/pkg/runtime" ) // ReconcileStatefulSet creates or updates the expected StatefulSet. -func ReconcileStatefulSet(c k8s.Client, scheme *runtime.Scheme, es v1beta1.Elasticsearch, expected appsv1.StatefulSet, expectations *expectations.Expectations) (appsv1.StatefulSet, error) { +func ReconcileStatefulSet(c k8s.Client, scheme *runtime.Scheme, es esv1.Elasticsearch, expected appsv1.StatefulSet, expectations *expectations.Expectations) (appsv1.StatefulSet, error) { var reconciled appsv1.StatefulSet err := reconciler.ReconcileResource(reconciler.Params{ Client: c, diff --git a/pkg/controller/elasticsearch/sset/reconcile_test.go b/pkg/controller/elasticsearch/sset/reconcile_test.go index eb5b186ea95..b0df53bbf0d 100644 --- a/pkg/controller/elasticsearch/sset/reconcile_test.go +++ b/pkg/controller/elasticsearch/sset/reconcile_test.go @@ -15,7 +15,8 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes/scheme" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/expectations" "github.com/elastic/cloud-on-k8s/pkg/controller/common/hash" "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" @@ -23,7 +24,7 @@ import ( ) func TestReconcileStatefulSet(t *testing.T) { - es := v1beta1.Elasticsearch{ + es := esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Namespace: "ns", Name: "es", diff --git a/pkg/controller/elasticsearch/user/credentials.go b/pkg/controller/elasticsearch/user/credentials.go index 55d12626318..30d1e5190d5 100644 --- a/pkg/controller/elasticsearch/user/credentials.go +++ b/pkg/controller/elasticsearch/user/credentials.go @@ -10,7 +10,7 @@ import ( "sort" "strings" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" common "github.com/elastic/cloud-on-k8s/pkg/controller/common/user" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" @@ -31,17 +31,17 @@ const ( // XPackFileRealmSecretName is the name of the secret containing all users and roles information in ES format. func XPackFileRealmSecretName(ownerName string) string { - return v1beta1.XPackFileRealmSecret(ownerName) + return esv1.XPackFileRealmSecret(ownerName) } // ElasticInternalUsersSecretName is the name of the secret containing the internal users' credentials. func ElasticInternalUsersSecretName(ownerName string) string { - return v1beta1.InternalUsersSecret(ownerName) + return esv1.InternalUsersSecret(ownerName) } // ElasticExternalUsersSecretName is the name of the secret containing the external users' credentials. func ElasticExternalUsersSecretName(ownerName string) string { - return v1beta1.ElasticUserSecret(ownerName) + return esv1.ElasticUserSecret(ownerName) } // UserCredentials captures Elasticsearch user credentials and their representation in a k8s secret. diff --git a/pkg/controller/elasticsearch/user/reconciler.go b/pkg/controller/elasticsearch/user/reconciler.go index 68eeeee6f41..7cfd6454fc8 100644 --- a/pkg/controller/elasticsearch/user/reconciler.go +++ b/pkg/controller/elasticsearch/user/reconciler.go @@ -5,20 +5,21 @@ package user import ( - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/user" - "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/client" + + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/user" + "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" ) // ReconcileUserCredentialsSecret creates or updates the given credentials. func ReconcileUserCredentialsSecret( c k8s.Client, scheme *runtime.Scheme, - es v1beta1.Elasticsearch, + es esv1.Elasticsearch, creds UserCredentials, ) error { expected := creds.Secret() @@ -74,7 +75,7 @@ func aggregateAllUsers(customUsers corev1.SecretList, defaultUsers ...ClearTextC func ReconcileUsers( c k8s.Client, scheme *runtime.Scheme, - es v1beta1.Elasticsearch, + es esv1.Elasticsearch, ) (*InternalUsers, error) { nsn := k8s.ExtractNamespacedName(&es) diff --git a/pkg/controller/elasticsearch/version/zen1/compatibility.go b/pkg/controller/elasticsearch/version/zen1/compatibility.go index 6d4af0a60a3..7ea5b83ee01 100644 --- a/pkg/controller/elasticsearch/version/zen1/compatibility.go +++ b/pkg/controller/elasticsearch/version/zen1/compatibility.go @@ -5,13 +5,14 @@ package zen1 import ( - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" + + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/version" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/sset" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" - appsv1 "k8s.io/api/apps/v1" - corev1 "k8s.io/api/core/v1" ) // versionCompatibleWithZen1 returns true if the given Elasticsearch version is compatible with zen1. @@ -30,7 +31,7 @@ func IsCompatibleWithZen1(statefulSet appsv1.StatefulSet) bool { func AtLeastOneNodeCompatibleWithZen1( statefulSets sset.StatefulSetList, c k8s.Client, - es v1beta1.Elasticsearch, + es esv1.Elasticsearch, ) (bool, error) { actualMasters, err := sset.GetActualMastersForCluster(c, es) if err != nil { diff --git a/pkg/controller/elasticsearch/version/zen1/compatibility_test.go b/pkg/controller/elasticsearch/version/zen1/compatibility_test.go index b93ea133ffc..0838c435117 100644 --- a/pkg/controller/elasticsearch/version/zen1/compatibility_test.go +++ b/pkg/controller/elasticsearch/version/zen1/compatibility_test.go @@ -7,7 +7,7 @@ package zen1 import ( "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/sset" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" @@ -27,7 +27,7 @@ func createStatefulSetWithVersion(version string) appsv1.StatefulSet { }}} } -var testES = v1beta1.Elasticsearch{ +var testES = esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Name: "es1", Namespace: "default", diff --git a/pkg/controller/elasticsearch/version/zen1/minimum_masters.go b/pkg/controller/elasticsearch/version/zen1/minimum_masters.go index c2093fb5058..4ef224d3580 100644 --- a/pkg/controller/elasticsearch/version/zen1/minimum_masters.go +++ b/pkg/controller/elasticsearch/version/zen1/minimum_masters.go @@ -8,7 +8,9 @@ import ( "context" "strconv" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + logf "sigs.k8s.io/controller-runtime/pkg/log" + + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" common "github.com/elastic/cloud-on-k8s/pkg/controller/common/settings" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" @@ -16,7 +18,6 @@ import ( "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/settings" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/sset" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" - logf "sigs.k8s.io/controller-runtime/pkg/log" ) var ( @@ -32,7 +33,7 @@ const ( // This function should not be called unless all the expectations are met. func SetupMinimumMasterNodesConfig( c k8s.Client, - es v1beta1.Elasticsearch, + es esv1.Elasticsearch, nodeSpecResources nodespec.ResourcesList, ) error { // Check if we have at least one Zen1 compatible pod or StatefulSet in flight. @@ -71,7 +72,7 @@ func SetupMinimumMasterNodesConfig( // patch config with the expected minimum master nodes if err := nodeSpecResources[i].Config.MergeWith( common.MustNewSingleValue( - v1beta1.DiscoveryZenMinimumMasterNodes, + esv1.DiscoveryZenMinimumMasterNodes, strconv.Itoa(quorum), ), ); err != nil { @@ -86,7 +87,7 @@ func SetupMinimumMasterNodesConfig( // It returns true if this should be retried later (re-queued). func UpdateMinimumMasterNodes( c k8s.Client, - es v1beta1.Elasticsearch, + es esv1.Elasticsearch, esClient client.Client, actualStatefulSets sset.StatefulSetList, ) (bool, error) { @@ -131,7 +132,7 @@ func UpdateMinimumMasterNodes( // to the given value, if the cluster is using zen1. // Should only be called it there are some Zen1 compatible masters func UpdateMinimumMasterNodesTo( - es v1beta1.Elasticsearch, + es esv1.Elasticsearch, c k8s.Client, esClient client.Client, minimumMasterNodes int, @@ -156,7 +157,7 @@ func UpdateMinimumMasterNodesTo( return annotateWithMinimumMasterNodes(c, es, minimumMasterNodes) } -func minimumMasterNodesFromAnnotation(es v1beta1.Elasticsearch) int { +func minimumMasterNodesFromAnnotation(es esv1.Elasticsearch) int { annotationStr, set := es.Annotations[Zen1MiniumMasterNodesAnnotationName] if !set { return 0 @@ -169,7 +170,7 @@ func minimumMasterNodesFromAnnotation(es v1beta1.Elasticsearch) int { return mmn } -func annotateWithMinimumMasterNodes(c k8s.Client, es v1beta1.Elasticsearch, minimumMasterNodes int) error { +func annotateWithMinimumMasterNodes(c k8s.Client, es esv1.Elasticsearch, minimumMasterNodes int) error { if es.Annotations == nil { es.Annotations = make(map[string]string) } diff --git a/pkg/controller/elasticsearch/version/zen1/minimum_masters_test.go b/pkg/controller/elasticsearch/version/zen1/minimum_masters_test.go index d6d914f30ce..ad63ab2a323 100644 --- a/pkg/controller/elasticsearch/version/zen1/minimum_masters_test.go +++ b/pkg/controller/elasticsearch/version/zen1/minimum_masters_test.go @@ -8,7 +8,13 @@ import ( "context" "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + "github.com/stretchr/testify/require" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/types" + + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/scheme" settings2 "github.com/elastic/cloud-on-k8s/pkg/controller/common/settings" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" @@ -17,11 +23,6 @@ import ( "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/settings" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/sset" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" - "github.com/stretchr/testify/require" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/types" ) func TestSetupMinimumMasterNodesConfig(t *testing.T) { @@ -48,13 +49,13 @@ func TestSetupMinimumMasterNodesConfig(t *testing.T) { }, expected: []settings.CanonicalConfig{ {CanonicalConfig: settings2.MustCanonicalConfig(map[string]string{ - v1beta1.DiscoveryZenMinimumMasterNodes: "4", + esv1.DiscoveryZenMinimumMasterNodes: "4", })}, {CanonicalConfig: settings2.MustCanonicalConfig(map[string]string{ - v1beta1.DiscoveryZenMinimumMasterNodes: "4", + esv1.DiscoveryZenMinimumMasterNodes: "4", })}, {CanonicalConfig: settings2.MustCanonicalConfig(map[string]string{ - v1beta1.DiscoveryZenMinimumMasterNodes: "4", + esv1.DiscoveryZenMinimumMasterNodes: "4", })}, }, pods: []runtime.Object{}, @@ -66,7 +67,7 @@ func TestSetupMinimumMasterNodesConfig(t *testing.T) { }, expected: []settings.CanonicalConfig{ {CanonicalConfig: settings2.MustCanonicalConfig(map[string]string{ - v1beta1.DiscoveryZenMinimumMasterNodes: "2", + esv1.DiscoveryZenMinimumMasterNodes: "2", })}, settings.NewCanonicalConfig(), }, @@ -150,7 +151,7 @@ func TestUpdateMinimumMasterNodes(t *testing.T) { wantRequeue bool wantCalledWith int c k8s.Client - es v1beta1.Elasticsearch + es esv1.Elasticsearch name string actualStatefulSets sset.StatefulSetList }{ @@ -164,7 +165,7 @@ func TestUpdateMinimumMasterNodes(t *testing.T) { name: "correct mmn already set in ES annotation", c: k8s.WrappedFakeClient(&podsReady3[0], &podsReady3[1], &podsReady3[2]), actualStatefulSets: sset.StatefulSetList{ssetSample}, - es: v1beta1.Elasticsearch{ + es: esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Name: esName, Namespace: ns, @@ -179,7 +180,7 @@ func TestUpdateMinimumMasterNodes(t *testing.T) { name: "mmn should be updated, it's different in the ES annotation", c: k8s.WrappedFakeClient(&podsReady3[0], &podsReady3[1], &podsReady3[2]), actualStatefulSets: sset.StatefulSetList{ssetSample}, - es: v1beta1.Elasticsearch{ + es: esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Name: esName, Namespace: ns, @@ -195,7 +196,7 @@ func TestUpdateMinimumMasterNodes(t *testing.T) { name: "mmn should be updated, it isn't set in the ES annotation", c: k8s.WrappedFakeClient(&podsReady3[0], &podsReady3[1], &podsReady3[2]), actualStatefulSets: sset.StatefulSetList{ssetSample}, - es: v1beta1.Elasticsearch{ObjectMeta: k8s.ToObjectMeta(nsn)}, + es: esv1.Elasticsearch{ObjectMeta: k8s.ToObjectMeta(nsn)}, wantCalled: true, wantCalledWith: 2, }, @@ -203,7 +204,7 @@ func TestUpdateMinimumMasterNodes(t *testing.T) { name: "cannot update since not enough masters available", c: k8s.WrappedFakeClient(&podsReady1[0], &podsReady1[1], &podsReady1[2]), actualStatefulSets: sset.StatefulSetList{ssetSample}, - es: v1beta1.Elasticsearch{ObjectMeta: k8s.ToObjectMeta(nsn)}, + es: esv1.Elasticsearch{ObjectMeta: k8s.ToObjectMeta(nsn)}, wantCalled: false, wantRequeue: true, }, diff --git a/pkg/controller/elasticsearch/version/zen2/compatibility.go b/pkg/controller/elasticsearch/version/zen2/compatibility.go index 9cb1e1ba18a..c95567f6e34 100644 --- a/pkg/controller/elasticsearch/version/zen2/compatibility.go +++ b/pkg/controller/elasticsearch/version/zen2/compatibility.go @@ -5,7 +5,7 @@ package zen2 import ( - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/version" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/sset" @@ -26,7 +26,7 @@ func IsCompatibleWithZen2(statefulSet appsv1.StatefulSet) bool { // AllMastersCompatibleWithZen2 returns true if all master nodes in the given cluster can use zen2 APIs. // During a v6 -> v7 rolling upgrade, we can only call zen2 APIs once the current master is using v7, // which would happen only if there is no more v6 master-eligible nodes in the cluster. -func AllMastersCompatibleWithZen2(c k8s.Client, es v1beta1.Elasticsearch) (bool, error) { +func AllMastersCompatibleWithZen2(c k8s.Client, es esv1.Elasticsearch) (bool, error) { masters, err := sset.GetActualMastersForCluster(c, es) if err != nil { return false, err @@ -47,7 +47,7 @@ func AllMastersCompatibleWithZen2(c k8s.Client, es v1beta1.Elasticsearch) (bool, } // IsInitialZen2Upgrade detects whether this is an initial upgrade of a non zen2 cluster (6.x) to a zen2 compatible version (7.x +) -func IsInitialZen2Upgrade(c k8s.Client, es v1beta1.Elasticsearch) (bool, error) { +func IsInitialZen2Upgrade(c k8s.Client, es esv1.Elasticsearch) (bool, error) { newVersion, err := version.Parse(es.Spec.Version) if err != nil || !versionCompatibleWithZen2(*newVersion) { return false, err diff --git a/pkg/controller/elasticsearch/version/zen2/compatibility_test.go b/pkg/controller/elasticsearch/version/zen2/compatibility_test.go index 492cbb62905..474af0739d4 100644 --- a/pkg/controller/elasticsearch/version/zen2/compatibility_test.go +++ b/pkg/controller/elasticsearch/version/zen2/compatibility_test.go @@ -7,7 +7,7 @@ package zen2 import ( "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/sset" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" @@ -60,7 +60,7 @@ func TestIsCompatibleWithZen2(t *testing.T) { } func TestAllMastersCompatibleWithZen2(t *testing.T) { - es := v1beta1.Elasticsearch{ + es := esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Namespace: "ns", Name: "cluster", @@ -117,7 +117,7 @@ func TestAllMastersCompatibleWithZen2(t *testing.T) { func TestIsInitialZen2Upgrade(t *testing.T) { type args struct { c k8s.Client - es v1beta1.Elasticsearch + es esv1.Elasticsearch } tests := []struct { name string @@ -129,7 +129,7 @@ func TestIsInitialZen2Upgrade(t *testing.T) { name: "new 7.x", args: args{ c: k8s.WrappedFakeClient(), - es: v1beta1.Elasticsearch{Spec: v1beta1.ElasticsearchSpec{Version: "7.3.0"}}, + es: esv1.Elasticsearch{Spec: esv1.ElasticsearchSpec{Version: "7.3.0"}}, }, want: true, wantErr: false, @@ -145,8 +145,8 @@ func TestIsInitialZen2Upgrade(t *testing.T) { Version: "6.8.0", Master: true, }.BuildPtr()), - es: v1beta1.Elasticsearch{ - Spec: v1beta1.ElasticsearchSpec{Version: "7.3.0"}, + es: esv1.Elasticsearch{ + Spec: esv1.ElasticsearchSpec{Version: "7.3.0"}, }, }, want: true, @@ -163,12 +163,12 @@ func TestIsInitialZen2Upgrade(t *testing.T) { Version: "7.1.0", Master: true, }.BuildPtr()), - es: v1beta1.Elasticsearch{ + es: esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Name: "es", Namespace: "default", }, - Spec: v1beta1.ElasticsearchSpec{Version: "7.3.0"}, + Spec: esv1.ElasticsearchSpec{Version: "7.3.0"}, }, }, want: false, @@ -185,8 +185,8 @@ func TestIsInitialZen2Upgrade(t *testing.T) { Version: "6.8.0", Master: true, }.BuildPtr()), - es: v1beta1.Elasticsearch{ - Spec: v1beta1.ElasticsearchSpec{Version: "6.8.1"}, + es: esv1.Elasticsearch{ + Spec: esv1.ElasticsearchSpec{Version: "6.8.1"}, }, }, want: false, diff --git a/pkg/controller/elasticsearch/version/zen2/initial_master_nodes.go b/pkg/controller/elasticsearch/version/zen2/initial_master_nodes.go index 0bc4c178b1b..0870907331d 100644 --- a/pkg/controller/elasticsearch/version/zen2/initial_master_nodes.go +++ b/pkg/controller/elasticsearch/version/zen2/initial_master_nodes.go @@ -5,7 +5,7 @@ package zen2 import ( - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/nodespec" ) @@ -28,7 +28,7 @@ func SetupInitialMasterNodes( continue } // patch config with the expected initial master nodes - if err := nodeSpecResources[i].Config.SetStrings(v1beta1.ClusterInitialMasterNodes, masters...); err != nil { + if err := nodeSpecResources[i].Config.SetStrings(esv1.ClusterInitialMasterNodes, masters...); err != nil { return err } } diff --git a/pkg/controller/elasticsearch/version/zen2/initial_master_nodes_test.go b/pkg/controller/elasticsearch/version/zen2/initial_master_nodes_test.go index 70e4d5da3f5..ccd6ba4258f 100644 --- a/pkg/controller/elasticsearch/version/zen2/initial_master_nodes_test.go +++ b/pkg/controller/elasticsearch/version/zen2/initial_master_nodes_test.go @@ -7,7 +7,7 @@ package zen2 import ( "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" settings2 "github.com/elastic/cloud-on-k8s/pkg/controller/common/settings" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/nodespec" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/settings" @@ -37,10 +37,10 @@ func TestSetupInitialMasterNodes(t *testing.T) { }, expected: []settings.CanonicalConfig{ {CanonicalConfig: settings2.MustCanonicalConfig(map[string][]string{ - v1beta1.ClusterInitialMasterNodes: {"master-0", "master-1", "master-2", "masterdata-0", "masterdata-1", "masterdata-2"}, + esv1.ClusterInitialMasterNodes: {"master-0", "master-1", "master-2", "masterdata-0", "masterdata-1", "masterdata-2"}, })}, {CanonicalConfig: settings2.MustCanonicalConfig(map[string][]string{ - v1beta1.ClusterInitialMasterNodes: {"master-0", "master-1", "master-2", "masterdata-0", "masterdata-1", "masterdata-2"}, + esv1.ClusterInitialMasterNodes: {"master-0", "master-1", "master-2", "masterdata-0", "masterdata-1", "masterdata-2"}, })}, // no config set on non-master nodes {CanonicalConfig: settings2.NewCanonicalConfig()}, @@ -62,7 +62,7 @@ func TestSetupInitialMasterNodes(t *testing.T) { expected: []settings.CanonicalConfig{ settings.NewCanonicalConfig(), {CanonicalConfig: settings2.MustCanonicalConfig(map[string][]string{ - v1beta1.ClusterInitialMasterNodes: {"masterv6-0", "masterv6-1", "masterv6-2", "masterv7-0", "masterv7-1", "masterv7-2"}, + esv1.ClusterInitialMasterNodes: {"masterv6-0", "masterv6-1", "masterv6-2", "masterv7-0", "masterv7-1", "masterv7-2"}, })}, }, }, diff --git a/pkg/controller/elasticsearch/version/zen2/voting_exclusions.go b/pkg/controller/elasticsearch/version/zen2/voting_exclusions.go index 7b65642e734..cba29e0d678 100644 --- a/pkg/controller/elasticsearch/version/zen2/voting_exclusions.go +++ b/pkg/controller/elasticsearch/version/zen2/voting_exclusions.go @@ -9,7 +9,7 @@ import ( logf "sigs.k8s.io/controller-runtime/pkg/log" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/sset" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" @@ -20,7 +20,7 @@ var ( ) // AddToVotingConfigExclusions adds the given node names to exclude from voting config exclusions. -func AddToVotingConfigExclusions(c k8s.Client, esClient client.Client, es v1beta1.Elasticsearch, excludeNodes []string) error { +func AddToVotingConfigExclusions(c k8s.Client, esClient client.Client, es esv1.Elasticsearch, excludeNodes []string) error { compatible, err := AllMastersCompatibleWithZen2(c, es) if err != nil { return err @@ -53,7 +53,7 @@ func canClearVotingConfigExclusions(c k8s.Client, actualStatefulSets sset.Statef // ClearVotingConfigExclusions resets the voting config exclusions if all excluded nodes are properly removed. // It returns true if this should be retried later (re-queued). -func ClearVotingConfigExclusions(es v1beta1.Elasticsearch, c k8s.Client, esClient client.Client, actualStatefulSets sset.StatefulSetList) (bool, error) { +func ClearVotingConfigExclusions(es esv1.Elasticsearch, c k8s.Client, esClient client.Client, actualStatefulSets sset.StatefulSetList) (bool, error) { compatible, err := AllMastersCompatibleWithZen2(c, es) if err != nil { return false, err diff --git a/pkg/controller/elasticsearch/version/zen2/voting_exclusions_test.go b/pkg/controller/elasticsearch/version/zen2/voting_exclusions_test.go index 4e4e8c19be7..be9fc7643c3 100644 --- a/pkg/controller/elasticsearch/version/zen2/voting_exclusions_test.go +++ b/pkg/controller/elasticsearch/version/zen2/voting_exclusions_test.go @@ -8,7 +8,7 @@ import ( "context" "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/sset" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" @@ -30,7 +30,7 @@ func (f *fakeESClient) DeleteVotingConfigExclusions(ctx context.Context, waitFor func Test_ClearVotingConfigExclusions(t *testing.T) { // dummy statefulset with 3 pods statefulSet3rep := sset.TestSset{Name: "nodes", Version: "7.2.0", Replicas: 3, Master: true, Data: true}.Build() - es := v1beta1.Elasticsearch{ObjectMeta: metav1.ObjectMeta{Name: "es", Namespace: statefulSet3rep.Namespace}} + es := esv1.Elasticsearch{ObjectMeta: metav1.ObjectMeta{Name: "es", Namespace: statefulSet3rep.Namespace}} pods := make([]corev1.Pod, 0, *statefulSet3rep.Spec.Replicas) for _, podName := range sset.PodNames(statefulSet3rep) { pods = append(pods, sset.TestPod{ diff --git a/pkg/controller/kibana/certificates/reconcile.go b/pkg/controller/kibana/certificates/reconcile.go index 95c9ef746db..549815eeeda 100644 --- a/pkg/controller/kibana/certificates/reconcile.go +++ b/pkg/controller/kibana/certificates/reconcile.go @@ -7,21 +7,22 @@ package certificates import ( "time" - "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + corev1 "k8s.io/api/core/v1" + "sigs.k8s.io/controller-runtime/pkg/reconcile" + + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates/http" "github.com/elastic/cloud-on-k8s/pkg/controller/common/driver" "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/label" "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/name" - coverv1 "k8s.io/api/core/v1" - "sigs.k8s.io/controller-runtime/pkg/reconcile" ) func Reconcile( d driver.Interface, - kb v1beta1.Kibana, - services []coverv1.Service, + kb kbv1.Kibana, + services []corev1.Service, rotation certificates.RotationParams, ) *reconciler.Results { selfSignedCert := kb.Spec.HTTP.TLS.SelfSignedCertificate diff --git a/pkg/controller/kibana/config/reconciler.go b/pkg/controller/kibana/config/reconciler.go index b838f1f8261..0c5d457fc05 100644 --- a/pkg/controller/kibana/config/reconciler.go +++ b/pkg/controller/kibana/config/reconciler.go @@ -8,7 +8,7 @@ import ( "reflect" "github.com/elastic/cloud-on-k8s/pkg/about" - "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/label" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" @@ -21,7 +21,7 @@ import ( // This managed secret is mounted into each pod of the Kibana deployment. func ReconcileConfigSecret( client k8s.Client, - kb v1beta1.Kibana, + kb kbv1.Kibana, kbSettings CanonicalConfig, operatorInfo about.OperatorInfo, ) error { diff --git a/pkg/controller/kibana/config/reconciler_test.go b/pkg/controller/kibana/config/reconciler_test.go index f660dba2c7f..c18c9129b4f 100644 --- a/pkg/controller/kibana/config/reconciler_test.go +++ b/pkg/controller/kibana/config/reconciler_test.go @@ -8,7 +8,7 @@ import ( "testing" "github.com/elastic/cloud-on-k8s/pkg/about" - "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/settings" "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/label" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" @@ -20,7 +20,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -var defaultKibana = v1beta1.Kibana{ +var defaultKibana = kbv1.Kibana{ ObjectMeta: metav1.ObjectMeta{ Namespace: "test-ns", Name: "test", @@ -30,7 +30,7 @@ var defaultKibana = v1beta1.Kibana{ func TestReconcileConfigSecret(t *testing.T) { type args struct { initialObjects []runtime.Object - kb v1beta1.Kibana + kb kbv1.Kibana } tests := []struct { name string @@ -41,7 +41,7 @@ func TestReconcileConfigSecret(t *testing.T) { name: "config secret should be created", args: args{ kb: defaultKibana, - initialObjects: []runtime.Object{&v1beta1.Kibana{ + initialObjects: []runtime.Object{&kbv1.Kibana{ ObjectMeta: metav1.ObjectMeta{ Name: "test", Namespace: "test-ns", diff --git a/pkg/controller/kibana/config/secret_volume.go b/pkg/controller/kibana/config/secret_volume.go index 9df24f347f0..4d9d3bcbab8 100644 --- a/pkg/controller/kibana/config/secret_volume.go +++ b/pkg/controller/kibana/config/secret_volume.go @@ -5,7 +5,7 @@ package config import ( - "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/volume" ) @@ -16,7 +16,7 @@ const ( ) // SecretVolume returns a SecretVolume to hold the Kibana config of the given Kibana resource. -func SecretVolume(kb v1beta1.Kibana) volume.SecretVolume { +func SecretVolume(kb kbv1.Kibana) volume.SecretVolume { return volume.NewSecretVolumeWithMountPath( SecretName(kb), VolumeName, @@ -25,6 +25,6 @@ func SecretVolume(kb v1beta1.Kibana) volume.SecretVolume { } // SecretName is the name of the secret that holds the Kibana config for the given Kibana resource. -func SecretName(kb v1beta1.Kibana) string { +func SecretName(kb kbv1.Kibana) string { return kb.Name + "-kb-" + VolumeName } diff --git a/pkg/controller/kibana/config/settings.go b/pkg/controller/kibana/config/settings.go index 89a5e336a34..fb63ca930f4 100644 --- a/pkg/controller/kibana/config/settings.go +++ b/pkg/controller/kibana/config/settings.go @@ -7,8 +7,8 @@ package config import ( "path" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/association" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates/http" @@ -27,10 +27,10 @@ type CanonicalConfig struct { } // NewConfigSettings returns the Kibana configuration settings for the given Kibana resource. -func NewConfigSettings(client k8s.Client, kb v1beta1.Kibana, versionSpecificCfg *settings.CanonicalConfig) (CanonicalConfig, error) { +func NewConfigSettings(client k8s.Client, kb kbv1.Kibana, versionSpecificCfg *settings.CanonicalConfig) (CanonicalConfig, error) { specConfig := kb.Spec.Config if specConfig == nil { - specConfig = &commonv1beta1.Config{} + specConfig = &commonv1.Config{} } userSettings, err := settings.NewCanonicalConfigFrom(specConfig.Data) @@ -73,7 +73,7 @@ func NewConfigSettings(client k8s.Client, kb v1beta1.Kibana, versionSpecificCfg return CanonicalConfig{cfg}, nil } -func baseSettings(kb v1beta1.Kibana) map[string]interface{} { +func baseSettings(kb kbv1.Kibana) map[string]interface{} { return map[string]interface{}{ ServerName: kb.Name, ServerHost: "0", @@ -82,7 +82,7 @@ func baseSettings(kb v1beta1.Kibana) map[string]interface{} { } } -func kibanaTLSSettings(kb v1beta1.Kibana) map[string]interface{} { +func kibanaTLSSettings(kb kbv1.Kibana) map[string]interface{} { if !kb.Spec.HTTP.TLS.Enabled() { return nil } @@ -93,7 +93,7 @@ func kibanaTLSSettings(kb v1beta1.Kibana) map[string]interface{} { } } -func elasticsearchTLSSettings(kb v1beta1.Kibana) map[string]interface{} { +func elasticsearchTLSSettings(kb kbv1.Kibana) map[string]interface{} { cfg := map[string]interface{}{ ElasticsearchSslVerificationMode: "certificate", } diff --git a/pkg/controller/kibana/config/settings_test.go b/pkg/controller/kibana/config/settings_test.go index 0117696ea31..9d1dcd941e9 100644 --- a/pkg/controller/kibana/config/settings_test.go +++ b/pkg/controller/kibana/config/settings_test.go @@ -7,8 +7,8 @@ package config import ( "testing" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/settings" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" ucfg "github.com/elastic/go-ucfg" @@ -53,7 +53,7 @@ elasticsearch: func TestNewConfigSettings(t *testing.T) { type args struct { client k8s.Client - kb func() v1beta1.Kibana + kb func() kbv1.Kibana } tests := []struct { name string @@ -71,12 +71,12 @@ func TestNewConfigSettings(t *testing.T) { { name: "without TLS", args: args{ - kb: func() v1beta1.Kibana { + kb: func() kbv1.Kibana { kb := mkKibana() - kb.Spec = v1beta1.KibanaSpec{ - HTTP: commonv1beta1.HTTPConfig{ - TLS: commonv1beta1.TLSOptions{ - SelfSignedCertificate: &commonv1beta1.SelfSignedCertificate{ + kb.Spec = kbv1.KibanaSpec{ + HTTP: commonv1.HTTPConfig{ + TLS: commonv1.TLSOptions{ + SelfSignedCertificate: &commonv1.SelfSignedCertificate{ Disabled: true, }, }, @@ -100,12 +100,12 @@ func TestNewConfigSettings(t *testing.T) { { name: "with Association", args: args{ - kb: func() v1beta1.Kibana { + kb: func() kbv1.Kibana { kb := mkKibana() - kb.Spec = v1beta1.KibanaSpec{ - ElasticsearchRef: commonv1beta1.ObjectSelector{Name: "test-es"}, + kb.Spec = kbv1.KibanaSpec{ + ElasticsearchRef: commonv1.ObjectSelector{Name: "test-es"}, } - kb.SetAssociationConf(&commonv1beta1.AssociationConf{ + kb.SetAssociationConf(&commonv1.AssociationConf{ AuthSecretName: "auth-secret", AuthSecretKey: "elastic", CASecretName: "ca-secret", @@ -151,10 +151,10 @@ func TestNewConfigSettings(t *testing.T) { { name: "with user config", args: args{ - kb: func() v1beta1.Kibana { + kb: func() kbv1.Kibana { kb := mkKibana() - kb.Spec = v1beta1.KibanaSpec{ - Config: &commonv1beta1.Config{ + kb.Spec = kbv1.KibanaSpec{ + Config: &commonv1.Config{ Data: map[string]interface{}{ "foo": "bar", }, @@ -180,7 +180,7 @@ func TestNewConfigSettings(t *testing.T) { require.NoError(t, got.Unpack(&gotCfg)) // convert "want" into something comparable - cfg, err := uyaml.NewConfig(tt.want, commonv1beta1.CfgOptions...) + cfg, err := uyaml.NewConfig(tt.want, commonv1.CfgOptions...) require.NoError(t, err) var wantCfg map[string]interface{} require.NoError(t, cfg.Unpack(&wantCfg)) @@ -191,7 +191,7 @@ func TestNewConfigSettings(t *testing.T) { } } -func mkKibana() v1beta1.Kibana { - kb := v1beta1.Kibana{} +func mkKibana() kbv1.Kibana { + kb := kbv1.Kibana{} return kb } diff --git a/pkg/controller/kibana/driver.go b/pkg/controller/kibana/driver.go index 37d34fcb13d..d2eb149ba15 100644 --- a/pkg/controller/kibana/driver.go +++ b/pkg/controller/kibana/driver.go @@ -8,7 +8,7 @@ import ( "crypto/sha256" "fmt" - kbtype "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates/http" @@ -51,7 +51,7 @@ var initContainersParameters = keystore.InitContainerParameters{ type driver struct { client k8s.Client scheme *runtime.Scheme - settingsFactory func(kb kbtype.Kibana) map[string]interface{} + settingsFactory func(kb kbv1.Kibana) map[string]interface{} dynamicWatches watches.DynamicWatches recorder record.EventRecorder } @@ -81,7 +81,7 @@ func secretWatchKey(kibana types.NamespacedName) string { // getStrategyType decides which deployment strategy (RollingUpdate or Recreate) to use based on whether the version // upgrade is in progress. Kibana does not support a smooth rolling upgrade from one version to another: // running multiple versions simultaneously may lead to concurrency bugs and data corruption. -func (d *driver) getStrategyType(kb *kbtype.Kibana) (appsv1.DeploymentStrategyType, error) { +func (d *driver) getStrategyType(kb *kbv1.Kibana) (appsv1.DeploymentStrategyType, error) { var pods corev1.PodList var labels client.MatchingLabels = map[string]string{label.KibanaNameLabelName: kb.Name} if err := d.client.List(&pods, client.InNamespace(kb.Namespace), labels); err != nil { @@ -101,7 +101,7 @@ func (d *driver) getStrategyType(kb *kbtype.Kibana) (appsv1.DeploymentStrategyTy return appsv1.RollingUpdateDeploymentStrategyType, nil } -func (d *driver) deploymentParams(kb *kbtype.Kibana) (deployment.Params, error) { +func (d *driver) deploymentParams(kb *kbv1.Kibana) (deployment.Params, error) { // setup a keystore with secure settings in an init container, if specified by the user keystoreResources, err := keystore.NewResources( d, @@ -229,7 +229,7 @@ func (d *driver) deploymentParams(kb *kbtype.Kibana) (deployment.Params, error) func (d *driver) Reconcile( state *State, - kb *kbtype.Kibana, + kb *kbv1.Kibana, params operator.Parameters, ) *reconciler.Results { results := reconciler.Results{} diff --git a/pkg/controller/kibana/driver_test.go b/pkg/controller/kibana/driver_test.go index 2989702b82e..35ff2c3e654 100644 --- a/pkg/controller/kibana/driver_test.go +++ b/pkg/controller/kibana/driver_test.go @@ -9,17 +9,6 @@ import ( "fmt" "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - kbtype "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates/http" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/deployment" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/version" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/watches" - "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/label" - "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/pod" - "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/volume" - "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" appsv1 "k8s.io/api/apps/v1" @@ -31,6 +20,18 @@ import ( "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/tools/record" "sigs.k8s.io/controller-runtime/pkg/client" + + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates/http" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/deployment" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/version" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/watches" + "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/label" + "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/pod" + "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/volume" + "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" ) var customResourceLimits = corev1.ResourceRequirements{ @@ -209,7 +210,7 @@ func Test_getStrategyType(t *testing.T) { func TestDriverDeploymentParams(t *testing.T) { type args struct { - kb func() *kbtype.Kibana + kb func() *kbv1.Kibana initialObjects func() []runtime.Object } @@ -240,9 +241,9 @@ func TestDriverDeploymentParams(t *testing.T) { { name: "with TLS disabled", args: args{ - kb: func() *kbtype.Kibana { + kb: func() *kbv1.Kibana { kb := kibanaFixture() - kb.Spec.HTTP.TLS.SelfSignedCertificate = &v1beta1.SelfSignedCertificate{ + kb.Spec.HTTP.TLS.SelfSignedCertificate = &commonv1.SelfSignedCertificate{ Disabled: true, } return kb @@ -268,7 +269,7 @@ func TestDriverDeploymentParams(t *testing.T) { p := expectedDeploymentParams() p.PodTemplateSpec.Labels["mylabel"] = "value" for i, c := range p.PodTemplateSpec.Spec.Containers { - if c.Name == kbtype.KibanaContainerName { + if c.Name == kbv1.KibanaContainerName { p.PodTemplateSpec.Spec.Containers[i].Resources = customResourceLimits } } @@ -331,7 +332,7 @@ func TestDriverDeploymentParams(t *testing.T) { { name: "6.x is supported", args: args{ - kb: func() *kbtype.Kibana { + kb: func() *kbv1.Kibana { kb := kibanaFixture() kb.Spec.Version = "6.5.0" return kb @@ -348,7 +349,7 @@ func TestDriverDeploymentParams(t *testing.T) { { name: "6.6 docker container already defaults elasticsearch.hosts", args: args{ - kb: func() *kbtype.Kibana { + kb: func() *kbv1.Kibana { kb := kibanaFixture() kb.Spec.Version = "6.6.0" return kb @@ -467,7 +468,7 @@ func expectedDeploymentParams() deployment.Params { }, }, Image: "my-image", - Name: kbtype.KibanaContainerName, + Name: kbv1.KibanaContainerName, Ports: []corev1.ContainerPort{ {Name: "http", ContainerPort: int32(5601), Protocol: corev1.ProtocolTCP}, }, @@ -493,20 +494,20 @@ func expectedDeploymentParams() deployment.Params { } } -func kibanaFixture() *kbtype.Kibana { - kbFixture := &kbtype.Kibana{ +func kibanaFixture() *kbv1.Kibana { + kbFixture := &kbv1.Kibana{ ObjectMeta: metav1.ObjectMeta{ Name: "test", Namespace: "default", }, - Spec: kbtype.KibanaSpec{ + Spec: kbv1.KibanaSpec{ Version: "7.0.0", Image: "my-image", Count: 1, }, } - kbFixture.SetAssociationConf(&v1beta1.AssociationConf{ + kbFixture.SetAssociationConf(&commonv1.AssociationConf{ AuthSecretName: "test-auth", AuthSecretKey: "kibana-user", CASecretName: "es-ca-secret", @@ -516,7 +517,7 @@ func kibanaFixture() *kbtype.Kibana { return kbFixture } -func kibanaFixtureWithPodTemplate() *kbtype.Kibana { +func kibanaFixtureWithPodTemplate() *kbv1.Kibana { kbFixture := kibanaFixture() kbFixture.Spec.PodTemplate = corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ @@ -527,7 +528,7 @@ func kibanaFixtureWithPodTemplate() *kbtype.Kibana { Spec: corev1.PodSpec{ Containers: []corev1.Container{ { - Name: kbtype.KibanaContainerName, + Name: kbv1.KibanaContainerName, Resources: customResourceLimits, }, }, diff --git a/pkg/controller/kibana/es/secret.go b/pkg/controller/kibana/es/secret.go index 9c5a8577e2e..07ec26f6df6 100644 --- a/pkg/controller/kibana/es/secret.go +++ b/pkg/controller/kibana/es/secret.go @@ -8,7 +8,7 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" - "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/volume" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" ) @@ -16,7 +16,7 @@ import ( var eSCertsVolumeMountPath = "/usr/share/kibana/config/elasticsearch-certs" // CaCertSecretVolume returns a SecretVolume to hold the Elasticsearch CA certs for the given Kibana resource. -func CaCertSecretVolume(kb v1beta1.Kibana) volume.SecretVolume { +func CaCertSecretVolume(kb kbv1.Kibana) volume.SecretVolume { // TODO: this is a little ugly as it reaches into the ES controller bits return volume.NewSecretVolumeWithMountPath( kb.AssociationConf().GetCASecretName(), @@ -26,7 +26,7 @@ func CaCertSecretVolume(kb v1beta1.Kibana) volume.SecretVolume { } // GetAuthSecret returns the Elasticsearch auth secret for the given Kibana resource. -func GetAuthSecret(client k8s.Client, kb v1beta1.Kibana) (*corev1.Secret, error) { +func GetAuthSecret(client k8s.Client, kb kbv1.Kibana) (*corev1.Secret, error) { esAuthSecret := types.NamespacedName{ Name: kb.AssociationConf().GetAuthSecretName(), Namespace: kb.Namespace, diff --git a/pkg/controller/kibana/kibana_controller.go b/pkg/controller/kibana/kibana_controller.go index 9f5f976074b..2b4da87072d 100644 --- a/pkg/controller/kibana/kibana_controller.go +++ b/pkg/controller/kibana/kibana_controller.go @@ -8,7 +8,7 @@ import ( "reflect" "sync/atomic" - kibanav1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common" "github.com/elastic/cloud-on-k8s/pkg/controller/common/annotation" "github.com/elastic/cloud-on-k8s/pkg/controller/common/association" @@ -72,14 +72,14 @@ func add(mgr manager.Manager, r reconcile.Reconciler) (controller.Controller, er func addWatches(c controller.Controller, r *ReconcileKibana) error { // Watch for changes to Kibana - if err := c.Watch(&source.Kind{Type: &kibanav1beta1.Kibana{}}, &handler.EnqueueRequestForObject{}); err != nil { + if err := c.Watch(&source.Kind{Type: &kbv1.Kibana{}}, &handler.EnqueueRequestForObject{}); err != nil { return err } // Watch deployments if err := c.Watch(&source.Kind{Type: &appsv1.Deployment{}}, &handler.EnqueueRequestForOwner{ IsController: true, - OwnerType: &kibanav1beta1.Kibana{}, + OwnerType: &kbv1.Kibana{}, }); err != nil { return err } @@ -87,7 +87,7 @@ func addWatches(c controller.Controller, r *ReconcileKibana) error { // Watch services if err := c.Watch(&source.Kind{Type: &corev1.Service{}}, &handler.EnqueueRequestForOwner{ IsController: true, - OwnerType: &kibanav1beta1.Kibana{}, + OwnerType: &kbv1.Kibana{}, }); err != nil { return err } @@ -95,7 +95,7 @@ func addWatches(c controller.Controller, r *ReconcileKibana) error { // Watch secrets if err := c.Watch(&source.Kind{Type: &corev1.Secret{}}, &handler.EnqueueRequestForOwner{ IsController: true, - OwnerType: &kibanav1beta1.Kibana{}, + OwnerType: &kbv1.Kibana{}, }); err != nil { return err } @@ -130,7 +130,7 @@ func (r *ReconcileKibana) Reconcile(request reconcile.Request) (reconcile.Result defer common.LogReconciliationRun(log, request, &r.iteration)() // retrieve the kibana object - var kb kibanav1beta1.Kibana + var kb kbv1.Kibana if ok, err := association.FetchWithAssociation(r.Client, request, &kb); !ok { if err != nil { return reconcile.Result{}, err @@ -175,7 +175,7 @@ func (r *ReconcileKibana) Reconcile(request reconcile.Request) (reconcile.Result return r.doReconcile(request, &kb) } -func (r *ReconcileKibana) isCompatible(kb *kibanav1beta1.Kibana) (bool, error) { +func (r *ReconcileKibana) isCompatible(kb *kbv1.Kibana) (bool, error) { selector := map[string]string{label.KibanaNameLabelName: kb.Name} compat, err := annotation.ReconcileCompatibility(r.Client, kb, selector, r.params.OperatorInfo.BuildInfo.Version) if err != nil { @@ -185,7 +185,7 @@ func (r *ReconcileKibana) isCompatible(kb *kibanav1beta1.Kibana) (bool, error) { return compat, err } -func (r *ReconcileKibana) doReconcile(request reconcile.Request, kb *kibanav1beta1.Kibana) (reconcile.Result, error) { +func (r *ReconcileKibana) doReconcile(request reconcile.Request, kb *kbv1.Kibana) (reconcile.Result, error) { ver, err := version.Parse(kb.Spec.Version) if err != nil { k8s.EmitErrorEvent(r.recorder, err, kb, events.EventReasonValidation, "Invalid version '%s': %v", kb.Spec.Version, err) diff --git a/pkg/controller/kibana/pod/pod.go b/pkg/controller/kibana/pod/pod.go index c286a81bbea..2599fe96431 100644 --- a/pkg/controller/kibana/pod/pod.go +++ b/pkg/controller/kibana/pod/pod.go @@ -7,7 +7,7 @@ package pod import ( "k8s.io/apimachinery/pkg/api/resource" - "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/defaults" "github.com/elastic/cloud-on-k8s/pkg/controller/common/keystore" "github.com/elastic/cloud-on-k8s/pkg/controller/common/pod" @@ -65,11 +65,11 @@ func imageWithVersion(image string, version string) string { return stringsutil.Concat(image, ":", version) } -func NewPodTemplateSpec(kb v1beta1.Kibana, keystore *keystore.Resources) corev1.PodTemplateSpec { +func NewPodTemplateSpec(kb kbv1.Kibana, keystore *keystore.Resources) corev1.PodTemplateSpec { labels := label.NewLabels(kb.Name) labels[label.KibanaVersionLabelName] = kb.Spec.Version - builder := defaults.NewPodTemplateBuilder(kb.Spec.PodTemplate, v1beta1.KibanaContainerName). + builder := defaults.NewPodTemplateBuilder(kb.Spec.PodTemplate, kbv1.KibanaContainerName). WithResources(DefaultResources). WithLabels(labels). WithDockerImage(kb.Spec.Image, imageWithVersion(defaultImageRepositoryAndName, kb.Spec.Version)). @@ -89,5 +89,5 @@ func NewPodTemplateSpec(kb v1beta1.Kibana, keystore *keystore.Resources) corev1. // GetKibanaContainer returns the Kibana container from the given podSpec. func GetKibanaContainer(podSpec corev1.PodSpec) *corev1.Container { - return pod.ContainerByName(podSpec, v1beta1.KibanaContainerName) + return pod.ContainerByName(podSpec, kbv1.KibanaContainerName) } diff --git a/pkg/controller/kibana/pod/pod_test.go b/pkg/controller/kibana/pod/pod_test.go index c5e0beb08b7..50e2c17aff7 100644 --- a/pkg/controller/kibana/pod/pod_test.go +++ b/pkg/controller/kibana/pod/pod_test.go @@ -7,14 +7,15 @@ package pod import ( "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/keystore" - "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/label" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/keystore" + "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/label" ) func Test_imageWithVersion(t *testing.T) { @@ -47,14 +48,14 @@ func Test_imageWithVersion(t *testing.T) { func TestNewPodTemplateSpec(t *testing.T) { tests := []struct { name string - kb v1beta1.Kibana + kb kbv1.Kibana keystore *keystore.Resources assertions func(pod corev1.PodTemplateSpec) }{ { name: "defaults", - kb: v1beta1.Kibana{ - Spec: v1beta1.KibanaSpec{ + kb: kbv1.Kibana{ + Spec: kbv1.KibanaSpec{ Version: "7.1.0", }, }, @@ -74,8 +75,8 @@ func TestNewPodTemplateSpec(t *testing.T) { }, { name: "with additional volumes and init containers for the Keystore", - kb: v1beta1.Kibana{ - Spec: v1beta1.KibanaSpec{ + kb: kbv1.Kibana{ + Spec: kbv1.KibanaSpec{ Version: "7.1.0", }, }, @@ -90,7 +91,7 @@ func TestNewPodTemplateSpec(t *testing.T) { }, { name: "with custom image", - kb: v1beta1.Kibana{Spec: v1beta1.KibanaSpec{ + kb: kbv1.Kibana{Spec: kbv1.KibanaSpec{ Image: "my-custom-image:1.0.0", Version: "7.1.0", }}, @@ -101,7 +102,7 @@ func TestNewPodTemplateSpec(t *testing.T) { }, { name: "with default resources", - kb: v1beta1.Kibana{Spec: v1beta1.KibanaSpec{ + kb: kbv1.Kibana{Spec: kbv1.KibanaSpec{ Version: "7.1.0", }}, keystore: nil, @@ -111,13 +112,13 @@ func TestNewPodTemplateSpec(t *testing.T) { }, { name: "with user-provided resources", - kb: v1beta1.Kibana{Spec: v1beta1.KibanaSpec{ + kb: kbv1.Kibana{Spec: kbv1.KibanaSpec{ Version: "7.1.0", PodTemplate: corev1.PodTemplateSpec{ Spec: corev1.PodSpec{ Containers: []corev1.Container{ { - Name: v1beta1.KibanaContainerName, + Name: kbv1.KibanaContainerName, Resources: corev1.ResourceRequirements{ Limits: map[corev1.ResourceName]resource.Quantity{ corev1.ResourceMemory: resource.MustParse("3Gi"), @@ -139,7 +140,7 @@ func TestNewPodTemplateSpec(t *testing.T) { }, { name: "with user-provided init containers", - kb: v1beta1.Kibana{Spec: v1beta1.KibanaSpec{ + kb: kbv1.Kibana{Spec: kbv1.KibanaSpec{ PodTemplate: corev1.PodTemplateSpec{ Spec: corev1.PodSpec{ InitContainers: []corev1.Container{ @@ -158,11 +159,11 @@ func TestNewPodTemplateSpec(t *testing.T) { { name: "with user-provided labels", keystore: nil, - kb: v1beta1.Kibana{ + kb: kbv1.Kibana{ ObjectMeta: metav1.ObjectMeta{ Name: "kibana-name", }, - Spec: v1beta1.KibanaSpec{ + Spec: kbv1.KibanaSpec{ PodTemplate: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ @@ -185,12 +186,12 @@ func TestNewPodTemplateSpec(t *testing.T) { }, { name: "with user-provided environment", - kb: v1beta1.Kibana{Spec: v1beta1.KibanaSpec{ + kb: kbv1.Kibana{Spec: kbv1.KibanaSpec{ PodTemplate: corev1.PodTemplateSpec{ Spec: corev1.PodSpec{ Containers: []corev1.Container{ { - Name: v1beta1.KibanaContainerName, + Name: kbv1.KibanaContainerName, Env: []corev1.EnvVar{ { Name: "user-env", @@ -208,12 +209,12 @@ func TestNewPodTemplateSpec(t *testing.T) { }, { name: "with user-provided volumes and volume mounts", - kb: v1beta1.Kibana{Spec: v1beta1.KibanaSpec{ + kb: kbv1.Kibana{Spec: kbv1.KibanaSpec{ PodTemplate: corev1.PodTemplateSpec{ Spec: corev1.PodSpec{ Containers: []corev1.Container{ { - Name: v1beta1.KibanaContainerName, + Name: kbv1.KibanaContainerName, VolumeMounts: []corev1.VolumeMount{ { Name: "user-volume-mount", diff --git a/pkg/controller/kibana/services.go b/pkg/controller/kibana/services.go index 5af9d6afaaf..9b0dd6c9a1e 100644 --- a/pkg/controller/kibana/services.go +++ b/pkg/controller/kibana/services.go @@ -7,14 +7,14 @@ package kibana import ( corev1 "k8s.io/api/core/v1" - kibanav1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/defaults" "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/label" kbname "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/name" "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/pod" ) -func NewService(kb kibanav1beta1.Kibana) *corev1.Service { +func NewService(kb kbv1.Kibana) *corev1.Service { svc := corev1.Service{ ObjectMeta: kb.Spec.HTTP.Service.ObjectMeta, Spec: kb.Spec.HTTP.Service.Spec, diff --git a/pkg/controller/kibana/services_test.go b/pkg/controller/kibana/services_test.go index 6d2156e104c..767afe016ee 100644 --- a/pkg/controller/kibana/services_test.go +++ b/pkg/controller/kibana/services_test.go @@ -7,27 +7,28 @@ package kibana import ( "testing" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common" "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/label" "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/pod" "github.com/elastic/cloud-on-k8s/pkg/utils/compare" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func TestNewService(t *testing.T) { testCases := []struct { name string - httpConf commonv1beta1.HTTPConfig + httpConf commonv1.HTTPConfig wantSvc func() corev1.Service }{ { name: "no TLS", - httpConf: commonv1beta1.HTTPConfig{ - TLS: commonv1beta1.TLSOptions{ - SelfSignedCertificate: &commonv1beta1.SelfSignedCertificate{ + httpConf: commonv1.HTTPConfig{ + TLS: commonv1.TLSOptions{ + SelfSignedCertificate: &commonv1.SelfSignedCertificate{ Disabled: true, }, }, @@ -36,10 +37,10 @@ func TestNewService(t *testing.T) { }, { name: "self-signed certificate", - httpConf: commonv1beta1.HTTPConfig{ - TLS: commonv1beta1.TLSOptions{ - SelfSignedCertificate: &commonv1beta1.SelfSignedCertificate{ - SubjectAlternativeNames: []commonv1beta1.SubjectAlternativeName{ + httpConf: commonv1.HTTPConfig{ + TLS: commonv1.TLSOptions{ + SelfSignedCertificate: &commonv1.SelfSignedCertificate{ + SubjectAlternativeNames: []commonv1.SubjectAlternativeName{ { DNS: "kibana-test.local", }, @@ -55,9 +56,9 @@ func TestNewService(t *testing.T) { }, { name: "user-provided certificate", - httpConf: commonv1beta1.HTTPConfig{ - TLS: commonv1beta1.TLSOptions{ - Certificate: commonv1beta1.SecretRef{ + httpConf: commonv1.HTTPConfig{ + TLS: commonv1.TLSOptions{ + Certificate: commonv1.SecretRef{ SecretName: "my-cert", }, }, @@ -70,8 +71,8 @@ func TestNewService(t *testing.T) { }, { name: "service template", - httpConf: commonv1beta1.HTTPConfig{ - Service: commonv1beta1.ServiceTemplate{ + httpConf: commonv1.HTTPConfig{ + Service: commonv1.ServiceTemplate{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"foo": "bar"}, Annotations: map[string]string{"bar": "baz"}, @@ -123,13 +124,13 @@ func mkService() corev1.Service { } } -func mkKibana(httpConf commonv1beta1.HTTPConfig) v1beta1.Kibana { - return v1beta1.Kibana{ +func mkKibana(httpConf commonv1.HTTPConfig) kbv1.Kibana { + return kbv1.Kibana{ ObjectMeta: metav1.ObjectMeta{ Name: "kibana-test", Namespace: "test", }, - Spec: v1beta1.KibanaSpec{ + Spec: kbv1.KibanaSpec{ HTTP: httpConf, }, } diff --git a/pkg/controller/kibana/state.go b/pkg/controller/kibana/state.go index fd3d831afa9..20ce4ca4759 100644 --- a/pkg/controller/kibana/state.go +++ b/pkg/controller/kibana/state.go @@ -5,34 +5,35 @@ package kibana import ( - "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" - v1 "k8s.io/api/apps/v1" + appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "sigs.k8s.io/controller-runtime/pkg/reconcile" + + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" ) // State holds the accumulated state during the reconcile loop including the response and a pointer to a Kibana // resource for status updates. type State struct { - Kibana *v1beta1.Kibana + Kibana *kbv1.Kibana Request reconcile.Request - originalKibana *v1beta1.Kibana + originalKibana *kbv1.Kibana } // NewState creates a new reconcile state based on the given request and Kibana resource with the resource // state reset to empty. -func NewState(request reconcile.Request, kb *v1beta1.Kibana) State { +func NewState(request reconcile.Request, kb *kbv1.Kibana) State { return State{Request: request, Kibana: kb, originalKibana: kb.DeepCopy()} } // UpdateKibanaState updates the Kibana status based on the given deployment. -func (s State) UpdateKibanaState(deployment v1.Deployment) { +func (s State) UpdateKibanaState(deployment appsv1.Deployment) { s.Kibana.Status.AvailableNodes = deployment.Status.AvailableReplicas - s.Kibana.Status.Health = v1beta1.KibanaRed + s.Kibana.Status.Health = kbv1.KibanaRed for _, c := range deployment.Status.Conditions { - if c.Type == v1.DeploymentAvailable && c.Status == corev1.ConditionTrue { - s.Kibana.Status.Health = v1beta1.KibanaGreen + if c.Type == appsv1.DeploymentAvailable && c.Status == corev1.ConditionTrue { + s.Kibana.Status.Health = kbv1.KibanaGreen } } } diff --git a/pkg/controller/kibana/version/version6/settings.go b/pkg/controller/kibana/version/version6/settings.go index f10a0040190..8950e3be354 100644 --- a/pkg/controller/kibana/version/version6/settings.go +++ b/pkg/controller/kibana/version/version6/settings.go @@ -5,12 +5,12 @@ package version6 import ( - kbtype "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/config" ) // SettingsFactory returns Kibana settings for a 6.x Kibana. -func SettingsFactory(kb kbtype.Kibana) map[string]interface{} { +func SettingsFactory(kb kbv1.Kibana) map[string]interface{} { return map[string]interface{}{ config.ElasticsearchURL: kb.AssociationConf().GetURL(), } diff --git a/pkg/controller/kibana/version/version7/settings.go b/pkg/controller/kibana/version/version7/settings.go index b73505cd945..6e8d8e0cca1 100644 --- a/pkg/controller/kibana/version/version7/settings.go +++ b/pkg/controller/kibana/version/version7/settings.go @@ -5,12 +5,12 @@ package version7 import ( - kbtype "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/config" ) // SettingsFactory returns Kibana settings for a 7.x Kibana. -func SettingsFactory(kb kbtype.Kibana) map[string]interface{} { +func SettingsFactory(kb kbv1.Kibana) map[string]interface{} { return map[string]interface{}{ config.ElasticsearchHosts: kb.AssociationConf().GetURL(), } diff --git a/pkg/controller/kibanaassociation/association_controller.go b/pkg/controller/kibanaassociation/association_controller.go index 04692b1128d..e849f5f39c1 100644 --- a/pkg/controller/kibanaassociation/association_controller.go +++ b/pkg/controller/kibanaassociation/association_controller.go @@ -8,9 +8,22 @@ import ( "reflect" "time" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - estype "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - kbtype "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/errors" + apierrors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/types" + "k8s.io/client-go/tools/record" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/controller" + logf "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/manager" + "sigs.k8s.io/controller-runtime/pkg/reconcile" + + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common" "github.com/elastic/cloud-on-k8s/pkg/controller/common/annotation" "github.com/elastic/cloud-on-k8s/pkg/controller/common/association" @@ -24,18 +37,6 @@ import ( "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/label" kblabel "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/label" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/errors" - apierrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/types" - "k8s.io/client-go/tools/record" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/controller" - logf "sigs.k8s.io/controller-runtime/pkg/log" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/reconcile" ) // Kibana association controller @@ -127,7 +128,7 @@ func (r *ReconcileAssociation) onDelete(obj types.NamespacedName) error { func (r *ReconcileAssociation) Reconcile(request reconcile.Request) (reconcile.Result, error) { defer common.LogReconciliationRun(log, request, &r.iteration)() - var kibana kbtype.Kibana + var kibana kbv1.Kibana if ok, err := association.FetchWithAssociation(r.Client, request, &kibana); !ok { if err != nil { return reconcile.Result{}, err @@ -182,16 +183,16 @@ func (r *ReconcileAssociation) Reconcile(request reconcile.Request) (reconcile.R return resultFromStatus(newStatus), err } -func resultFromStatus(status commonv1beta1.AssociationStatus) reconcile.Result { +func resultFromStatus(status commonv1.AssociationStatus) reconcile.Result { switch status { - case commonv1beta1.AssociationPending: + case commonv1.AssociationPending: return defaultRequeue // retry default: return reconcile.Result{} // we are done or there is not much we can do } } -func (r *ReconcileAssociation) isCompatible(kibana *kbtype.Kibana) (bool, error) { +func (r *ReconcileAssociation) isCompatible(kibana *kbv1.Kibana) (bool, error) { selector := map[string]string{label.KibanaNameLabelName: kibana.Name} compat, err := annotation.ReconcileCompatibility(r.Client, kibana, selector, r.OperatorInfo.BuildInfo.Version) if err != nil { @@ -201,7 +202,7 @@ func (r *ReconcileAssociation) isCompatible(kibana *kbtype.Kibana) (bool, error) return compat, err } -func (r *ReconcileAssociation) reconcileInternal(kibana *kbtype.Kibana) (commonv1beta1.AssociationStatus, error) { +func (r *ReconcileAssociation) reconcileInternal(kibana *kbv1.Kibana) (commonv1.AssociationStatus, error) { kibanaKey := k8s.ExtractNamespacedName(kibana) // garbage collect leftover resources that are not required anymore @@ -213,7 +214,7 @@ func (r *ReconcileAssociation) reconcileInternal(kibana *kbtype.Kibana) (commonv // stop watching any ES cluster previously referenced for this Kibana resource r.watches.ElasticsearchClusters.RemoveHandlerForKey(elasticsearchWatchName(kibanaKey)) // other leftover resources are already garbage-collected - return commonv1beta1.AssociationUnknown, nil + return commonv1.AssociationUnknown, nil } // this Kibana instance references an Elasticsearch cluster @@ -230,7 +231,7 @@ func (r *ReconcileAssociation) reconcileInternal(kibana *kbtype.Kibana) (commonv Watched: []types.NamespacedName{esRefKey}, Watcher: kibanaKey, }); err != nil { - return commonv1beta1.AssociationFailed, err + return commonv1.AssociationFailed, err } userSecretKey := association.UserKey(kibana, kibanaUserSuffix) @@ -240,10 +241,10 @@ func (r *ReconcileAssociation) reconcileInternal(kibana *kbtype.Kibana) (commonv Watched: []types.NamespacedName{userSecretKey}, Watcher: kibanaKey, }); err != nil { - return commonv1beta1.AssociationFailed, err + return commonv1.AssociationFailed, err } - var es estype.Elasticsearch + var es esv1.Elasticsearch if err := r.Get(esRefKey, &es); err != nil { k8s.EmitErrorEvent(r.recorder, err, kibana, events.EventAssociationError, "Failed to find referenced backend %s: %v", esRefKey, err) if apierrors.IsNotFound(err) { @@ -255,12 +256,12 @@ func (r *ReconcileAssociation) reconcileInternal(kibana *kbtype.Kibana) (commonv if err := association.RemoveAssociationConf(r.Client, kibana); err != nil && !errors.IsConflict(err) { log.Error(err, "Failed to remove Elasticsearch configuration from Kibana object", "namespace", kibana.Namespace, "kibana_name", kibana.Name) - return commonv1beta1.AssociationPending, err + return commonv1.AssociationPending, err } - return commonv1beta1.AssociationPending, nil + return commonv1.AssociationPending, nil } - return commonv1beta1.AssociationFailed, err + return commonv1.AssociationFailed, err } if err := association.ReconcileEsUser( @@ -274,17 +275,17 @@ func (r *ReconcileAssociation) reconcileInternal(kibana *kbtype.Kibana) (commonv elasticsearchuser.KibanaSystemUserBuiltinRole, kibanaUserSuffix, es); err != nil { - return commonv1beta1.AssociationPending, err + return commonv1.AssociationPending, err } caSecret, err := r.reconcileElasticsearchCA(kibana, esRefKey) if err != nil { - return commonv1beta1.AssociationPending, err + return commonv1.AssociationPending, err } // construct the expected association configuration authSecret := association.ClearTextSecretKeySelector(kibana, kibanaUserSuffix) - expectedESAssoc := &commonv1beta1.AssociationConf{ + expectedESAssoc := &commonv1.AssociationConf{ AuthSecretName: authSecret.Name, AuthSecretKey: authSecret.Key, CACertProvided: caSecret.CACertProvided, @@ -297,23 +298,23 @@ func (r *ReconcileAssociation) reconcileInternal(kibana *kbtype.Kibana) (commonv log.Info("Updating Kibana spec with Elasticsearch backend configuration", "namespace", kibana.Namespace, "kibana_name", kibana.Name) if err := association.UpdateAssociationConf(r.Client, kibana, expectedESAssoc); err != nil { if errors.IsConflict(err) { - return commonv1beta1.AssociationPending, nil + return commonv1.AssociationPending, nil } log.Error(err, "Failed to update association configuration", "namespace", kibana.Namespace, "kibana_name", kibana.Name) - return commonv1beta1.AssociationPending, err + return commonv1.AssociationPending, err } kibana.SetAssociationConf(expectedESAssoc) } - return commonv1beta1.AssociationEstablished, nil + return commonv1.AssociationEstablished, nil } -func (r *ReconcileAssociation) reconcileElasticsearchCA(kibana *kbtype.Kibana, es types.NamespacedName) (association.CASecret, error) { +func (r *ReconcileAssociation) reconcileElasticsearchCA(kibana *kbv1.Kibana, es types.NamespacedName) (association.CASecret, error) { kibanaKey := k8s.ExtractNamespacedName(kibana) // watch ES CA secret to reconcile on any change if err := r.watches.Secrets.AddHandler(watches.NamedWatch{ Name: esCAWatchName(kibanaKey), - Watched: []types.NamespacedName{http.PublicCertsSecretRef(estype.ESNamer, es)}, + Watched: []types.NamespacedName{http.PublicCertsSecretRef(esv1.ESNamer, es)}, Watcher: kibanaKey, }); err != nil { return association.CASecret{}, err @@ -333,7 +334,7 @@ func (r *ReconcileAssociation) reconcileElasticsearchCA(kibana *kbtype.Kibana, e // deleteOrphanedResources deletes resources created by this association that are left over from previous reconciliation // attempts. Common use case is an Elasticsearch reference in Kibana spec that was removed. -func deleteOrphanedResources(c k8s.Client, kibana *kbtype.Kibana) error { +func deleteOrphanedResources(c k8s.Client, kibana *kbv1.Kibana) error { var secrets corev1.SecretList ns := client.InNamespace(kibana.Namespace) matchLabels := NewResourceSelector(kibana.Name) diff --git a/pkg/controller/kibanaassociation/association_controller_test.go b/pkg/controller/kibanaassociation/association_controller_test.go index 4a8d331befe..4d85549c170 100644 --- a/pkg/controller/kibanaassociation/association_controller_test.go +++ b/pkg/controller/kibanaassociation/association_controller_test.go @@ -7,10 +7,9 @@ package kibanaassociation import ( "testing" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - estype "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - kbtype "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common" "github.com/elastic/cloud-on-k8s/pkg/controller/common/association" "github.com/elastic/cloud-on-k8s/pkg/controller/common/user" @@ -27,7 +26,7 @@ const ( userSecretName = "kibana-foo-kibana-user" // nolint ) -var esFixture = estype.Elasticsearch{ +var esFixture = esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Name: "es-foo", Namespace: "default", @@ -36,7 +35,7 @@ var esFixture = estype.Elasticsearch{ } var esRefFixture = metav1.OwnerReference{ - APIVersion: "elasticsearch.k8s.elastic.co/v1beta1", + APIVersion: "elasticsearch.k8s.elastic.co/v1", Kind: "Elasticsearch", Name: "es-foo", UID: "f8d564d9-885e-11e9-896d-08002703f062", @@ -52,10 +51,10 @@ var kibanaFixtureObjectMeta = metav1.ObjectMeta{ UID: kibanaFixtureUID, } -var kibanaFixture = kbtype.Kibana{ +var kibanaFixture = kbv1.Kibana{ ObjectMeta: kibanaFixtureObjectMeta, - Spec: kbtype.KibanaSpec{ - ElasticsearchRef: commonv1beta1.ObjectSelector{ + Spec: kbv1.KibanaSpec{ + ElasticsearchRef: commonv1.ObjectSelector{ Name: esFixture.Name, Namespace: esFixture.Namespace, }, @@ -64,7 +63,7 @@ var kibanaFixture = kbtype.Kibana{ var t = true var ownerRefFixture = metav1.OwnerReference{ - APIVersion: "kibana.k8s.elastic.co/v1beta1", + APIVersion: "kibana.k8s.elastic.co/v1", Kind: "Kibana", Name: "foo", UID: kibanaFixtureUID, @@ -75,18 +74,18 @@ var ownerRefFixture = metav1.OwnerReference{ func Test_deleteOrphanedResources(t *testing.T) { tests := []struct { name string - kibana kbtype.Kibana - es v1beta1.Elasticsearch + kibana kbv1.Kibana + es esv1.Elasticsearch initialObjects []runtime.Object postCondition func(c k8s.Client) wantErr bool }{ { name: "Do not delete if there's no namespace in the ref", - kibana: kbtype.Kibana{ + kibana: kbv1.Kibana{ ObjectMeta: kibanaFixtureObjectMeta, - Spec: kbtype.KibanaSpec{ - ElasticsearchRef: commonv1beta1.ObjectSelector{ // ElasticsearchRef without a namespace + Spec: kbv1.KibanaSpec{ + ElasticsearchRef: commonv1.ObjectSelector{ // ElasticsearchRef without a namespace Name: esFixture.Name, //Namespace: esFixture.Namespace, No namespace on purpose }, @@ -132,10 +131,10 @@ func Test_deleteOrphanedResources(t *testing.T) { }, { name: "ES namespace has changed ", - kibana: kbtype.Kibana{ + kibana: kbv1.Kibana{ ObjectMeta: kibanaFixtureObjectMeta, - Spec: kbtype.KibanaSpec{ - ElasticsearchRef: commonv1beta1.ObjectSelector{ + Spec: kbv1.KibanaSpec{ + ElasticsearchRef: commonv1.ObjectSelector{ Name: esFixture.Name, Namespace: "ns2", // Kibana does not reference the default namespace anymore }, @@ -187,7 +186,7 @@ func Test_deleteOrphanedResources(t *testing.T) { }, { name: "nothing to delete", - kibana: kbtype.Kibana{}, + kibana: kbv1.Kibana{}, wantErr: false, }, { @@ -230,7 +229,7 @@ func Test_deleteOrphanedResources(t *testing.T) { }, { name: "No more es ref in Kibana, orphan user & CA for previous es ref exist", - kibana: kbtype.Kibana{ + kibana: kbv1.Kibana{ ObjectMeta: kibanaFixtureObjectMeta, }, es: esFixture, diff --git a/pkg/controller/kibanaassociation/labels.go b/pkg/controller/kibanaassociation/labels.go index 5df510956a6..88a2729cb46 100644 --- a/pkg/controller/kibanaassociation/labels.go +++ b/pkg/controller/kibanaassociation/labels.go @@ -5,12 +5,13 @@ package kibanaassociation import ( - "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/common" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/user" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" + + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/common" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/user" ) const ( @@ -27,7 +28,7 @@ func NewResourceSelector(name string) client.MatchingLabels { }) } -func hasBeenCreatedBy(object metav1.Object, kibana *v1beta1.Kibana) bool { +func hasBeenCreatedBy(object metav1.Object, kibana *kbv1.Kibana) bool { labels := object.GetLabels() if name, ok := labels[AssociationLabelName]; !ok || name != kibana.Name { return false diff --git a/pkg/controller/kibanaassociation/watch.go b/pkg/controller/kibanaassociation/watch.go index 998b767db02..a6f1942964b 100644 --- a/pkg/controller/kibanaassociation/watch.go +++ b/pkg/controller/kibanaassociation/watch.go @@ -5,8 +5,8 @@ package kibanaassociation import ( - estype "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - kbtype "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/controller" @@ -16,12 +16,12 @@ import ( func addWatches(c controller.Controller, r *ReconcileAssociation) error { // Watch for changes to Kibana resources - if err := c.Watch(&source.Kind{Type: &kbtype.Kibana{}}, &handler.EnqueueRequestForObject{}); err != nil { + if err := c.Watch(&source.Kind{Type: &kbv1.Kibana{}}, &handler.EnqueueRequestForObject{}); err != nil { return err } // Dynamically watch related Elasticsearch resources (not all ES resources) - if err := c.Watch(&source.Kind{Type: &estype.Elasticsearch{}}, r.watches.ElasticsearchClusters); err != nil { + if err := c.Watch(&source.Kind{Type: &esv1.Elasticsearch{}}, r.watches.ElasticsearchClusters); err != nil { return err } @@ -32,7 +32,7 @@ func addWatches(c controller.Controller, r *ReconcileAssociation) error { // Watch Secrets owned by a Kibana resource if err := c.Watch(&source.Kind{Type: &corev1.Secret{}}, &handler.EnqueueRequestForOwner{ - OwnerType: &kbtype.Kibana{}, + OwnerType: &kbv1.Kibana{}, IsController: true, }); err != nil { return err diff --git a/pkg/controller/license/license_controller.go b/pkg/controller/license/license_controller.go index 96979b24b72..1c0277bfbfd 100644 --- a/pkg/controller/license/license_controller.go +++ b/pkg/controller/license/license_controller.go @@ -10,15 +10,6 @@ import ( "reflect" "time" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/common" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/license" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/operator" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" - esclient "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" - "github.com/elastic/cloud-on-k8s/pkg/utils/compare" - "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" - "github.com/elastic/cloud-on-k8s/pkg/utils/maps" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -31,6 +22,17 @@ import ( "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" + + esclient "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" + "github.com/elastic/cloud-on-k8s/pkg/utils/compare" + "github.com/elastic/cloud-on-k8s/pkg/utils/maps" + + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/common" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/license" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/operator" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" + "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" ) const ( @@ -103,7 +105,7 @@ func add(mgr manager.Manager, r *ReconcileLicenses) error { // Watch for changes to Elasticsearch clusters. if err := c.Watch( - &source.Kind{Type: &v1beta1.Elasticsearch{}}, &handler.EnqueueRequestForObject{}, + &source.Kind{Type: &esv1.Elasticsearch{}}, &handler.EnqueueRequestForObject{}, ); err != nil { return err } @@ -160,11 +162,11 @@ func findLicense(c k8s.Client, checker license.Checker) (esclient.License, strin // reconcileSecret upserts a secret in the namespace of the Elasticsearch cluster containing the signature of its license. func reconcileSecret( c k8s.Client, - cluster v1beta1.Elasticsearch, + cluster esv1.Elasticsearch, parent string, esLicense esclient.License, ) error { - secretName := v1beta1.LicenseSecretName(cluster.Name) + secretName := esv1.LicenseSecretName(cluster.Name) licenseBytes, err := json.Marshal(esLicense) if err != nil { @@ -208,13 +210,13 @@ func reconcileSecret( // reconcileClusterLicense upserts a cluster license in the namespace of the given Elasticsearch cluster. // Returns time to next reconciliation, bool whether a license is configured at all and optional error. -func (r *ReconcileLicenses) reconcileClusterLicense(cluster v1beta1.Elasticsearch) (time.Time, bool, error) { +func (r *ReconcileLicenses) reconcileClusterLicense(cluster esv1.Elasticsearch) (time.Time, bool, error) { var noResult time.Time matchingSpec, parent, found := findLicense(r, r.checker) if !found { // no license, delete cluster level licenses to revert to basic log.V(1).Info("No enterprise license found. Attempting to remove cluster license secret", "namespace", cluster.Namespace, "es_name", cluster.Name) - secretName := v1beta1.LicenseSecretName(cluster.Name) + secretName := esv1.LicenseSecretName(cluster.Name) err := r.Client.Delete(&corev1.Secret{ ObjectMeta: k8s.ToObjectMeta(types.NamespacedName{ Namespace: cluster.Namespace, @@ -239,7 +241,7 @@ func (r *ReconcileLicenses) reconcileInternal(request reconcile.Request) *reconc res := &reconciler.Results{} // Fetch the cluster to ensure it still exists - cluster := v1beta1.Elasticsearch{} + cluster := esv1.Elasticsearch{} err := r.Get(request.NamespacedName, &cluster) if err != nil { if errors.IsNotFound(err) { diff --git a/pkg/controller/license/license_controller_integration_test.go b/pkg/controller/license/license_controller_integration_test.go index 7f212e92466..1820b9cc002 100644 --- a/pkg/controller/license/license_controller_integration_test.go +++ b/pkg/controller/license/license_controller_integration_test.go @@ -24,7 +24,7 @@ import ( "k8s.io/client-go/util/workqueue" "sigs.k8s.io/controller-runtime/pkg/manager" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/license" "github.com/elastic/cloud-on-k8s/pkg/controller/common/operator" esclient "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" @@ -89,14 +89,14 @@ func TestReconcile(t *testing.T) { return nil }) - cluster := &v1beta1.Elasticsearch{ + cluster := &esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Name: "foo", Namespace: "default", }, - Spec: v1beta1.ElasticsearchSpec{ + Spec: esv1.ElasticsearchSpec{ Version: "7.0.0", - NodeSets: []v1beta1.NodeSet{ + NodeSets: []esv1.NodeSet{ { Name: "all", Count: 3, @@ -109,7 +109,7 @@ func TestReconcile(t *testing.T) { // test license assignment and ownership being triggered on cluster create test.RetryUntilSuccess(t, func() error { var clusterLicense corev1.Secret - if err := c.Get(types.NamespacedName{Namespace: "default", Name: v1beta1.LicenseSecretName("foo")}, &clusterLicense); err != nil { + if err := c.Get(types.NamespacedName{Namespace: "default", Name: esv1.LicenseSecretName("foo")}, &clusterLicense); err != nil { return err } return validateOwnerRef(&clusterLicense, cluster.ObjectMeta) diff --git a/pkg/controller/license/license_controller_test.go b/pkg/controller/license/license_controller_test.go index c7f19af3703..f97f3fe76a4 100644 --- a/pkg/controller/license/license_controller_test.go +++ b/pkg/controller/license/license_controller_test.go @@ -10,7 +10,7 @@ import ( "testing" "time" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" commonlicense "github.com/elastic/cloud-on-k8s/pkg/controller/common/license" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" "github.com/elastic/cloud-on-k8s/pkg/utils/chrono" @@ -71,7 +71,7 @@ func Test_nextReconcileRelativeTo(t *testing.T) { } } -var cluster = &v1beta1.Elasticsearch{ +var cluster = &esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster", Namespace: "namespace", @@ -115,7 +115,7 @@ func enterpriseLicense(t *testing.T, licenseType commonlicense.ElasticsearchLice func TestReconcileLicenses_reconcileInternal(t *testing.T) { tests := []struct { name string - cluster *v1beta1.Elasticsearch + cluster *esv1.Elasticsearch k8sResources []runtime.Object wantErr string wantNewLicense bool @@ -194,7 +194,7 @@ func TestReconcileLicenses_reconcileInternal(t *testing.T) { // verify that a cluster license was created // following the es naming convention licenseNsn := nsn - licenseNsn.Name = v1beta1.LicenseSecretName(licenseNsn.Name) + licenseNsn.Name = esv1.LicenseSecretName(licenseNsn.Name) var license corev1.Secret err = client.Get(licenseNsn, &license) if !tt.wantNewLicense { diff --git a/pkg/controller/license/list.go b/pkg/controller/license/list.go index f76ee8fd3ce..9fbf85fd4fc 100644 --- a/pkg/controller/license/list.go +++ b/pkg/controller/license/list.go @@ -5,14 +5,15 @@ package license import ( - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/reconcile" + + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" ) func reconcileRequestsForAllClusters(c k8s.Client) ([]reconcile.Request, error) { - var clusters v1beta1.ElasticsearchList + var clusters esv1.ElasticsearchList // list all clusters err := c.List(&clusters) if err != nil { diff --git a/pkg/controller/license/list_test.go b/pkg/controller/license/list_test.go index c0f9ea83527..3699c7dcfee 100644 --- a/pkg/controller/license/list_test.go +++ b/pkg/controller/license/list_test.go @@ -8,14 +8,15 @@ import ( "reflect" "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/pkg/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/reconcile" + + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" ) type failingClient struct { @@ -46,14 +47,14 @@ func Test_listAffectedLicenses(t *testing.T) { name: "happy path", args: args{ initialObjects: []runtime.Object{ - &v1beta1.Elasticsearch{ + &esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Name: "foo-cluster", Namespace: "default", SelfLink: "/apis/elasticsearch.k8s.elastic.co/", }, }, - &v1beta1.Elasticsearch{ + &esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Name: "bar-cluster", Namespace: "default", diff --git a/test/e2e/apm/association_test.go b/test/e2e/apm/association_test.go index 9580071298a..19e80d1196f 100644 --- a/test/e2e/apm/association_test.go +++ b/test/e2e/apm/association_test.go @@ -8,8 +8,8 @@ import ( "fmt" "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1beta1" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" + apmv1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/annotation" "github.com/elastic/cloud-on-k8s/pkg/controller/common/events" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" @@ -46,7 +46,7 @@ func TestCrossNSAssociation(t *testing.T) { func TestAPMAssociationWithNonExistentES(t *testing.T) { name := "test-apm-assoc-non-existent-es" apmBuilder := apmserver.NewBuilder(name). - WithElasticsearchRef(commonv1beta1.ObjectSelector{ + WithElasticsearchRef(commonv1.ObjectSelector{ Name: "non-existent-es", }). WithNodeCount(1) @@ -90,7 +90,7 @@ func TestAPMAssociationWhenReferencedESDisappears(t *testing.T) { test.Step{ Name: "Updating to invalid Elasticsearch reference should succeed", Test: func(t *testing.T) { - var apm v1beta1.ApmServer + var apm apmv1.ApmServer require.NoError(t, k.Client.Get(k8s.ExtractNamespacedName(&apmBuilder.ApmServer), &apm)) apm.Spec.ElasticsearchRef.Namespace = "xxxx" require.NoError(t, k.Client.Update(&apm)) @@ -112,11 +112,11 @@ func TestAPMAssociationWhenReferencedESDisappears(t *testing.T) { switch { case evt.Type == corev1.EventTypeNormal && evt.Reason == events.EventAssociationStatusChange: prevStatus, currStatus := annotation.ExtractAssociationStatus(evt.ObjectMeta) - if prevStatus == commonv1beta1.AssociationEstablished && currStatus != prevStatus { + if prevStatus == commonv1.AssociationEstablished && currStatus != prevStatus { assocLostEventSeen = true } - if currStatus == commonv1beta1.AssociationEstablished { + if currStatus == commonv1.AssociationEstablished { assocEstablishedEventSeen = true } case evt.Type == corev1.EventTypeWarning && evt.Reason == events.EventAssociationError: diff --git a/test/e2e/apm/configuration_test.go b/test/e2e/apm/configuration_test.go index e8dcfd51b83..78109e0ff23 100644 --- a/test/e2e/apm/configuration_test.go +++ b/test/e2e/apm/configuration_test.go @@ -8,8 +8,8 @@ import ( "fmt" "testing" - apmtype "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1beta1" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" + apmv1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/services" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/test/e2e/test" @@ -110,9 +110,9 @@ func TestUpdateConfiguration(t *testing.T) { require.True(t, len(pods) == 1) previousPodUID = &pods[0].UID - var apm apmtype.ApmServer + var apm apmv1.ApmServer require.NoError(t, k.Client.Get(apmNamespacedName, &apm)) - apm.Spec.SecureSettings = []commonv1beta1.SecretSource{ + apm.Spec.SecureSettings = []commonv1.SecretSource{ {SecretName: secureSettingsSecretName}, } require.NoError(t, k.Client.Update(&apm)) @@ -147,9 +147,9 @@ func TestUpdateConfiguration(t *testing.T) { require.True(t, len(pods) == 1) previousPodUID = &pods[0].UID - var apm apmtype.ApmServer + var apm apmv1.ApmServer require.NoError(t, k.Client.Get(apmNamespacedName, &apm)) - customConfig := commonv1beta1.Config{ + customConfig := commonv1.Config{ Data: map[string]interface{}{"output.elasticsearch.compression_level": 1}, } apm.Spec.Config = &customConfig diff --git a/test/e2e/apm/standalone_test.go b/test/e2e/apm/standalone_test.go index b5ca5b40211..43d8d072801 100644 --- a/test/e2e/apm/standalone_test.go +++ b/test/e2e/apm/standalone_test.go @@ -7,7 +7,7 @@ package apm import ( "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" "github.com/elastic/cloud-on-k8s/test/e2e/test" "github.com/elastic/cloud-on-k8s/test/e2e/test/apmserver" ) @@ -32,9 +32,9 @@ func TestApmStandaloneNoTLS(t *testing.T) { "pretty": true, }, }). - WithHTTPCfg(v1beta1.HTTPConfig{ - TLS: v1beta1.TLSOptions{ - SelfSignedCertificate: &v1beta1.SelfSignedCertificate{ + WithHTTPCfg(commonv1.HTTPConfig{ + TLS: commonv1.TLSOptions{ + SelfSignedCertificate: &commonv1.SelfSignedCertificate{ Disabled: true, }, }, diff --git a/test/e2e/es/certs_test.go b/test/e2e/es/certs_test.go index 8264b2a222a..dc3abb79ffc 100644 --- a/test/e2e/es/certs_test.go +++ b/test/e2e/es/certs_test.go @@ -13,7 +13,7 @@ import ( "testing" "time" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" "github.com/elastic/cloud-on-k8s/pkg/dev/portforward" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" @@ -60,7 +60,7 @@ func TestUpdateHTTPCertSAN(t *testing.T) { { Name: "Add load balancer IP to the SAN", Test: func(t *testing.T) { - var currentEs v1beta1.Elasticsearch + var currentEs esv1.Elasticsearch err := k.Client.Get(k8s.ExtractNamespacedName(&b.Elasticsearch), ¤tEs) require.NoError(t, err) @@ -93,7 +93,7 @@ func getCert(k *test.K8sClient, ns string, esName string) ([]byte, error) { var secret corev1.Secret key := types.NamespacedName{ Namespace: ns, - Name: certificates.PublicSecretName(v1beta1.ESNamer, esName, certificates.HTTPCAType), + Name: certificates.PublicSecretName(esv1.ESNamer, esName, certificates.HTTPCAType), } if err := k.Client.Get(key, &secret); err != nil { return nil, err diff --git a/test/e2e/es/failure_test.go b/test/e2e/es/failure_test.go index 4abc4da35d3..aa3d3bbfec8 100644 --- a/test/e2e/es/failure_test.go +++ b/test/e2e/es/failure_test.go @@ -7,7 +7,7 @@ package es import ( "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" "github.com/elastic/cloud-on-k8s/test/e2e/test" "github.com/elastic/cloud-on-k8s/test/e2e/test/elasticsearch" @@ -68,7 +68,7 @@ func TestDeleteServices(t *testing.T) { { Name: "Delete external service", Test: func(t *testing.T) { - s, err := k.GetService(b.Elasticsearch.Namespace, v1beta1.HTTPService(b.Elasticsearch.Name)) + s, err := k.GetService(b.Elasticsearch.Namespace, esv1.HTTPService(b.Elasticsearch.Name)) require.NoError(t, err) err = k.Client.Delete(s) require.NoError(t, err) diff --git a/test/e2e/es/forced_upgrade_test.go b/test/e2e/es/forced_upgrade_test.go index 8087af32fd4..dc128c565a3 100644 --- a/test/e2e/es/forced_upgrade_test.go +++ b/test/e2e/es/forced_upgrade_test.go @@ -9,7 +9,7 @@ import ( "fmt" "testing" - estype "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" "github.com/elastic/cloud-on-k8s/test/e2e/test" @@ -43,12 +43,12 @@ func TestForceUpgradePendingPodsInOneStatefulSet(t *testing.T) { // create a cluster in which one StatefulSet is OK, // and the second one will have Pods that stay Pending forever initial := elasticsearch.NewBuilder("force-upgrade-pending-sset"). - WithNodeSet(estype.NodeSet{ + WithNodeSet(esv1.NodeSet{ Name: "ok", Count: 1, PodTemplate: elasticsearch.ESPodTemplate(elasticsearch.DefaultResources), }). - WithNodeSet(estype.NodeSet{ + WithNodeSet(esv1.NodeSet{ Name: "pending", Count: 1, PodTemplate: elasticsearch.ESPodTemplate(elasticsearch.DefaultResources), @@ -72,7 +72,7 @@ func TestForceUpgradePendingPodsInOneStatefulSet(t *testing.T) { { Name: "Wait for Pods of the first StatefulSet to be running, and second StatefulSet to be Pending", Test: test.Eventually(func() error { - pendingSset := estype.StatefulSet(initial.Elasticsearch.Name, initial.Elasticsearch.Spec.NodeSets[1].Name) + pendingSset := esv1.StatefulSet(initial.Elasticsearch.Name, initial.Elasticsearch.Spec.NodeSets[1].Name) pods, err := k.GetPods(test.ESPodListOptions(initial.Elasticsearch.Namespace, initial.Elasticsearch.Name)...) if err != nil { return err @@ -95,7 +95,7 @@ func TestForceUpgradePendingPodsInOneStatefulSet(t *testing.T) { { Name: "Wait for the ES service to have endpoints and become technically reachable", Test: test.Eventually(func() error { - endpoints, err := k.GetEndpoints(initial.Elasticsearch.Namespace, estype.HTTPService(initial.Elasticsearch.Name)) + endpoints, err := k.GetEndpoints(initial.Elasticsearch.Namespace, esv1.HTTPService(initial.Elasticsearch.Name)) if err != nil { return err } @@ -135,7 +135,7 @@ func TestForceUpgradeBootloopingPods(t *testing.T) { "Pods should have restarted at least once due to wrong ES config", func(p corev1.Pod) error { for _, containerStatus := range p.Status.ContainerStatuses { - if containerStatus.Name != estype.ElasticsearchContainerName { + if containerStatus.Name != esv1.ElasticsearchContainerName { continue } if containerStatus.RestartCount < 1 { @@ -143,7 +143,7 @@ func TestForceUpgradeBootloopingPods(t *testing.T) { } return nil } - return fmt.Errorf("container %s not found in pod %s", estype.ElasticsearchContainerName, p.Name) + return fmt.Errorf("container %s not found in pod %s", esv1.ElasticsearchContainerName, p.Name) }, ), }, diff --git a/test/e2e/es/keystore_test.go b/test/e2e/es/keystore_test.go index a142a806b51..e996c14f670 100644 --- a/test/e2e/es/keystore_test.go +++ b/test/e2e/es/keystore_test.go @@ -7,7 +7,7 @@ package es import ( "testing" - estype "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/test/e2e/test" "github.com/elastic/cloud-on-k8s/test/e2e/test/elasticsearch" @@ -110,7 +110,7 @@ func TestUpdateESSecureSettings(t *testing.T) { Name: "Remove secure settings from the spec", Test: func(t *testing.T) { // retrieve current Elasticsearch resource - var currentEs estype.Elasticsearch + var currentEs esv1.Elasticsearch err := k.Client.Get(k8s.ExtractNamespacedName(&b.Elasticsearch), ¤tEs) require.NoError(t, err) // set its secure settings to nil diff --git a/test/e2e/es/naming_test.go b/test/e2e/es/naming_test.go index 8d63c046fb6..7f71f6a8d75 100644 --- a/test/e2e/es/naming_test.go +++ b/test/e2e/es/naming_test.go @@ -21,7 +21,7 @@ import ( "k8s.io/apimachinery/pkg/util/rand" "k8s.io/apimachinery/pkg/util/validation" - estype "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/name" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" ) @@ -51,7 +51,7 @@ func testLongestPossibleName(t *testing.T) { WithESMasterDataNodes(3, elasticsearch.DefaultResources). WithNamespace(test.Ctx().ManagedNamespace(0)). WithVersion(test.Ctx().ElasticStackVersion). - WithNodeSet(estype.NodeSet{ + WithNodeSet(esv1.NodeSet{ Name: nodeSpecName, Count: 1, }). @@ -88,7 +88,7 @@ func testRejectionOfLongName(t *testing.T) { WithESMasterDataNodes(1, elasticsearch.DefaultResources). WithNamespace(test.Ctx().ManagedNamespace(0)). WithVersion(test.Ctx().ElasticStackVersion). - WithNodeSet(estype.NodeSet{ + WithNodeSet(esv1.NodeSet{ Name: "default", Count: 1, }). @@ -111,13 +111,13 @@ func testRejectionOfLongName(t *testing.T) { // if the validating webhook is not active, operator's own validation check should set the object phase to "Invalid" objectCreated = true test.Eventually(func() error { - var createdES estype.Elasticsearch + var createdES esv1.Elasticsearch if err := k.Client.Get(k8s.ExtractNamespacedName(&esBuilder.Elasticsearch), &createdES); err != nil { return err } - if createdES.Status.Phase != estype.ElasticsearchResourceInvalid { - return fmt.Errorf("expected phase=[%s], actual phase=[%s]", estype.ElasticsearchResourceInvalid, createdES.Status.Phase) + if createdES.Status.Phase != esv1.ElasticsearchResourceInvalid { + return fmt.Errorf("expected phase=[%s], actual phase=[%s]", esv1.ElasticsearchResourceInvalid, createdES.Status.Phase) } return nil }) @@ -138,7 +138,7 @@ func testRejectionOfLongName(t *testing.T) { } test.Eventually(func() error { - var createdES estype.Elasticsearch + var createdES esv1.Elasticsearch err := k.Client.Get(k8s.ExtractNamespacedName(&esBuilder.Elasticsearch), &createdES) if apierrors.IsNotFound(err) { return nil diff --git a/test/e2e/es/podtemplate_test.go b/test/e2e/es/podtemplate_test.go index 69729ef4771..e1104cc9b83 100644 --- a/test/e2e/es/podtemplate_test.go +++ b/test/e2e/es/podtemplate_test.go @@ -11,7 +11,7 @@ import ( "net/http" "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" "github.com/elastic/cloud-on-k8s/test/e2e/test" "github.com/elastic/cloud-on-k8s/test/e2e/test/elasticsearch" @@ -50,7 +50,7 @@ func TestCustomConfiguration(t *testing.T) { }, Containers: []corev1.Container{ { - Name: v1beta1.ElasticsearchContainerName, + Name: esv1.ElasticsearchContainerName, Resources: elasticsearch.DefaultResources, VolumeMounts: []corev1.VolumeMount{ { diff --git a/test/e2e/es/reversal_test.go b/test/e2e/es/reversal_test.go index 31c513ee963..f5d2d14fcb7 100644 --- a/test/e2e/es/reversal_test.go +++ b/test/e2e/es/reversal_test.go @@ -7,8 +7,8 @@ package es import ( "testing" - common "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/test/e2e/test" "github.com/elastic/cloud-on-k8s/test/e2e/test/elasticsearch" ) @@ -57,13 +57,13 @@ func TestReversalStatefulSetRename(t *testing.T) { func TestRiskyMasterReconfiguration(t *testing.T) { b := elasticsearch.NewBuilder("test-sset-reconfig-reversal"). WithESMasterDataNodes(1, elasticsearch.DefaultResources). - WithNodeSet(v1beta1.NodeSet{ + WithNodeSet(esv1.NodeSet{ Name: "other-master", Count: 1, - Config: &common.Config{ + Config: &commonv1.Config{ Data: map[string]interface{}{ - v1beta1.NodeMaster: true, - v1beta1.NodeData: true, + esv1.NodeMaster: true, + esv1.NodeData: true, }, }, PodTemplate: elasticsearch.ESPodTemplate(elasticsearch.DefaultResources), @@ -71,13 +71,13 @@ func TestRiskyMasterReconfiguration(t *testing.T) { // this currently breaks the cluster (something we might fix in the future at which point this just tests a temp downscale) noMasterMaster := b.WithNoESTopology().WithESMasterDataNodes(1, elasticsearch.DefaultResources). - WithNodeSet(v1beta1.NodeSet{ + WithNodeSet(esv1.NodeSet{ Name: "other-master", Count: 1, - Config: &common.Config{ + Config: &commonv1.Config{ Data: map[string]interface{}{ - v1beta1.NodeMaster: false, - v1beta1.NodeData: true, + esv1.NodeMaster: false, + esv1.NodeData: true, }, }, PodTemplate: elasticsearch.ESPodTemplate(elasticsearch.DefaultResources), diff --git a/test/e2e/kb/association_test.go b/test/e2e/kb/association_test.go index 661174a3af9..55885b3bfb9 100644 --- a/test/e2e/kb/association_test.go +++ b/test/e2e/kb/association_test.go @@ -8,8 +8,8 @@ import ( "fmt" "testing" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/annotation" "github.com/elastic/cloud-on-k8s/pkg/controller/common/events" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" @@ -42,7 +42,7 @@ func TestCrossNSAssociation(t *testing.T) { func TestKibanaAssociationWithNonExistentES(t *testing.T) { name := "test-kb-assoc-non-existent-es" kbBuilder := kibana.NewBuilder(name). - WithElasticsearchRef(commonv1beta1.ObjectSelector{Name: "some-es"}). + WithElasticsearchRef(commonv1.ObjectSelector{Name: "some-es"}). WithNodeCount(1) k := test.NewK8sClientOrFatal() @@ -84,7 +84,7 @@ func TestKibanaAssociationWhenReferencedESDisappears(t *testing.T) { test.Step{ Name: "Updating to invalid Elasticsearch reference should succeed", Test: func(t *testing.T) { - var kb v1beta1.Kibana + var kb kbv1.Kibana require.NoError(t, k.Client.Get(k8s.ExtractNamespacedName(&kbBuilder.Kibana), &kb)) kb.Spec.ElasticsearchRef.Namespace = "xxxx" require.NoError(t, k.Client.Update(&kb)) @@ -106,11 +106,11 @@ func TestKibanaAssociationWhenReferencedESDisappears(t *testing.T) { switch { case evt.Type == corev1.EventTypeNormal && evt.Reason == events.EventAssociationStatusChange: prevStatus, currStatus := annotation.ExtractAssociationStatus(evt.ObjectMeta) - if prevStatus == commonv1beta1.AssociationEstablished && currStatus != prevStatus { + if prevStatus == commonv1.AssociationEstablished && currStatus != prevStatus { assocLostEventSeen = true } - if currStatus == commonv1beta1.AssociationEstablished { + if currStatus == commonv1.AssociationEstablished { assocEstablishedEventSeen = true } case evt.Type == corev1.EventTypeWarning && evt.Reason == events.EventAssociationError: diff --git a/test/e2e/kb/keystore_test.go b/test/e2e/kb/keystore_test.go index 5ac9baf5259..a555dd0ed65 100644 --- a/test/e2e/kb/keystore_test.go +++ b/test/e2e/kb/keystore_test.go @@ -7,7 +7,7 @@ package kb import ( "testing" - kbtype "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/test/e2e/test" "github.com/elastic/cloud-on-k8s/test/e2e/test/elasticsearch" @@ -88,7 +88,7 @@ func TestUpdateKibanaSecureSettings(t *testing.T) { Name: "Remove secure settings from the spec", Test: func(t *testing.T) { // retrieve current Kibana resource - var currentKb kbtype.Kibana + var currentKb kbv1.Kibana err := k.Client.Get(k8s.ExtractNamespacedName(&kbBuilder.Kibana), ¤tKb) require.NoError(t, err) // set its secure settings to nil diff --git a/test/e2e/kb/testdata/kibana_standalone.yaml b/test/e2e/kb/testdata/kibana_standalone.yaml index 596014f0d8c..bbbdeea4cd0 100644 --- a/test/e2e/kb/testdata/kibana_standalone.yaml +++ b/test/e2e/kb/testdata/kibana_standalone.yaml @@ -1,5 +1,5 @@ --- -apiVersion: elasticsearch.k8s.elastic.co/v1beta1 +apiVersion: elasticsearch.k8s.elastic.co/v1 kind: Elasticsearch metadata: name: test-kibana-standalone-es-{{ .Suffix }} @@ -13,7 +13,7 @@ spec: node.data: true node.store.allow_mmap: false --- -apiVersion: kibana.k8s.elastic.co/v1beta1 +apiVersion: kibana.k8s.elastic.co/v1 kind: Kibana metadata: name: test-kibana-standalone-{{ .Suffix }} diff --git a/test/e2e/samples_test.go b/test/e2e/samples_test.go index 538ce0514ba..8e4b27fd93c 100644 --- a/test/e2e/samples_test.go +++ b/test/e2e/samples_test.go @@ -11,7 +11,7 @@ import ( "strings" "testing" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" "github.com/elastic/cloud-on-k8s/test/e2e/test" "github.com/elastic/cloud-on-k8s/test/e2e/test/apmserver" "github.com/elastic/cloud-on-k8s/test/e2e/test/elasticsearch" @@ -80,7 +80,7 @@ func createBuilders(t *testing.T, decoder *helper.YAMLDecoder, sampleFile string return builders } -func tweakElasticsearchRef(ref commonv1beta1.ObjectSelector, suffix string) commonv1beta1.ObjectSelector { +func tweakElasticsearchRef(ref commonv1.ObjectSelector, suffix string) commonv1.ObjectSelector { // All the objects defined in the YAML file will have a random test suffix added to prevent clashes with previous runs. // This necessitates changing the Elasticsearch reference to match the suffixed name. if ref.Name != "" { diff --git a/test/e2e/test/apmserver/builder.go b/test/e2e/test/apmserver/builder.go index 1cda7d20fd0..cc5e6952155 100644 --- a/test/e2e/test/apmserver/builder.go +++ b/test/e2e/test/apmserver/builder.go @@ -5,8 +5,8 @@ package apmserver import ( - apmtype "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1beta1" - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" + apmv1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1" + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" "github.com/elastic/cloud-on-k8s/test/e2e/test" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -16,7 +16,7 @@ import ( // Builder to create APM Servers type Builder struct { - ApmServer apmtype.ApmServer + ApmServer apmv1.ApmServer } var _ test.Builder = Builder{} @@ -35,12 +35,12 @@ func newBuilder(name, randSuffix string) Builder { Namespace: test.Ctx().ManagedNamespace(0), } return Builder{ - ApmServer: apmtype.ApmServer{ + ApmServer: apmv1.ApmServer{ ObjectMeta: meta, - Spec: apmtype.ApmServerSpec{ + Spec: apmv1.ApmServerSpec{ Count: 1, Version: test.Ctx().ElasticStackVersion, - Config: &commonv1beta1.Config{ + Config: &commonv1.Config{ Data: map[string]interface{}{ "apm-server.ilm.enabled": false, }, @@ -82,14 +82,14 @@ func (b Builder) WithNodeCount(count int) Builder { return b } -func (b Builder) WithElasticsearchRef(ref commonv1beta1.ObjectSelector) Builder { +func (b Builder) WithElasticsearchRef(ref commonv1.ObjectSelector) Builder { b.ApmServer.Spec.ElasticsearchRef = ref return b } func (b Builder) WithConfig(cfg map[string]interface{}) Builder { if b.ApmServer.Spec.Config == nil || b.ApmServer.Spec.Config.Data == nil { - b.ApmServer.Spec.Config = &commonv1beta1.Config{ + b.ApmServer.Spec.Config = &commonv1.Config{ Data: cfg, } return b @@ -101,7 +101,7 @@ func (b Builder) WithConfig(cfg map[string]interface{}) Builder { return b } -func (b Builder) WithHTTPCfg(cfg commonv1beta1.HTTPConfig) Builder { +func (b Builder) WithHTTPCfg(cfg commonv1.HTTPConfig) Builder { b.ApmServer.Spec.HTTP = cfg return b } diff --git a/test/e2e/test/apmserver/checks_apm.go b/test/e2e/test/apmserver/checks_apm.go index 3c6f51dc2c0..29b5a33adf7 100644 --- a/test/e2e/test/apmserver/checks_apm.go +++ b/test/e2e/test/apmserver/checks_apm.go @@ -13,8 +13,8 @@ import ( "strings" "testing" - apmtype "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + apmv1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/test/e2e/test" @@ -40,7 +40,7 @@ func (b Builder) CheckStackTestSteps(k *test.K8sClient) test.StepList { } } -func (c *apmClusterChecks) BuildApmServerClient(apm apmtype.ApmServer, k *test.K8sClient, +func (c *apmClusterChecks) BuildApmServerClient(apm apmv1.ApmServer, k *test.K8sClient, ) test.Step { return test.Step{ Name: "Every secret should be set so that we can build an APM client", @@ -48,7 +48,7 @@ func (c *apmClusterChecks) BuildApmServerClient(apm apmtype.ApmServer, k *test.K test.Eventually(func() error { // fetch the latest APM Server resource from the API because we need to get resources that are provided // by the controller apm part of the status section - var updatedApmServer apmtype.ApmServer + var updatedApmServer apmv1.ApmServer if err := k.Client.Get(k8s.ExtractNamespacedName(&apm), &updatedApmServer); err != nil { return err } @@ -65,7 +65,7 @@ func (c *apmClusterChecks) BuildApmServerClient(apm apmtype.ApmServer, k *test.K } // We assume here that the Elasticsearch object has been created before the APM Server. - var es v1beta1.Elasticsearch + var es esv1.Elasticsearch namespace := apm.Spec.ElasticsearchRef.Namespace if len(namespace) == 0 { namespace = apm.Namespace @@ -98,7 +98,7 @@ func (c *apmClusterChecks) CheckApmServerReachable() test.Step { } } -func (c *apmClusterChecks) CheckApmServerVersion(apm apmtype.ApmServer) test.Step { +func (c *apmClusterChecks) CheckApmServerVersion(apm apmv1.ApmServer) test.Step { return test.Step{ Name: "ApmServer version should be the expected one", Test: func(t *testing.T) { @@ -149,12 +149,12 @@ type CountResult struct { // CheckEventsInElasticsearch checks that the events sent in the previous step have been stored. // We only count document to not rely on the internal schema of the APM Server. -func (c *apmClusterChecks) CheckEventsInElasticsearch(apm apmtype.ApmServer, k *test.K8sClient) test.Step { +func (c *apmClusterChecks) CheckEventsInElasticsearch(apm apmv1.ApmServer, k *test.K8sClient) test.Step { return test.Step{ Name: "Events should eventually show up in Elasticsearch", Test: test.Eventually(func() error { // Fetch the last version of the APM Server - var updatedApmServer apmtype.ApmServer + var updatedApmServer apmv1.ApmServer if err := k.Client.Get(k8s.ExtractNamespacedName(&apm), &updatedApmServer); err != nil { return err } diff --git a/test/e2e/test/apmserver/http_client.go b/test/e2e/test/apmserver/http_client.go index c4e7fd8a5ba..46284162de9 100644 --- a/test/e2e/test/apmserver/http_client.go +++ b/test/e2e/test/apmserver/http_client.go @@ -15,7 +15,7 @@ import ( "strings" "time" - apmtype "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1beta1" + apmv1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/apmserver" "github.com/elastic/cloud-on-k8s/pkg/controller/apmserver/config" "github.com/elastic/cloud-on-k8s/pkg/controller/apmserver/name" @@ -35,7 +35,7 @@ type ApmClient struct { authorizationHeaderValue string } -func NewApmServerClient(as apmtype.ApmServer, k *test.K8sClient) (*ApmClient, error) { +func NewApmServerClient(as apmv1.ApmServer, k *test.K8sClient) (*ApmClient, error) { var secretTokenSecret v1.Secret secretTokenNamespacedName := types.NamespacedName{Namespace: as.Namespace, Name: as.Status.SecretTokenSecretName} if err := k.Client.Get(secretTokenNamespacedName, &secretTokenSecret); err != nil { diff --git a/test/e2e/test/apmserver/steps_creation.go b/test/e2e/test/apmserver/steps_creation.go index f18db1ab0d1..3467287d2fc 100644 --- a/test/e2e/test/apmserver/steps_creation.go +++ b/test/e2e/test/apmserver/steps_creation.go @@ -7,7 +7,7 @@ package apmserver import ( "testing" - apmtype "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1beta1" + apmv1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/test/e2e/test" "github.com/stretchr/testify/require" @@ -28,7 +28,7 @@ func (b Builder) CreationTestSteps(k *test.K8sClient) test.StepList { { Name: "APM Server should be created", Test: func(t *testing.T) { - var createdApmServer apmtype.ApmServer + var createdApmServer apmv1.ApmServer err := k.Client.Get(k8s.ExtractNamespacedName(&b.ApmServer), &createdApmServer) require.NoError(t, err) require.Equal(t, b.ApmServer.Spec.Version, createdApmServer.Spec.Version) diff --git a/test/e2e/test/apmserver/steps_init.go b/test/e2e/test/apmserver/steps_init.go index ee792a706c2..d364da76252 100644 --- a/test/e2e/test/apmserver/steps_init.go +++ b/test/e2e/test/apmserver/steps_init.go @@ -7,7 +7,7 @@ package apmserver import ( "testing" - apmtype "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1beta1" + apmv1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1" "github.com/elastic/cloud-on-k8s/test/e2e/test" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" @@ -28,7 +28,7 @@ func (b Builder) InitTestSteps(k *test.K8sClient) test.StepList { { Name: "APM Server CRDs should exist", Test: func(t *testing.T) { - err := k.Client.List(&apmtype.ApmServerList{}) + err := k.Client.List(&apmv1.ApmServerList{}) require.NoError(t, err) }, }, diff --git a/test/e2e/test/elasticsearch/builder.go b/test/e2e/test/elasticsearch/builder.go index cbb1ef04f26..ed4ccf6759d 100644 --- a/test/e2e/test/elasticsearch/builder.go +++ b/test/e2e/test/elasticsearch/builder.go @@ -5,16 +5,17 @@ package elasticsearch import ( - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - estype "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/volume" - "github.com/elastic/cloud-on-k8s/pkg/utils/pointer" - "github.com/elastic/cloud-on-k8s/test/e2e/test" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/rand" + + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/volume" + "github.com/elastic/cloud-on-k8s/pkg/utils/pointer" + "github.com/elastic/cloud-on-k8s/test/e2e/test" ) const ( @@ -29,7 +30,7 @@ func ESPodTemplate(resources corev1.ResourceRequirements) corev1.PodTemplateSpec SecurityContext: test.DefaultSecurityContext(), Containers: []corev1.Container{ { - Name: estype.ElasticsearchContainerName, + Name: esv1.ElasticsearchContainerName, Resources: resources, }, }, @@ -39,7 +40,7 @@ func ESPodTemplate(resources corev1.ResourceRequirements) corev1.PodTemplateSpec // Builder to create Elasticsearch clusters type Builder struct { - Elasticsearch estype.Elasticsearch + Elasticsearch esv1.Elasticsearch MutatedFrom *Builder } @@ -59,9 +60,9 @@ func newBuilder(name, randSuffix string) Builder { Namespace: test.Ctx().ManagedNamespace(0), } return Builder{ - Elasticsearch: estype.Elasticsearch{ + Elasticsearch: esv1.Elasticsearch{ ObjectMeta: meta, - Spec: estype.ElasticsearchSpec{ + Spec: esv1.ElasticsearchSpec{ Version: test.Ctx().ElasticStackVersion, }, }, @@ -75,8 +76,8 @@ func (b Builder) WithSuffix(suffix string) Builder { return b } -func (b Builder) Ref() commonv1beta1.ObjectSelector { - return commonv1beta1.ObjectSelector{ +func (b Builder) Ref() commonv1.ObjectSelector { + return commonv1.ObjectSelector{ Name: b.Elasticsearch.Name, Namespace: b.Elasticsearch.Namespace, } @@ -108,7 +109,7 @@ func (b Builder) WithHTTPLoadBalancer() Builder { func (b Builder) WithTLSDisabled(disabled bool) Builder { if b.Elasticsearch.Spec.HTTP.TLS.SelfSignedCertificate == nil { - b.Elasticsearch.Spec.HTTP.TLS.SelfSignedCertificate = &commonv1beta1.SelfSignedCertificate{} + b.Elasticsearch.Spec.HTTP.TLS.SelfSignedCertificate = &commonv1.SelfSignedCertificate{} } else { b.Elasticsearch.Spec.HTTP.TLS.SelfSignedCertificate = b.Elasticsearch.Spec.HTTP.TLS.SelfSignedCertificate.DeepCopy() } @@ -117,8 +118,8 @@ func (b Builder) WithTLSDisabled(disabled bool) Builder { } func (b Builder) WithHTTPSAN(ip string) Builder { - b.Elasticsearch.Spec.HTTP.TLS.SelfSignedCertificate = &commonv1beta1.SelfSignedCertificate{ - SubjectAlternativeNames: []commonv1beta1.SubjectAlternativeName{{IP: ip}}, + b.Elasticsearch.Spec.HTTP.TLS.SelfSignedCertificate = &commonv1.SelfSignedCertificate{ + SubjectAlternativeNames: []commonv1.SubjectAlternativeName{{IP: ip}}, } return b } @@ -126,17 +127,17 @@ func (b Builder) WithHTTPSAN(ip string) Builder { // -- ES Nodes func (b Builder) WithNoESTopology() Builder { - b.Elasticsearch.Spec.NodeSets = []estype.NodeSet{} + b.Elasticsearch.Spec.NodeSets = []esv1.NodeSet{} return b } func (b Builder) WithESMasterNodes(count int, resources corev1.ResourceRequirements) Builder { - return b.WithNodeSet(estype.NodeSet{ + return b.WithNodeSet(esv1.NodeSet{ Name: "master", Count: int32(count), - Config: &commonv1beta1.Config{ + Config: &commonv1.Config{ Data: map[string]interface{}{ - estype.NodeData: "false", + esv1.NodeData: "false", }, }, PodTemplate: ESPodTemplate(resources), @@ -144,12 +145,12 @@ func (b Builder) WithESMasterNodes(count int, resources corev1.ResourceRequireme } func (b Builder) WithESDataNodes(count int, resources corev1.ResourceRequirements) Builder { - return b.WithNodeSet(estype.NodeSet{ + return b.WithNodeSet(esv1.NodeSet{ Name: "data", Count: int32(count), - Config: &commonv1beta1.Config{ + Config: &commonv1.Config{ Data: map[string]interface{}{ - estype.NodeMaster: "false", + esv1.NodeMaster: "false", }, }, PodTemplate: ESPodTemplate(resources), @@ -157,12 +158,12 @@ func (b Builder) WithESDataNodes(count int, resources corev1.ResourceRequirement } func (b Builder) WithNamedESDataNodes(count int, name string, resources corev1.ResourceRequirements) Builder { - return b.WithNodeSet(estype.NodeSet{ + return b.WithNodeSet(esv1.NodeSet{ Name: name, Count: int32(count), - Config: &commonv1beta1.Config{ + Config: &commonv1.Config{ Data: map[string]interface{}{ - estype.NodeMaster: "false", + esv1.NodeMaster: "false", }, }, PodTemplate: ESPodTemplate(resources), @@ -170,18 +171,18 @@ func (b Builder) WithNamedESDataNodes(count int, name string, resources corev1.R } func (b Builder) WithESMasterDataNodes(count int, resources corev1.ResourceRequirements) Builder { - return b.WithNodeSet(estype.NodeSet{ + return b.WithNodeSet(esv1.NodeSet{ Name: "masterdata", Count: int32(count), PodTemplate: ESPodTemplate(resources), }) } -func (b Builder) WithNodeSet(nodeSet estype.NodeSet) Builder { +func (b Builder) WithNodeSet(nodeSet esv1.NodeSet) Builder { // Make sure the config specifies "node.store.allow_mmap: false". // We disable mmap to avoid having to set the vm.max_map_count sysctl on test k8s nodes. if nodeSet.Config == nil { - nodeSet.Config = &commonv1beta1.Config{Data: map[string]interface{}{}} + nodeSet.Config = &commonv1.Config{Data: map[string]interface{}{}} } nodeSet.Config.Data["node.store.allow_mmap"] = false b.Elasticsearch.Spec.NodeSets = append(b.Elasticsearch.Spec.NodeSets, nodeSet) @@ -189,9 +190,9 @@ func (b Builder) WithNodeSet(nodeSet estype.NodeSet) Builder { } func (b Builder) WithESSecureSettings(secretNames ...string) Builder { - refs := make([]commonv1beta1.SecretSource, 0, len(secretNames)) + refs := make([]commonv1.SecretSource, 0, len(secretNames)) for i := range secretNames { - refs = append(refs, commonv1beta1.SecretSource{SecretName: secretNames[i]}) + refs = append(refs, commonv1.SecretSource{SecretName: secretNames[i]}) } b.Elasticsearch.Spec.SecureSettings = refs return b @@ -256,7 +257,7 @@ func (b Builder) WithPodTemplate(pt corev1.PodTemplateSpec) Builder { } func (b Builder) WithAdditionalConfig(nodeSetCfg map[string]map[string]interface{}) Builder { - var newNodeSets []estype.NodeSet + var newNodeSets []esv1.NodeSet for nodeSetName, cfg := range nodeSetCfg { for _, n := range b.Elasticsearch.Spec.NodeSets { if n.Name == nodeSetName { @@ -274,7 +275,7 @@ func (b Builder) WithAdditionalConfig(nodeSetCfg map[string]map[string]interface } func (b Builder) WithChangeBudget(maxSurge, maxUnavailable int32) Builder { - b.Elasticsearch.Spec.UpdateStrategy.ChangeBudget = estype.ChangeBudget{ + b.Elasticsearch.Spec.UpdateStrategy.ChangeBudget = esv1.ChangeBudget{ MaxSurge: pointer.Int32(maxSurge), MaxUnavailable: pointer.Int32(maxUnavailable), } diff --git a/test/e2e/test/elasticsearch/checks_budget.go b/test/e2e/test/elasticsearch/checks_budget.go index acebbc70f4f..8bdfddd6518 100644 --- a/test/e2e/test/elasticsearch/checks_budget.go +++ b/test/e2e/test/elasticsearch/checks_budget.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/reconcile" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/sset" "github.com/elastic/cloud-on-k8s/test/e2e/test" @@ -18,7 +18,7 @@ import ( // NewMasterChangeBudgetWatcher returns a watcher that checks whether at most one master pod at a time is added/removed. // Relies on the assumption that resolution of 1 second is high enough to observe all change steps. -func NewMasterChangeBudgetWatcher(es v1beta1.Elasticsearch) test.Watcher { +func NewMasterChangeBudgetWatcher(es esv1.Elasticsearch) test.Watcher { var observations []int return test.NewWatcher( @@ -48,7 +48,7 @@ func NewMasterChangeBudgetWatcher(es v1beta1.Elasticsearch) test.Watcher { // NewChangeBudgetWatcher returns a watcher that checks whether the pod count stays within the given change budget. // Assumes that observations resolution of 1 second is high enough to observe all changes steps. -func NewChangeBudgetWatcher(from v1beta1.ElasticsearchSpec, to v1beta1.Elasticsearch) test.Watcher { +func NewChangeBudgetWatcher(from esv1.ElasticsearchSpec, to esv1.Elasticsearch) test.Watcher { var PodCounts []int32 var ReadyPodCounts []int32 diff --git a/test/e2e/test/elasticsearch/checks_es.go b/test/e2e/test/elasticsearch/checks_es.go index 97609cb9f41..a47e24b71e1 100644 --- a/test/e2e/test/elasticsearch/checks_es.go +++ b/test/e2e/test/elasticsearch/checks_es.go @@ -10,15 +10,14 @@ import ( "strconv" "strings" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - estype "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" "github.com/elastic/cloud-on-k8s/test/e2e/test" "k8s.io/apimachinery/pkg/api/resource" ) type esClusterChecks struct { - es estype.Elasticsearch + es esv1.Elasticsearch k *test.K8sClient } @@ -39,7 +38,7 @@ func (e *esClusterChecks) newESClient() (client.Client, error) { return NewElasticsearchClient(e.es, e.k) } -func (e *esClusterChecks) CheckESVersion(es estype.Elasticsearch) test.Step { +func (e *esClusterChecks) CheckESVersion(es esv1.Elasticsearch) test.Step { return test.Step{ Name: "ES version should be the expected one", Test: test.Eventually(func() error { @@ -75,8 +74,8 @@ func (e *esClusterChecks) CheckESHealthGreen() test.Step { if err != nil { return err } - actualHealth := estype.ElasticsearchHealth(health.Status) - expectedHealth := estype.ElasticsearchGreenHealth + actualHealth := esv1.ElasticsearchHealth(health.Status) + expectedHealth := esv1.ElasticsearchGreenHealth if actualHealth != expectedHealth { return fmt.Errorf("cluster health is not green, but %s", actualHealth) } @@ -85,7 +84,7 @@ func (e *esClusterChecks) CheckESHealthGreen() test.Step { } } -func (e *esClusterChecks) CheckESNodesTopology(es estype.Elasticsearch) test.Step { +func (e *esClusterChecks) CheckESNodesTopology(es esv1.Elasticsearch) test.Step { return test.Step{ Name: "ES nodes topology should eventually be the expected one", Test: test.Eventually(func() error { @@ -115,7 +114,7 @@ func (e *esClusterChecks) CheckESNodesTopology(es estype.Elasticsearch) test.Ste } // flatten the topology - var expectedTopology []estype.NodeSet + var expectedTopology []esv1.NodeSet for _, node := range es.Spec.NodeSets { for i := 0; i < int(node.Count); i++ { expectedTopology = append(expectedTopology, node) @@ -148,7 +147,7 @@ func (e *esClusterChecks) CheckESNodesTopology(es estype.Elasticsearch) test.Ste nodeRoles := rolesToConfig(node.Roles) nodeStats := nodesStats.Nodes[nodeID] for i, topoElem := range expectedTopology { - cfg, err := v1beta1.UnpackConfig(topoElem.Config) + cfg, err := esv1.UnpackConfig(topoElem.Config) if err != nil { return err } @@ -178,8 +177,8 @@ func (e *esClusterChecks) CheckESNodesTopology(es estype.Elasticsearch) test.Ste } } -func rolesToConfig(roles []string) estype.Node { - node := estype.Node{ +func rolesToConfig(roles []string) esv1.Node { + node := esv1.Node{ ML: true, // ML is not reported in roles array, we assume true } for _, r := range roles { @@ -195,10 +194,10 @@ func rolesToConfig(roles []string) estype.Node { return node } -func compareMemoryLimit(topologyElement estype.NodeSet, cgroupMemoryLimitsInBytes int64) bool { +func compareMemoryLimit(topologyElement esv1.NodeSet, cgroupMemoryLimitsInBytes int64) bool { var memoryLimit *resource.Quantity for _, c := range topologyElement.PodTemplate.Spec.Containers { - if c.Name == v1beta1.ElasticsearchContainerName { + if c.Name == esv1.ElasticsearchContainerName { memoryLimit = c.Resources.Limits.Memory() } } diff --git a/test/e2e/test/elasticsearch/checks_k8s.go b/test/e2e/test/elasticsearch/checks_k8s.go index 4b739d907bd..852d7c2738f 100644 --- a/test/e2e/test/elasticsearch/checks_k8s.go +++ b/test/e2e/test/elasticsearch/checks_k8s.go @@ -10,7 +10,7 @@ import ( "reflect" "sort" - estype "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" "github.com/elastic/cloud-on-k8s/pkg/controller/common/hash" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/label" @@ -148,12 +148,12 @@ func CheckClusterHealth(b Builder, k *test.K8sClient) test.Step { } func clusterHealthGreen(b Builder, k *test.K8sClient) error { - var es estype.Elasticsearch + var es esv1.Elasticsearch err := k.Client.Get(k8s.ExtractNamespacedName(&b.Elasticsearch), &es) if err != nil { return err } - if es.Status.Health != estype.ElasticsearchGreenHealth { + if es.Status.Health != esv1.ElasticsearchGreenHealth { return fmt.Errorf("health is %s", es.Status.Health) } return nil @@ -165,7 +165,7 @@ func CheckServices(b Builder, k *test.K8sClient) test.Step { Name: "ES services should be created", Test: test.Eventually(func() error { for _, s := range []string{ - estype.HTTPService(b.Elasticsearch.Name), + esv1.HTTPService(b.Elasticsearch.Name), } { if _, err := k.GetService(b.Elasticsearch.Namespace, s); err != nil { return err @@ -182,7 +182,7 @@ func CheckServicesEndpoints(b Builder, k *test.K8sClient) test.Step { Name: "ES services should have endpoints", Test: test.Eventually(func() error { for endpointName, addrCount := range map[string]int{ - estype.HTTPService(b.Elasticsearch.Name): int(b.Elasticsearch.Spec.NodeCount()), + esv1.HTTPService(b.Elasticsearch.Name): int(b.Elasticsearch.Spec.NodeCount()), } { if addrCount == 0 { continue // maybe no Kibana @@ -244,7 +244,7 @@ func checkExpectedPodsReady(b Builder, k *test.K8sClient) error { if err := k.Client.Get( types.NamespacedName{ Namespace: b.Elasticsearch.Namespace, - Name: estype.StatefulSet(b.Elasticsearch.Name, nodeSet.Name), + Name: esv1.StatefulSet(b.Elasticsearch.Name, nodeSet.Name), }, &statefulSet, ); err != nil { @@ -291,7 +291,7 @@ func checkStatefulSetsReplicas(b Builder, k *test.K8sClient) error { // build names and replicas count of expected StatefulSets expected := make(map[string]int32, len(b.Elasticsearch.Spec.NodeSets)) // map[StatefulSetName]Replicas for _, nodeSet := range b.Elasticsearch.Spec.NodeSets { - expected[estype.StatefulSet(b.Elasticsearch.Name, nodeSet.Name)] = nodeSet.Count + expected[esv1.StatefulSet(b.Elasticsearch.Name, nodeSet.Name)] = nodeSet.Count } statefulSets, err := k.GetESStatefulSets(b.Elasticsearch.Namespace, b.Elasticsearch.Name) if err != nil { @@ -317,7 +317,7 @@ func AnnotatePodsWithBuilderHash(b Builder, k *test.K8sClient) []test.Step { for _, nodeSet := range b.Elasticsearch.Spec.NodeSets { pods, err := sset.GetActualPodsForStatefulSet(k.Client, types.NamespacedName{ Namespace: es.Namespace, - Name: estype.StatefulSet(es.Name, nodeSet.Name), + Name: esv1.StatefulSet(es.Name, nodeSet.Name), }) if err != nil { return err @@ -335,7 +335,7 @@ func AnnotatePodsWithBuilderHash(b Builder, k *test.K8sClient) []test.Step { } // nodeSetHash builds a hash of the nodeSet specification in the given ES resource. -func nodeSetHash(es estype.Elasticsearch, nodeSet estype.NodeSet) string { +func nodeSetHash(es esv1.Elasticsearch, nodeSet esv1.NodeSet) string { // Normalize the count to zero to exclude it from the hash. Otherwise scaling up/down would affect the hash but // existing nodes not affected by the scaling will not be cycled and therefore be annotated with the previous hash. nodeSet.Count = 0 diff --git a/test/e2e/test/elasticsearch/checks_volume.go b/test/e2e/test/elasticsearch/checks_volume.go index 47c352c8bc6..fe6b7781148 100644 --- a/test/e2e/test/elasticsearch/checks_volume.go +++ b/test/e2e/test/elasticsearch/checks_volume.go @@ -7,13 +7,13 @@ package elasticsearch import ( "testing" - estype "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/volume" "github.com/elastic/cloud-on-k8s/test/e2e/test" "github.com/stretchr/testify/require" ) -func usesEmptyDir(es estype.Elasticsearch) bool { +func usesEmptyDir(es esv1.Elasticsearch) bool { var emptyDirUsed bool for _, n := range es.Spec.NodeSets { for _, v := range n.PodTemplate.Spec.Volumes { @@ -25,7 +25,7 @@ func usesEmptyDir(es estype.Elasticsearch) bool { return emptyDirUsed } -func CheckESDataVolumeType(es estype.Elasticsearch, k *test.K8sClient) test.Step { +func CheckESDataVolumeType(es esv1.Elasticsearch, k *test.K8sClient) test.Step { return test.Step{ Name: "Elasticsearch data volumes should be of the specified type", Test: func(t *testing.T) { diff --git a/test/e2e/test/elasticsearch/cluster_uuid.go b/test/e2e/test/elasticsearch/cluster_uuid.go index 9f08b6f0e31..17a991f559d 100644 --- a/test/e2e/test/elasticsearch/cluster_uuid.go +++ b/test/e2e/test/elasticsearch/cluster_uuid.go @@ -9,13 +9,13 @@ import ( "fmt" "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" esclient "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" "github.com/elastic/cloud-on-k8s/test/e2e/test" "github.com/stretchr/testify/require" ) -func clusterUUID(es v1beta1.Elasticsearch, k *test.K8sClient) (string, error) { +func clusterUUID(es esv1.Elasticsearch, k *test.K8sClient) (string, error) { client, err := NewElasticsearchClient(es, k) if err != nil { return "", err @@ -30,7 +30,7 @@ func clusterUUID(es v1beta1.Elasticsearch, k *test.K8sClient) (string, error) { } // RetrieveClusterUUIDStep stores the current clusterUUID into the given futureClusterUUID -func RetrieveClusterUUIDStep(es v1beta1.Elasticsearch, k *test.K8sClient, futureClusterUUID *string) test.Step { +func RetrieveClusterUUIDStep(es esv1.Elasticsearch, k *test.K8sClient, futureClusterUUID *string) test.Step { return test.Step{ Name: "Retrieve Elasticsearch cluster UUID for comparison purpose", Test: test.Eventually(func() error { @@ -50,7 +50,7 @@ func RetrieveClusterUUIDStep(es v1beta1.Elasticsearch, k *test.K8sClient, future // CompareClusterUUIDStep compares the current clusterUUID with previousClusterUUID, // and fails if they don't match -func CompareClusterUUIDStep(es v1beta1.Elasticsearch, k *test.K8sClient, previousClusterUUID *string) test.Step { +func CompareClusterUUIDStep(es esv1.Elasticsearch, k *test.K8sClient, previousClusterUUID *string) test.Step { return test.Step{ Name: "Cluster UUID should have been preserved", Test: func(t *testing.T) { diff --git a/test/e2e/test/elasticsearch/http_client.go b/test/e2e/test/elasticsearch/http_client.go index 7c440c58dcd..b0aeb1b57a5 100644 --- a/test/e2e/test/elasticsearch/http_client.go +++ b/test/e2e/test/elasticsearch/http_client.go @@ -5,7 +5,7 @@ package elasticsearch import ( - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/version" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/reconcile" @@ -17,14 +17,14 @@ import ( ) // NewElasticsearchClient returns an ES client for the given ES cluster -func NewElasticsearchClient(es v1beta1.Elasticsearch, k *test.K8sClient) (client.Client, error) { +func NewElasticsearchClient(es esv1.Elasticsearch, k *test.K8sClient) (client.Client, error) { password, err := k.GetElasticPassword(es.Namespace, es.Name) if err != nil { return nil, err } esUser := client.UserAuth{Name: "elastic", Password: password} - caCert, err := k.GetHTTPCerts(v1beta1.ESNamer, es.Namespace, es.Name) + caCert, err := k.GetHTTPCerts(esv1.ESNamer, es.Namespace, es.Name) if err != nil { return nil, err } diff --git a/test/e2e/test/elasticsearch/pause.go b/test/e2e/test/elasticsearch/pause.go index 300f2dd8581..f22ecea33d1 100644 --- a/test/e2e/test/elasticsearch/pause.go +++ b/test/e2e/test/elasticsearch/pause.go @@ -8,17 +8,17 @@ import ( "fmt" "strconv" - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/test/e2e/test" ) -func togglePauseOn(paused bool, es v1beta1.Elasticsearch, k *test.K8sClient) test.Step { +func togglePauseOn(paused bool, es esv1.Elasticsearch, k *test.K8sClient) test.Step { return test.Step{ Name: fmt.Sprintf("Should pause reconciliation %v", paused), Test: test.Eventually(func() error { - var curr v1beta1.Elasticsearch + var curr esv1.Elasticsearch if err := k.Client.Get(k8s.ExtractNamespacedName(&es), &curr); err != nil { return err } @@ -33,10 +33,10 @@ func togglePauseOn(paused bool, es v1beta1.Elasticsearch, k *test.K8sClient) tes } } -func PauseReconciliation(es v1beta1.Elasticsearch, k *test.K8sClient) test.Step { +func PauseReconciliation(es esv1.Elasticsearch, k *test.K8sClient) test.Step { return togglePauseOn(true, es, k) } -func ResumeReconciliation(es v1beta1.Elasticsearch, k *test.K8sClient) test.Step { +func ResumeReconciliation(es esv1.Elasticsearch, k *test.K8sClient) test.Step { return togglePauseOn(false, es, k) } diff --git a/test/e2e/test/elasticsearch/settings.go b/test/e2e/test/elasticsearch/settings.go index b47567b99dd..c55e7f6028b 100644 --- a/test/e2e/test/elasticsearch/settings.go +++ b/test/e2e/test/elasticsearch/settings.go @@ -5,12 +5,12 @@ package elasticsearch import ( - "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" common "github.com/elastic/cloud-on-k8s/pkg/controller/common/settings" "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/settings" ) -func MustNumDataNodes(es v1beta1.Elasticsearch) int { +func MustNumDataNodes(es esv1.Elasticsearch) int { var numNodes int for _, n := range es.Spec.NodeSets { if isDataNode(n) { @@ -20,9 +20,9 @@ func MustNumDataNodes(es v1beta1.Elasticsearch) int { return numNodes } -func isDataNode(node v1beta1.NodeSet) bool { +func isDataNode(node esv1.NodeSet) bool { if node.Config == nil { - return v1beta1.DefaultCfg.Node.Data // if not specified use the default + return esv1.DefaultCfg.Node.Data // if not specified use the default } config, err := common.NewCanonicalConfigFrom(node.Config.Data) if err != nil { diff --git a/test/e2e/test/elasticsearch/steps_creation.go b/test/e2e/test/elasticsearch/steps_creation.go index aa5ca3aba4a..80bc93fbaee 100644 --- a/test/e2e/test/elasticsearch/steps_creation.go +++ b/test/e2e/test/elasticsearch/steps_creation.go @@ -7,7 +7,7 @@ package elasticsearch import ( "testing" - estype "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/test/e2e/test" "github.com/stretchr/testify/require" @@ -29,7 +29,7 @@ func (b Builder) CreationTestSteps(k *test.K8sClient) test.StepList { test.Step{ Name: "Elasticsearch cluster should be created", Test: func(t *testing.T) { - var createdEs estype.Elasticsearch + var createdEs esv1.Elasticsearch err := k.Client.Get(k8s.ExtractNamespacedName(&b.Elasticsearch), &createdEs) require.NoError(t, err) require.Equal(t, b.Elasticsearch.Spec.Version, createdEs.Spec.Version) diff --git a/test/e2e/test/elasticsearch/steps_init.go b/test/e2e/test/elasticsearch/steps_init.go index 4dd886b6cbf..77426fbffe6 100644 --- a/test/e2e/test/elasticsearch/steps_init.go +++ b/test/e2e/test/elasticsearch/steps_init.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - estype "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/test/e2e/test" "github.com/stretchr/testify/require" @@ -34,7 +34,7 @@ func (b Builder) InitTestSteps(k *test.K8sClient) test.StepList { Name: "Elasticsearch CRDs should exist", Test: func(t *testing.T) { crds := []runtime.Object{ - &estype.ElasticsearchList{}, + &esv1.ElasticsearchList{}, } for _, crd := range crds { err := k.Client.List(crd) @@ -60,7 +60,7 @@ func (b Builder) InitTestSteps(k *test.K8sClient) test.StepList { // it may take some extra time for Elasticsearch to be fully deleted test.Eventually(func() error { - var es estype.Elasticsearch + var es esv1.Elasticsearch err := k.Client.Get(k8s.ExtractNamespacedName(&b.Elasticsearch), &es) if err != nil && !apierrors.IsNotFound(err) { return err diff --git a/test/e2e/test/elasticsearch/steps_license.go b/test/e2e/test/elasticsearch/steps_license.go index dff23633451..88cc75a89ad 100644 --- a/test/e2e/test/elasticsearch/steps_license.go +++ b/test/e2e/test/elasticsearch/steps_license.go @@ -10,26 +10,27 @@ import ( "fmt" "testing" - estype "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - "github.com/elastic/cloud-on-k8s/pkg/controller/common" - "github.com/elastic/cloud-on-k8s/pkg/controller/common/license" - "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" - "github.com/elastic/cloud-on-k8s/pkg/utils/stringsutil" - "github.com/elastic/cloud-on-k8s/test/e2e/test" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" k8sclient "sigs.k8s.io/controller-runtime/pkg/client" + + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + "github.com/elastic/cloud-on-k8s/pkg/controller/common" + "github.com/elastic/cloud-on-k8s/pkg/controller/common/license" + "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" + "github.com/elastic/cloud-on-k8s/pkg/utils/stringsutil" + "github.com/elastic/cloud-on-k8s/test/e2e/test" ) type LicenseTestContext struct { esClient client.Client k *test.K8sClient - es estype.Elasticsearch + es esv1.Elasticsearch } -func NewLicenseTestContext(k *test.K8sClient, es estype.Elasticsearch) LicenseTestContext { +func NewLicenseTestContext(k *test.K8sClient, es esv1.Elasticsearch) LicenseTestContext { return LicenseTestContext{ k: k, es: es, diff --git a/test/e2e/test/elasticsearch/steps_mutation.go b/test/e2e/test/elasticsearch/steps_mutation.go index 899a63df696..05ab3ada022 100644 --- a/test/e2e/test/elasticsearch/steps_mutation.go +++ b/test/e2e/test/elasticsearch/steps_mutation.go @@ -10,7 +10,7 @@ import ( "testing" "time" - estype "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" esclient "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/client" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/test/e2e/test" @@ -30,7 +30,7 @@ func (b Builder) UpgradeTestSteps(k *test.K8sClient) test.StepList { test.Step{ Name: "Applying the Elasticsearch mutation should succeed", Test: func(t *testing.T) { - var curEs estype.Elasticsearch + var curEs esv1.Elasticsearch require.NoError(t, k.Client.Get(k8s.ExtractNamespacedName(&b.Elasticsearch), &curEs)) curEs.Spec = b.Elasticsearch.Spec require.NoError(t, k.Client.Update(&curEs)) @@ -191,7 +191,7 @@ func (hc *ContinuousHealthCheck) Start() { continue } clusterUnavailability.markAvailable() - if estype.ElasticsearchHealth(health.Status) == estype.ElasticsearchRedHealth { + if esv1.ElasticsearchHealth(health.Status) == esv1.ElasticsearchRedHealth { hc.AppendErr(errors.New("cluster health red")) continue } diff --git a/test/e2e/test/helper/yaml.go b/test/e2e/test/helper/yaml.go index a7e4e6605df..7b73afa28dd 100644 --- a/test/e2e/test/helper/yaml.go +++ b/test/e2e/test/helper/yaml.go @@ -9,9 +9,9 @@ import ( "fmt" "io" - apmtype "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1beta1" - estype "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - kbtype "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + apmv1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/test/e2e/test" "github.com/elastic/cloud-on-k8s/test/e2e/test/apmserver" "github.com/elastic/cloud-on-k8s/test/e2e/test/elasticsearch" @@ -30,9 +30,9 @@ type YAMLDecoder struct { func NewYAMLDecoder() *YAMLDecoder { scheme := runtime.NewScheme() - scheme.AddKnownTypes(estype.GroupVersion, &estype.Elasticsearch{}, &estype.ElasticsearchList{}) - scheme.AddKnownTypes(kbtype.GroupVersion, &kbtype.Kibana{}, &kbtype.KibanaList{}) - scheme.AddKnownTypes(apmtype.GroupVersion, &apmtype.ApmServer{}, &apmtype.ApmServerList{}) + scheme.AddKnownTypes(esv1.GroupVersion, &esv1.Elasticsearch{}, &esv1.ElasticsearchList{}) + scheme.AddKnownTypes(kbv1.GroupVersion, &kbv1.Kibana{}, &kbv1.KibanaList{}) + scheme.AddKnownTypes(apmv1.GroupVersion, &apmv1.ApmServer{}, &apmv1.ApmServerList{}) decoder := serializer.NewCodecFactory(scheme).UniversalDeserializer() return &YAMLDecoder{decoder: decoder} @@ -58,15 +58,15 @@ func (yd *YAMLDecoder) ToBuilders(reader *bufio.Reader, transform BuilderTransfo var builder test.Builder switch decodedObj := obj.(type) { - case *estype.Elasticsearch: + case *esv1.Elasticsearch: b := elasticsearch.NewBuilderWithoutSuffix(decodedObj.Name) b.Elasticsearch = *decodedObj builder = transform(b) - case *kbtype.Kibana: + case *kbv1.Kibana: b := kibana.NewBuilderWithoutSuffix(decodedObj.Name) b.Kibana = *decodedObj builder = transform(b) - case *apmtype.ApmServer: + case *apmv1.ApmServer: b := apmserver.NewBuilderWithoutSuffix(decodedObj.Name) b.ApmServer = *decodedObj builder = transform(b) diff --git a/test/e2e/test/k8s_client.go b/test/e2e/test/k8s_client.go index 9598d802269..21049e9945a 100644 --- a/test/e2e/test/k8s_client.go +++ b/test/e2e/test/k8s_client.go @@ -10,9 +10,9 @@ import ( "fmt" "os" - apmtype "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1beta1" - estype "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1beta1" - kbtype "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + apmv1 "github.com/elastic/cloud-on-k8s/pkg/apis/apm/v1" + esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" apmlabels "github.com/elastic/cloud-on-k8s/pkg/controller/apmserver/labels" "github.com/elastic/cloud-on-k8s/pkg/controller/common" "github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates" @@ -65,13 +65,13 @@ func CreateClient() (k8s.Client, error) { if err != nil { return nil, err } - if err := estype.AddToScheme(scheme.Scheme); err != nil { + if err := esv1.AddToScheme(scheme.Scheme); err != nil { return nil, err } - if err := kbtype.AddToScheme(scheme.Scheme); err != nil { + if err := kbv1.AddToScheme(scheme.Scheme); err != nil { return nil, err } - if err := apmtype.AddToScheme(scheme.Scheme); err != nil { + if err := apmv1.AddToScheme(scheme.Scheme); err != nil { return nil, err } client, err := k8sclient.New(cfg, k8sclient.Options{Scheme: scheme.Scheme}) @@ -216,7 +216,7 @@ func (k *K8sClient) GetCA(ownerNamespace, ownerName string, caType certificates. var secret corev1.Secret key := types.NamespacedName{ Namespace: ownerNamespace, - Name: certificates.CAInternalSecretName(estype.ESNamer, ownerName, caType), + Name: certificates.CAInternalSecretName(esv1.ESNamer, ownerName, caType), } if err := k.Client.Get(key, &secret); err != nil { return nil, err @@ -252,7 +252,7 @@ func (k *K8sClient) GetTransportCert(esName, podName string) (caCert, transportC var secret corev1.Secret key := types.NamespacedName{ Namespace: Ctx().ManagedNamespace(0), - Name: estype.TransportCertificatesSecret(esName), + Name: esv1.TransportCertificatesSecret(esName), } if err = k.Client.Get(key, &secret); err != nil { return nil, nil, err diff --git a/test/e2e/test/kibana/builder.go b/test/e2e/test/kibana/builder.go index c3e16a37e9a..6d37e37ab93 100644 --- a/test/e2e/test/kibana/builder.go +++ b/test/e2e/test/kibana/builder.go @@ -5,18 +5,19 @@ package kibana import ( - commonv1beta1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1beta1" - kbtype "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" - "github.com/elastic/cloud-on-k8s/test/e2e/test" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/rand" + + commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" + "github.com/elastic/cloud-on-k8s/test/e2e/test" ) // Builder to create Kibana instances type Builder struct { - Kibana kbtype.Kibana + Kibana kbv1.Kibana MutatedFrom *Builder } @@ -36,9 +37,9 @@ func newBuilder(name, randSuffix string) Builder { Namespace: test.Ctx().ManagedNamespace(0), } return Builder{ - Kibana: kbtype.Kibana{ + Kibana: kbv1.Kibana{ ObjectMeta: meta, - Spec: kbtype.KibanaSpec{ + Spec: kbv1.KibanaSpec{ Version: test.Ctx().ElasticStackVersion, PodTemplate: corev1.PodTemplateSpec{ Spec: corev1.PodSpec{ @@ -57,7 +58,7 @@ func (b Builder) WithSuffix(suffix string) Builder { return b } -func (b Builder) WithElasticsearchRef(ref commonv1beta1.ObjectSelector) Builder { +func (b Builder) WithElasticsearchRef(ref commonv1.ObjectSelector) Builder { b.Kibana.Spec.ElasticsearchRef = ref return b } @@ -84,9 +85,9 @@ func (b Builder) WithNodeCount(count int) Builder { } func (b Builder) WithKibanaSecureSettings(secretNames ...string) Builder { - refs := make([]commonv1beta1.SecretSource, 0, len(secretNames)) + refs := make([]commonv1.SecretSource, 0, len(secretNames)) for i := range secretNames { - refs = append(refs, commonv1beta1.SecretSource{SecretName: secretNames[i]}) + refs = append(refs, commonv1.SecretSource{SecretName: secretNames[i]}) } b.Kibana.Spec.SecureSettings = refs return b @@ -95,11 +96,11 @@ func (b Builder) WithKibanaSecureSettings(secretNames ...string) Builder { func (b Builder) WithResources(resources corev1.ResourceRequirements) Builder { if len(b.Kibana.Spec.PodTemplate.Spec.Containers) == 0 { b.Kibana.Spec.PodTemplate.Spec.Containers = []corev1.Container{ - {Name: kbtype.KibanaContainerName}, + {Name: kbv1.KibanaContainerName}, } } for i, c := range b.Kibana.Spec.PodTemplate.Spec.Containers { - if c.Name == kbtype.KibanaContainerName { + if c.Name == kbv1.KibanaContainerName { c.Resources = resources b.Kibana.Spec.PodTemplate.Spec.Containers[i] = c } diff --git a/test/e2e/test/kibana/checks_kb.go b/test/e2e/test/kibana/checks_kb.go index 74de7fd31f1..97e7776238e 100644 --- a/test/e2e/test/kibana/checks_kb.go +++ b/test/e2e/test/kibana/checks_kb.go @@ -11,7 +11,7 @@ import ( "strings" "testing" - kbtype "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/name" "github.com/elastic/cloud-on-k8s/test/e2e/test" "github.com/pkg/errors" @@ -36,7 +36,7 @@ func (b Builder) CheckStackTestSteps(k *test.K8sClient) test.StepList { } } -func (check *kbChecks) CreateKbClient(kb kbtype.Kibana) test.Step { +func (check *kbChecks) CreateKbClient(kb kbv1.Kibana) test.Step { return test.Step{ Name: "Create Kibana client", Test: func(t *testing.T) { @@ -49,7 +49,7 @@ func (check *kbChecks) CreateKbClient(kb kbtype.Kibana) test.Step { } // CheckKbLoginHealthy checks that Kibana is able to connect to Elasticsearch by inspecting its login page. -func (check *kbChecks) CheckKbLoginHealthy(kb kbtype.Kibana) test.Step { +func (check *kbChecks) CheckKbLoginHealthy(kb kbv1.Kibana) test.Step { return test.Step{ Name: "Kibana should be able to connect to Elasticsearch", Test: test.Eventually(func() error { diff --git a/test/e2e/test/kibana/http_client.go b/test/e2e/test/kibana/http_client.go index cc851a1e4d4..14fe17d568e 100644 --- a/test/e2e/test/kibana/http_client.go +++ b/test/e2e/test/kibana/http_client.go @@ -13,14 +13,14 @@ import ( "net/url" "path" - "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/name" kbname "github.com/elastic/cloud-on-k8s/pkg/controller/kibana/name" "github.com/elastic/cloud-on-k8s/test/e2e/test" "github.com/pkg/errors" ) -func NewKibanaClient(kb v1beta1.Kibana, k *test.K8sClient) (*http.Client, error) { +func NewKibanaClient(kb kbv1.Kibana, k *test.K8sClient) (*http.Client, error) { var caCerts []*x509.Certificate if kb.Spec.HTTP.TLS.Enabled() { crts, err := k.GetHTTPCerts(name.KBNamer, kb.Namespace, kb.Name) diff --git a/test/e2e/test/kibana/steps_creation.go b/test/e2e/test/kibana/steps_creation.go index a949eccaed4..b36b350c614 100644 --- a/test/e2e/test/kibana/steps_creation.go +++ b/test/e2e/test/kibana/steps_creation.go @@ -7,7 +7,7 @@ package kibana import ( "testing" - kbtype "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/test/e2e/test" "github.com/stretchr/testify/require" @@ -28,7 +28,7 @@ func (b Builder) CreationTestSteps(k *test.K8sClient) test.StepList { { Name: "Kibana should be created", Test: func(t *testing.T) { - var createdKb kbtype.Kibana + var createdKb kbv1.Kibana err := k.Client.Get(k8s.ExtractNamespacedName(&b.Kibana), &createdKb) require.NoError(t, err) require.Equal(t, b.Kibana.Spec.Version, createdKb.Spec.Version) diff --git a/test/e2e/test/kibana/steps_init.go b/test/e2e/test/kibana/steps_init.go index ca8933dc537..48d648eff82 100644 --- a/test/e2e/test/kibana/steps_init.go +++ b/test/e2e/test/kibana/steps_init.go @@ -7,7 +7,7 @@ package kibana import ( "testing" - kbtype "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/test/e2e/test" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" @@ -29,7 +29,7 @@ func (b Builder) InitTestSteps(k *test.K8sClient) test.StepList { Name: "Kibana CRDs should exist", Test: func(t *testing.T) { crds := []runtime.Object{ - &kbtype.KibanaList{}, + &kbv1.KibanaList{}, } for _, crd := range crds { err := k.Client.List(crd) diff --git a/test/e2e/test/kibana/steps_mutation.go b/test/e2e/test/kibana/steps_mutation.go index 647432482fb..9dc32aecfac 100644 --- a/test/e2e/test/kibana/steps_mutation.go +++ b/test/e2e/test/kibana/steps_mutation.go @@ -7,7 +7,7 @@ package kibana import ( "testing" - "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1beta1" + kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1" "github.com/elastic/cloud-on-k8s/pkg/controller/common/hash" "github.com/elastic/cloud-on-k8s/pkg/utils/k8s" "github.com/elastic/cloud-on-k8s/test/e2e/test" @@ -53,7 +53,7 @@ func (b Builder) UpgradeTestSteps(k *test.K8sClient) test.StepList { { Name: "Applying the Kibana mutation should succeed", Test: func(t *testing.T) { - var kb v1beta1.Kibana + var kb kbv1.Kibana require.NoError(t, k.Client.Get(k8s.ExtractNamespacedName(&b.Kibana), &kb)) kb.Spec = b.Kibana.Spec require.NoError(t, k.Client.Update(&kb))