Skip to content

Commit

Permalink
(not ready to merge) Create CRDs V1 (elastic#2184)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sebgl authored and mjmbischoff committed Jan 13, 2020
1 parent fdbea83 commit 6553082
Show file tree
Hide file tree
Showing 236 changed files with 6,285 additions and 1,500 deletions.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
31 changes: 16 additions & 15 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
}
Expand Down
21 changes: 15 additions & 6 deletions config/crds/all-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions config/crds/bases/apm.k8s.elastic.co_apmservers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""
Expand Down
7 changes: 5 additions & 2 deletions config/crds/bases/kibana.k8s.elastic.co_kibanas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""
Expand Down
19 changes: 19 additions & 0 deletions config/e2e/global_operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions config/operator/global/webhook.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@ kind: ValidatingWebhookConfiguration
metadata:
name: elastic-webhook.k8s.elastic.co
webhooks:
- clientConfig:
caBundle: Cg==
service:
name: elastic-webhook-server
namespace: <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:
Expand Down
4 changes: 2 additions & 2 deletions config/recipes/beats/1_monitor.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions config/samples/apm/apm_es_kibana.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/samples/apm/apmserver.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: apm.k8s.elastic.co/v1beta1
apiVersion: apm.k8s.elastic.co/v1
kind: ApmServer
metadata:
name: apmserver-sample
Expand Down
2 changes: 1 addition & 1 deletion config/samples/elasticsearch/elasticsearch.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions config/samples/kibana/kibana_es.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
20 changes: 19 additions & 1 deletion config/webhook/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading

0 comments on commit 6553082

Please sign in to comment.