From 7f314b5bd4d92883bc36c012fc235f10fad7f2c3 Mon Sep 17 00:00:00 2001 From: Gary Brown Date: Thu, 4 Apr 2019 13:41:22 +0100 Subject: [PATCH] Change ES operator apiversion (#360) * Change ES operator apiversion Signed-off-by: Gary Brown * Fix unit tests Signed-off-by: Gary Brown --- Gopkg.lock | 8 ++- pkg/apis/addtoscheme_jaegertracing_v1.go | 4 +- pkg/apis/io/v1alpha1/jaeger_types.go | 13 ++-- pkg/apis/jaegertracing/v1/jaeger_types.go | 14 ++-- pkg/controller/jaeger/elasticsearch.go | 8 +-- pkg/controller/jaeger/elasticsearch_test.go | 18 ++--- .../jaeger/jaeger_controller_test.go | 4 +- pkg/inventory/elasticsearch.go | 20 +++--- pkg/inventory/elasticsearch_test.go | 24 +++---- pkg/storage/elasticsearch.go | 34 ++++----- pkg/storage/elasticsearch/v1/doc.go | 3 + .../{v1alpha1 => v1}/register.go | 4 +- .../elasticsearch/{v1alpha1 => v1}/types.go | 56 +++++++-------- .../{v1alpha1 => v1}/zz_generated.deepcopy.go | 26 ++++++- pkg/storage/elasticsearch_test.go | 71 ++++++++++--------- pkg/strategy/strategy.go | 8 +-- pkg/strategy/strategy_test.go | 4 +- 17 files changed, 175 insertions(+), 144 deletions(-) create mode 100644 pkg/storage/elasticsearch/v1/doc.go rename pkg/storage/elasticsearch/{v1alpha1 => v1}/register.go (89%) rename pkg/storage/elasticsearch/{v1alpha1 => v1}/types.go (80%) rename pkg/storage/elasticsearch/{v1alpha1 => v1}/zz_generated.deepcopy.go (93%) diff --git a/Gopkg.lock b/Gopkg.lock index 71f817b00..f1bdf21c1 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -410,7 +410,10 @@ branch = "release-3.11" digest = "1:66dec43174af7bc882f832dbc67257f31c724245565cc059d188fb7ae08b9e7f" name = "github.com/openshift/api" - packages = ["route/v1"] + packages = [ + "route/v1", + "security/v1", + ] pruneopts = "NT" revision = "5ad8479f64f1b60ee9c62ce8ef1fe6638838725e" @@ -1134,6 +1137,7 @@ input-imports = [ "github.com/mitchellh/go-homedir", "github.com/openshift/api/route/v1", + "github.com/openshift/api/security/v1", "github.com/operator-framework/operator-sdk/pkg/k8sutil", "github.com/operator-framework/operator-sdk/pkg/leader", "github.com/operator-framework/operator-sdk/pkg/metrics", @@ -1146,12 +1150,12 @@ "github.com/spf13/viper", "github.com/stretchr/testify/assert", "github.com/uber/jaeger-client-go/config", + "golang.org/x/net/context", "k8s.io/api/apps/v1", "k8s.io/api/batch/v1", "k8s.io/api/batch/v1beta1", "k8s.io/api/core/v1", "k8s.io/api/extensions/v1beta1", - "k8s.io/api/rbac/v1", "k8s.io/apimachinery/pkg/api/errors", "k8s.io/apimachinery/pkg/api/resource", "k8s.io/apimachinery/pkg/apis/meta/v1", diff --git a/pkg/apis/addtoscheme_jaegertracing_v1.go b/pkg/apis/addtoscheme_jaegertracing_v1.go index 741553ebb..a0c73d6c0 100644 --- a/pkg/apis/addtoscheme_jaegertracing_v1.go +++ b/pkg/apis/addtoscheme_jaegertracing_v1.go @@ -2,10 +2,10 @@ package apis import ( "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1" - esv1alpha1 "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1alpha1" + esv1 "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1" ) func init() { // Register the types with the Scheme so the components can map objects to GroupVersionKinds and back - AddToSchemes = append(AddToSchemes, v1.SchemeBuilder.AddToScheme, esv1alpha1.SchemeBuilder.AddToScheme) + AddToSchemes = append(AddToSchemes, v1.SchemeBuilder.AddToScheme, esv1.SchemeBuilder.AddToScheme) } diff --git a/pkg/apis/io/v1alpha1/jaeger_types.go b/pkg/apis/io/v1alpha1/jaeger_types.go index 9f97cdb6a..35a4a08ee 100644 --- a/pkg/apis/io/v1alpha1/jaeger_types.go +++ b/pkg/apis/io/v1alpha1/jaeger_types.go @@ -4,8 +4,7 @@ import ( "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1alpha1" - esv1alpha1 "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1alpha1" + esv1 "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1" ) // IngressSecurityType represents the possible values for the security type @@ -160,11 +159,11 @@ type JaegerStorageSpec struct { // ElasticsearchSpec represents the ES configuration options that we pass down to the Elasticsearch operator type ElasticsearchSpec struct { - Resources v1.ResourceRequirements `json:"resources"` - NodeCount int32 `json:"nodeCount"` - NodeSelector map[string]string `json:"nodeSelector,omitempty"` - Storage esv1alpha1.ElasticsearchStorageSpec `json:"storage"` - RedundancyPolicy v1alpha1.RedundancyPolicyType `json:"redundancyPolicy"` + Resources v1.ResourceRequirements `json:"resources"` + NodeCount int32 `json:"nodeCount"` + NodeSelector map[string]string `json:"nodeSelector,omitempty"` + Storage esv1.ElasticsearchStorageSpec `json:"storage"` + RedundancyPolicy esv1.RedundancyPolicyType `json:"redundancyPolicy"` } // JaegerCassandraCreateSchemaSpec holds the options related to the create-schema batch job diff --git a/pkg/apis/jaegertracing/v1/jaeger_types.go b/pkg/apis/jaegertracing/v1/jaeger_types.go index 792ffef99..111278eaa 100644 --- a/pkg/apis/jaegertracing/v1/jaeger_types.go +++ b/pkg/apis/jaegertracing/v1/jaeger_types.go @@ -4,7 +4,7 @@ import ( "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1alpha1" + esv1 "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1" ) // IngressSecurityType represents the possible values for the security type @@ -187,12 +187,12 @@ type JaegerStorageSpec struct { // ElasticsearchSpec represents the ES configuration options that we pass down to the Elasticsearch operator // +k8s:openapi-gen=true type ElasticsearchSpec struct { - Image string `json:"image"` - Resources v1.ResourceRequirements `json:"resources"` - NodeCount int32 `json:"nodeCount"` - NodeSelector map[string]string `json:"nodeSelector,omitempty"` - Storage v1alpha1.ElasticsearchStorageSpec `json:"storage"` - RedundancyPolicy v1alpha1.RedundancyPolicyType `json:"redundancyPolicy"` + Image string `json:"image"` + Resources v1.ResourceRequirements `json:"resources"` + NodeCount int32 `json:"nodeCount"` + NodeSelector map[string]string `json:"nodeSelector,omitempty"` + Storage esv1.ElasticsearchStorageSpec `json:"storage"` + RedundancyPolicy esv1.RedundancyPolicyType `json:"redundancyPolicy"` } // JaegerCassandraCreateSchemaSpec holds the options related to the create-schema batch job diff --git a/pkg/controller/jaeger/elasticsearch.go b/pkg/controller/jaeger/elasticsearch.go index 946983697..6a9df7e13 100644 --- a/pkg/controller/jaeger/elasticsearch.go +++ b/pkg/controller/jaeger/elasticsearch.go @@ -14,15 +14,15 @@ import ( "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1" "github.com/jaegertracing/jaeger-operator/pkg/inventory" - esv1alpha1 "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1alpha1" + esv1 "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1" ) -func (r *ReconcileJaeger) applyElasticsearches(jaeger v1.Jaeger, desired []esv1alpha1.Elasticsearch) error { +func (r *ReconcileJaeger) applyElasticsearches(jaeger v1.Jaeger, desired []esv1.Elasticsearch) error { opts := client.MatchingLabels(map[string]string{ "app.kubernetes.io/instance": jaeger.Name, "app.kubernetes.io/part-of": "jaeger", }) - list := &esv1alpha1.ElasticsearchList{} + list := &esv1.ElasticsearchList{} if err := r.client.List(context.Background(), opts, list); err != nil { return err } @@ -55,7 +55,7 @@ func (r *ReconcileJaeger) applyElasticsearches(jaeger v1.Jaeger, desired []esv1a return nil } -func waitForAvailableElastic(c client.Client, es esv1alpha1.Elasticsearch) error { +func waitForAvailableElastic(c client.Client, es esv1.Elasticsearch) error { var expectedSize int32 for _, n := range es.Spec.Nodes { expectedSize += n.NodeCount diff --git a/pkg/controller/jaeger/elasticsearch_test.go b/pkg/controller/jaeger/elasticsearch_test.go index 2abf87ec4..13aacba7e 100644 --- a/pkg/controller/jaeger/elasticsearch_test.go +++ b/pkg/controller/jaeger/elasticsearch_test.go @@ -12,7 +12,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1" - esv1alpha1 "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1alpha1" + esv1 "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1" "github.com/jaegertracing/jaeger-operator/pkg/strategy" ) @@ -35,7 +35,7 @@ func TestElasticsearchesCreate(t *testing.T) { r, cl := getReconciler(objs) r.strategyChooser = func(jaeger *v1.Jaeger) strategy.S { - s := strategy.New().WithElasticsearches([]esv1alpha1.Elasticsearch{{ + s := strategy.New().WithElasticsearches([]esv1.Elasticsearch{{ ObjectMeta: metav1.ObjectMeta{ Name: nsn.Name, }, @@ -50,7 +50,7 @@ func TestElasticsearchesCreate(t *testing.T) { assert.NoError(t, err) assert.False(t, res.Requeue, "We don't requeue for now") - persisted := &esv1alpha1.Elasticsearch{} + persisted := &esv1.Elasticsearch{} persistedName := types.NamespacedName{ Name: nsn.Name, Namespace: nsn.Namespace, @@ -69,7 +69,7 @@ func TestElasticsearchesUpdate(t *testing.T) { Name: "TestElasticsearchesUpdate", } - orig := esv1alpha1.Elasticsearch{} + orig := esv1.Elasticsearch{} orig.Name = nsn.Name orig.Annotations = map[string]string{"key": "value"} @@ -80,11 +80,11 @@ func TestElasticsearchesUpdate(t *testing.T) { r, cl := getReconciler(objs) r.strategyChooser = func(jaeger *v1.Jaeger) strategy.S { - updated := esv1alpha1.Elasticsearch{} + updated := esv1.Elasticsearch{} updated.Name = orig.Name updated.Annotations = map[string]string{"key": "new-value"} - s := strategy.New().WithElasticsearches([]esv1alpha1.Elasticsearch{updated}) + s := strategy.New().WithElasticsearches([]esv1.Elasticsearch{updated}) return s } @@ -93,7 +93,7 @@ func TestElasticsearchesUpdate(t *testing.T) { assert.NoError(t, err) // verify - persisted := &esv1alpha1.Elasticsearch{} + persisted := &esv1.Elasticsearch{} persistedName := types.NamespacedName{ Name: orig.Name, Namespace: orig.Namespace, @@ -112,7 +112,7 @@ func TestElasticsearchesDelete(t *testing.T) { Name: "TestElasticsearchesDelete", } - orig := esv1alpha1.Elasticsearch{} + orig := esv1.Elasticsearch{} orig.Name = nsn.Name objs := []runtime.Object{ @@ -130,7 +130,7 @@ func TestElasticsearchesDelete(t *testing.T) { assert.NoError(t, err) // verify - persisted := &esv1alpha1.Elasticsearch{} + persisted := &esv1.Elasticsearch{} persistedName := types.NamespacedName{ Name: orig.Name, Namespace: orig.Namespace, diff --git a/pkg/controller/jaeger/jaeger_controller_test.go b/pkg/controller/jaeger/jaeger_controller_test.go index ce9dd2aa1..a2d47092d 100644 --- a/pkg/controller/jaeger/jaeger_controller_test.go +++ b/pkg/controller/jaeger/jaeger_controller_test.go @@ -14,7 +14,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1" - esv1alpha1 "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1alpha1" + esv1 "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1" "github.com/jaegertracing/jaeger-operator/pkg/strategy" ) @@ -99,7 +99,7 @@ func getReconciler(objs []runtime.Object) (*ReconcileJaeger, client.Client) { s.AddKnownTypes(v1.SchemeGroupVersion, &v1.Jaeger{}) // Jaeger's Elasticsearch - s.AddKnownTypes(v1.SchemeGroupVersion, &esv1alpha1.Elasticsearch{}, &esv1alpha1.ElasticsearchList{}) + s.AddKnownTypes(v1.SchemeGroupVersion, &esv1.Elasticsearch{}, &esv1.ElasticsearchList{}) cl := fake.NewFakeClient(objs...) return &ReconcileJaeger{client: cl, scheme: s}, cl diff --git a/pkg/inventory/elasticsearch.go b/pkg/inventory/elasticsearch.go index a24d1e08a..d33a2bb1d 100644 --- a/pkg/inventory/elasticsearch.go +++ b/pkg/inventory/elasticsearch.go @@ -1,19 +1,19 @@ package inventory import ( - esv1alpha1 "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1alpha1" + esv1 "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1" ) // Elasticsearch represents the elastic search inventory based on the current and desired states type Elasticsearch struct { - Create []esv1alpha1.Elasticsearch - Update []esv1alpha1.Elasticsearch - Delete []esv1alpha1.Elasticsearch + Create []esv1.Elasticsearch + Update []esv1.Elasticsearch + Delete []esv1.Elasticsearch } // ForElasticsearches builds a new elastic search inventory based on the existing and desired states -func ForElasticsearches(existing []esv1alpha1.Elasticsearch, desired []esv1alpha1.Elasticsearch) Elasticsearch { - update := []esv1alpha1.Elasticsearch{} +func ForElasticsearches(existing []esv1.Elasticsearch, desired []esv1.Elasticsearch) Elasticsearch { + update := []esv1.Elasticsearch{} mcreate := esMap(desired) mdelete := esMap(existing) @@ -45,16 +45,16 @@ func ForElasticsearches(existing []esv1alpha1.Elasticsearch, desired []esv1alpha } } -func esMap(deps []esv1alpha1.Elasticsearch) map[string]esv1alpha1.Elasticsearch { - m := map[string]esv1alpha1.Elasticsearch{} +func esMap(deps []esv1.Elasticsearch) map[string]esv1.Elasticsearch { + m := map[string]esv1.Elasticsearch{} for _, d := range deps { m[d.Name] = d } return m } -func esList(m map[string]esv1alpha1.Elasticsearch) []esv1alpha1.Elasticsearch { - l := []esv1alpha1.Elasticsearch{} +func esList(m map[string]esv1.Elasticsearch) []esv1.Elasticsearch { + l := []esv1.Elasticsearch{} for _, v := range m { l = append(l, v) } diff --git a/pkg/inventory/elasticsearch_test.go b/pkg/inventory/elasticsearch_test.go index 529520407..0be1282ee 100644 --- a/pkg/inventory/elasticsearch_test.go +++ b/pkg/inventory/elasticsearch_test.go @@ -6,39 +6,39 @@ import ( "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - esv1alpha1 "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1alpha1" + esv1 "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1" ) func TestElasticsearchInventory(t *testing.T) { - toCreate := esv1alpha1.Elasticsearch{ + toCreate := esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Name: "to-create", }, } - toUpdate := esv1alpha1.Elasticsearch{ + toUpdate := esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Name: "to-update", }, - Spec: esv1alpha1.ElasticsearchSpec{ - ManagementState: esv1alpha1.ManagementStateManaged, + Spec: esv1.ElasticsearchSpec{ + ManagementState: esv1.ManagementStateManaged, }, } - updated := esv1alpha1.Elasticsearch{ + updated := esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Name: "to-update", }, - Spec: esv1alpha1.ElasticsearchSpec{ - ManagementState: esv1alpha1.ManagementStateUnmanaged, + Spec: esv1.ElasticsearchSpec{ + ManagementState: esv1.ManagementStateUnmanaged, }, } - toDelete := esv1alpha1.Elasticsearch{ + toDelete := esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Name: "to-delete", }, } - existing := []esv1alpha1.Elasticsearch{toUpdate, toDelete} - desired := []esv1alpha1.Elasticsearch{updated, toCreate} + existing := []esv1.Elasticsearch{toUpdate, toDelete} + desired := []esv1.Elasticsearch{updated, toCreate} inv := ForElasticsearches(existing, desired) assert.Len(t, inv.Create, 1) @@ -46,7 +46,7 @@ func TestElasticsearchInventory(t *testing.T) { assert.Len(t, inv.Update, 1) assert.Equal(t, "to-update", inv.Update[0].Name) - assert.Equal(t, esv1alpha1.ManagementStateUnmanaged, inv.Update[0].Spec.ManagementState) + assert.Equal(t, esv1.ManagementStateUnmanaged, inv.Update[0].Spec.ManagementState) assert.Len(t, inv.Delete, 1) assert.Equal(t, "to-delete", inv.Delete[0].Name) diff --git a/pkg/storage/elasticsearch.go b/pkg/storage/elasticsearch.go index b87162a52..89af4c04c 100644 --- a/pkg/storage/elasticsearch.go +++ b/pkg/storage/elasticsearch.go @@ -9,7 +9,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1" - esv1alpha1 "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1alpha1" + esv1 "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1" "github.com/jaegertracing/jaeger-operator/pkg/util" ) @@ -126,8 +126,8 @@ func (ed *ElasticsearchDeployment) InjectSecretsConfiguration(p *corev1.PodSpec) } // Elasticsearch returns an ES CR for the deployment -func (ed *ElasticsearchDeployment) Elasticsearch() *esv1alpha1.Elasticsearch { - return &esv1alpha1.Elasticsearch{ +func (ed *ElasticsearchDeployment) Elasticsearch() *esv1.Elasticsearch { + return &esv1.Elasticsearch{ ObjectMeta: metav1.ObjectMeta{ Namespace: ed.Jaeger.Namespace, Name: esSecret.name, @@ -143,10 +143,10 @@ func (ed *ElasticsearchDeployment) Elasticsearch() *esv1alpha1.Elasticsearch { }, OwnerReferences: []metav1.OwnerReference{util.AsOwner(ed.Jaeger)}, }, - Spec: esv1alpha1.ElasticsearchSpec{ - ManagementState: esv1alpha1.ManagementStateManaged, + Spec: esv1.ElasticsearchSpec{ + ManagementState: esv1.ManagementStateManaged, RedundancyPolicy: ed.Jaeger.Spec.Storage.Elasticsearch.RedundancyPolicy, - Spec: esv1alpha1.ElasticsearchNodeSpec{ + Spec: esv1.ElasticsearchNodeSpec{ Image: ed.Jaeger.Spec.Storage.Elasticsearch.Image, Resources: ed.Jaeger.Spec.Storage.Elasticsearch.Resources, }, @@ -155,29 +155,29 @@ func (ed *ElasticsearchDeployment) Elasticsearch() *esv1alpha1.Elasticsearch { } } -func getNodes(es v1.ElasticsearchSpec) []esv1alpha1.ElasticsearchNode { +func getNodes(es v1.ElasticsearchSpec) []esv1.ElasticsearchNode { if es.NodeCount <= 3 { - return []esv1alpha1.ElasticsearchNode{ + return []esv1.ElasticsearchNode{ { NodeCount: es.NodeCount, Storage: es.Storage, NodeSelector: es.NodeSelector, - Roles: []esv1alpha1.ElasticsearchNodeRole{esv1alpha1.ElasticsearchRoleClient, esv1alpha1.ElasticsearchRoleData, esv1alpha1.ElasticsearchRoleMaster}, + Roles: []esv1.ElasticsearchNodeRole{esv1.ElasticsearchRoleClient, esv1.ElasticsearchRoleData, esv1.ElasticsearchRoleMaster}, }, } } - return []esv1alpha1.ElasticsearchNode{ + return []esv1.ElasticsearchNode{ { NodeCount: 3, Storage: es.Storage, NodeSelector: es.NodeSelector, - Roles: []esv1alpha1.ElasticsearchNodeRole{esv1alpha1.ElasticsearchRoleMaster}, + Roles: []esv1.ElasticsearchNodeRole{esv1.ElasticsearchRoleMaster}, }, { NodeCount: dataNodesCount(es.NodeCount), Storage: es.Storage, NodeSelector: es.NodeSelector, - Roles: []esv1alpha1.ElasticsearchNodeRole{esv1alpha1.ElasticsearchRoleClient, esv1alpha1.ElasticsearchRoleData}, + Roles: []esv1.ElasticsearchNodeRole{esv1.ElasticsearchRoleClient, esv1.ElasticsearchRoleData}, }, } } @@ -190,15 +190,15 @@ func dataNodesCount(nodesCount int32) int32 { } // taken from https://github.com/openshift/cluster-logging-operator/blob/1ead6701c7c7af9c0578aa66597261079b2781d5/vendor/github.com/openshift/elasticsearch-operator/pkg/k8shandler/defaults.go#L33 -func calculateReplicaShards(policyType esv1alpha1.RedundancyPolicyType, dataNodes int) int { +func calculateReplicaShards(policyType esv1.RedundancyPolicyType, dataNodes int) int { switch policyType { - case esv1alpha1.FullRedundancy: + case esv1.FullRedundancy: return dataNodes - 1 - case esv1alpha1.MultipleRedundancy: + case esv1.MultipleRedundancy: return (dataNodes - 1) / 2 - case esv1alpha1.SingleRedundancy: + case esv1.SingleRedundancy: return 1 - case esv1alpha1.ZeroRedundancy: + case esv1.ZeroRedundancy: return 0 default: return 1 diff --git a/pkg/storage/elasticsearch/v1/doc.go b/pkg/storage/elasticsearch/v1/doc.go new file mode 100644 index 000000000..16684cd05 --- /dev/null +++ b/pkg/storage/elasticsearch/v1/doc.go @@ -0,0 +1,3 @@ +// +k8s:deepcopy-gen=package +// +groupName=logging.openshift.io +package v1 diff --git a/pkg/storage/elasticsearch/v1alpha1/register.go b/pkg/storage/elasticsearch/v1/register.go similarity index 89% rename from pkg/storage/elasticsearch/v1alpha1/register.go rename to pkg/storage/elasticsearch/v1/register.go index f2a021b1d..2f10122d0 100644 --- a/pkg/storage/elasticsearch/v1alpha1/register.go +++ b/pkg/storage/elasticsearch/v1/register.go @@ -1,4 +1,4 @@ -package v1alpha1 +package v1 import ( "k8s.io/apimachinery/pkg/runtime/schema" @@ -7,7 +7,7 @@ import ( var ( // SchemeGroupVersion is group version used to register these objects - SchemeGroupVersion = schema.GroupVersion{Group: "logging.openshift.io", Version: "v1alpha1"} + SchemeGroupVersion = schema.GroupVersion{Group: "logging.openshift.io", Version: "v1"} // SchemeBuilder is used to add go types to the GroupVersionKind scheme SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} diff --git a/pkg/storage/elasticsearch/v1alpha1/types.go b/pkg/storage/elasticsearch/v1/types.go similarity index 80% rename from pkg/storage/elasticsearch/v1alpha1/types.go rename to pkg/storage/elasticsearch/v1/types.go index 26abea185..4aaa74394 100644 --- a/pkg/storage/elasticsearch/v1alpha1/types.go +++ b/pkg/storage/elasticsearch/v1/types.go @@ -1,7 +1,7 @@ -package v1alpha1 +package v1 import ( - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -64,10 +64,12 @@ type ElasticsearchNode struct { Resources v1.ResourceRequirements `json:"resources"` NodeSelector map[string]string `json:"nodeSelector,omitempty"` Storage ElasticsearchStorageSpec `json:"storage"` + GenUUID *string `json:"genUUID,omitempty"` + // GenUUID will be populated by the operator if not provided } type ElasticsearchStorageSpec struct { - StorageClassName string `json:"storageClassName,omitempty"` + StorageClassName *string `json:"storageClassName,omitempty"` Size *resource.Quantity `json:"size,omitempty"` } @@ -80,11 +82,14 @@ type ElasticsearchNodeStatus struct { Status string `json:"status,omitempty"` UpgradeStatus ElasticsearchNodeUpgradeStatus `json:"upgradeStatus,omitempty"` Roles []ElasticsearchNodeRole `json:"roles,omitempty"` + Conditions []ClusterCondition `json:"conditions,omitempty"` } type ElasticsearchNodeUpgradeStatus struct { - UnderUpgrade UpgradeStatus `json:"underUpgrade,omitempty"` - UpgradePhase ElasticsearchUpgradePhase `json:"upgradePhase,omitempty"` + ScheduledForUpgrade v1.ConditionStatus `json:"scheduledUpgrade,omitempty"` + ScheduledForRedeploy v1.ConditionStatus `json:"scheduledRedeploy,omitempty"` + UnderUpgrade v1.ConditionStatus `json:"underUpgrade,omitempty"` + UpgradePhase ElasticsearchUpgradePhase `json:"upgradePhase,omitempty"` } type ElasticsearchUpgradePhase string @@ -97,17 +102,11 @@ const ( // ElasticsearchNodeSpec represents configuration of an individual Elasticsearch node type ElasticsearchNodeSpec struct { - Image string `json:"image,omitempty"` - Resources v1.ResourceRequirements `json:"resources"` + Image string `json:"image,omitempty"` + Resources v1.ResourceRequirements `json:"resources"` + NodeSelector map[string]string `json:"nodeSelector,omitempty"` } -type UpgradeStatus string - -const ( - UnderUpgradeTrue UpgradeStatus = "True" - UnderUpgradeFalse UpgradeStatus = "False" -) - type ElasticsearchRequiredAction string const ( @@ -130,8 +129,9 @@ const ( type ShardAllocationState string const ( - ShardAllocationTrue ShardAllocationState = "True" - ShardAllocationFalse ShardAllocationState = "False" + ShardAllocationAll ShardAllocationState = "all" + ShardAllocationNone ShardAllocationState = "none" + ShardAllocationUnknown ShardAllocationState = "shard allocation unknown" ) // ElasticsearchStatus represents the status of Elasticsearch cluster @@ -168,7 +168,7 @@ type ClusterCondition struct { // Type is the type of the condition. Type ClusterConditionType `json:"type"` // Status is the status of the condition. - Status ConditionStatus `json:"status"` + Status v1.ConditionStatus `json:"status"` // Last time the condition transitioned from one status to another. LastTransitionTime metav1.Time `json:"lastTransitionTime"` // Unique, one-word, CamelCase reason for the condition's last transition. @@ -186,14 +186,18 @@ const ( ScalingUp ClusterConditionType = "ScalingUp" ScalingDown ClusterConditionType = "ScalingDown" Restarting ClusterConditionType = "Restarting" -) -type ConditionStatus string - -const ( - ConditionTrue ConditionStatus = "True" - ConditionFalse ConditionStatus = "False" - ConditionUnknown ConditionStatus = "Unknown" + InvalidMasters ClusterConditionType = "InvalidMasters" + InvalidData ClusterConditionType = "InvalidData" + InvalidRedundancy ClusterConditionType = "InvalidRedundancy" + InvalidUUID ClusterConditionType = "InvalidUUID" + + ESContainerWaiting ClusterConditionType = "ElasticsearchContainerWaiting" + ESContainerTerminated ClusterConditionType = "ElasticsearchContainerTerminated" + ProxyContainerWaiting ClusterConditionType = "ProxyContainerWaiting" + ProxyContainerTerminated ClusterConditionType = "ProxyContainerTerminated" + Unschedulable ClusterConditionType = "Unschedulable" + NodeStorage ClusterConditionType = "NodeStorage" ) type ClusterEvent string @@ -204,7 +208,3 @@ const ( UpdateClusterSettings ClusterEvent = "UpdateClusterSettings" NoEvent ClusterEvent = "NoEvent" ) - -func init() { - SchemeBuilder.Register(&Elasticsearch{}, &ElasticsearchList{}) -} diff --git a/pkg/storage/elasticsearch/v1alpha1/zz_generated.deepcopy.go b/pkg/storage/elasticsearch/v1/zz_generated.deepcopy.go similarity index 93% rename from pkg/storage/elasticsearch/v1alpha1/zz_generated.deepcopy.go rename to pkg/storage/elasticsearch/v1/zz_generated.deepcopy.go index 8c0975034..0e04ddbb6 100644 --- a/pkg/storage/elasticsearch/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/storage/elasticsearch/v1/zz_generated.deepcopy.go @@ -2,7 +2,7 @@ // Code generated by deepcopy-gen. DO NOT EDIT. -package v1alpha1 +package v1 import ( runtime "k8s.io/apimachinery/pkg/runtime" @@ -106,6 +106,11 @@ func (in *ElasticsearchNode) DeepCopyInto(out *ElasticsearchNode) { } } in.Storage.DeepCopyInto(&out.Storage) + if in.GenUUID != nil { + in, out := &in.GenUUID, &out.GenUUID + *out = new(string) + **out = **in + } return } @@ -123,6 +128,13 @@ func (in *ElasticsearchNode) DeepCopy() *ElasticsearchNode { func (in *ElasticsearchNodeSpec) DeepCopyInto(out *ElasticsearchNodeSpec) { *out = *in in.Resources.DeepCopyInto(&out.Resources) + if in.NodeSelector != nil { + in, out := &in.NodeSelector, &out.NodeSelector + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } return } @@ -145,6 +157,13 @@ func (in *ElasticsearchNodeStatus) DeepCopyInto(out *ElasticsearchNodeStatus) { *out = make([]ElasticsearchNodeRole, len(*in)) copy(*out, *in) } + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make([]ClusterCondition, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } return } @@ -256,6 +275,11 @@ func (in *ElasticsearchStatus) DeepCopy() *ElasticsearchStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ElasticsearchStorageSpec) DeepCopyInto(out *ElasticsearchStorageSpec) { *out = *in + if in.StorageClassName != nil { + in, out := &in.StorageClassName, &out.StorageClassName + *out = new(string) + **out = **in + } if in.Size != nil { in, out := &in.Size, &out.Size x := (*in).DeepCopy() diff --git a/pkg/storage/elasticsearch_test.go b/pkg/storage/elasticsearch_test.go index 04c0fac1d..2f78827ab 100644 --- a/pkg/storage/elasticsearch_test.go +++ b/pkg/storage/elasticsearch_test.go @@ -8,7 +8,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1" - esv1alpha1 "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1alpha1" + esv1 "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1" ) func TestShouldDeployElasticsearch(t *testing.T) { @@ -27,27 +27,28 @@ func TestShouldDeployElasticsearch(t *testing.T) { } func TestCreateElasticsearchCR(t *testing.T) { + storageClassName := "floppydisk" tests := []struct { jEsSpec v1.ElasticsearchSpec - esSpec esv1alpha1.ElasticsearchSpec + esSpec esv1.ElasticsearchSpec }{ { jEsSpec: v1.ElasticsearchSpec{ NodeCount: 2, - RedundancyPolicy: esv1alpha1.FullRedundancy, - Storage: esv1alpha1.ElasticsearchStorageSpec{ - StorageClassName: "floppydisk", + RedundancyPolicy: esv1.FullRedundancy, + Storage: esv1.ElasticsearchStorageSpec{ + StorageClassName: &storageClassName, }, }, - esSpec: esv1alpha1.ElasticsearchSpec{ - ManagementState: esv1alpha1.ManagementStateManaged, - RedundancyPolicy: esv1alpha1.FullRedundancy, - Spec: esv1alpha1.ElasticsearchNodeSpec{}, - Nodes: []esv1alpha1.ElasticsearchNode{ + esSpec: esv1.ElasticsearchSpec{ + ManagementState: esv1.ManagementStateManaged, + RedundancyPolicy: esv1.FullRedundancy, + Spec: esv1.ElasticsearchNodeSpec{}, + Nodes: []esv1.ElasticsearchNode{ { NodeCount: 2, - Storage: esv1alpha1.ElasticsearchStorageSpec{StorageClassName: "floppydisk"}, - Roles: []esv1alpha1.ElasticsearchNodeRole{esv1alpha1.ElasticsearchRoleClient, esv1alpha1.ElasticsearchRoleData, esv1alpha1.ElasticsearchRoleMaster}, + Storage: esv1.ElasticsearchStorageSpec{StorageClassName: &storageClassName}, + Roles: []esv1.ElasticsearchNodeRole{esv1.ElasticsearchRoleClient, esv1.ElasticsearchRoleData, esv1.ElasticsearchRoleMaster}, }, }, }, @@ -55,25 +56,25 @@ func TestCreateElasticsearchCR(t *testing.T) { { jEsSpec: v1.ElasticsearchSpec{ NodeCount: 5, - RedundancyPolicy: esv1alpha1.FullRedundancy, - Storage: esv1alpha1.ElasticsearchStorageSpec{ - StorageClassName: "floppydisk", + RedundancyPolicy: esv1.FullRedundancy, + Storage: esv1.ElasticsearchStorageSpec{ + StorageClassName: &storageClassName, }, }, - esSpec: esv1alpha1.ElasticsearchSpec{ - ManagementState: esv1alpha1.ManagementStateManaged, - RedundancyPolicy: esv1alpha1.FullRedundancy, - Spec: esv1alpha1.ElasticsearchNodeSpec{}, - Nodes: []esv1alpha1.ElasticsearchNode{ + esSpec: esv1.ElasticsearchSpec{ + ManagementState: esv1.ManagementStateManaged, + RedundancyPolicy: esv1.FullRedundancy, + Spec: esv1.ElasticsearchNodeSpec{}, + Nodes: []esv1.ElasticsearchNode{ { NodeCount: 3, - Storage: esv1alpha1.ElasticsearchStorageSpec{StorageClassName: "floppydisk"}, - Roles: []esv1alpha1.ElasticsearchNodeRole{esv1alpha1.ElasticsearchRoleMaster}, + Storage: esv1.ElasticsearchStorageSpec{StorageClassName: &storageClassName}, + Roles: []esv1.ElasticsearchNodeRole{esv1.ElasticsearchRoleMaster}, }, { NodeCount: 2, - Storage: esv1alpha1.ElasticsearchStorageSpec{StorageClassName: "floppydisk"}, - Roles: []esv1alpha1.ElasticsearchNodeRole{esv1alpha1.ElasticsearchRoleClient, esv1alpha1.ElasticsearchRoleData}, + Storage: esv1.ElasticsearchStorageSpec{StorageClassName: &storageClassName}, + Roles: []esv1.ElasticsearchNodeRole{esv1.ElasticsearchRoleClient, esv1.ElasticsearchRoleData}, }, }, }, @@ -156,7 +157,7 @@ func TestInject(t *testing.T) { }, { pod: &corev1.PodSpec{Containers: []corev1.Container{{}}}, - es: v1.ElasticsearchSpec{NodeCount: 15, RedundancyPolicy: esv1alpha1.FullRedundancy}, + es: v1.ElasticsearchSpec{NodeCount: 15, RedundancyPolicy: esv1.FullRedundancy}, expected: &corev1.PodSpec{ Containers: []corev1.Container{{ Args: []string{ @@ -180,7 +181,7 @@ func TestInject(t *testing.T) { }, { pod: &corev1.PodSpec{Containers: []corev1.Container{{Args: []string{"--es-archive.enabled=true"}}}}, - es: v1.ElasticsearchSpec{NodeCount: 15, RedundancyPolicy: esv1alpha1.FullRedundancy}, + es: v1.ElasticsearchSpec{NodeCount: 15, RedundancyPolicy: esv1.FullRedundancy}, expected: &corev1.PodSpec{ Containers: []corev1.Container{{ Args: []string{ @@ -225,17 +226,17 @@ func TestInject(t *testing.T) { func TestCalculateReplicaShards(t *testing.T) { tests := []struct { dataNodes int - redType esv1alpha1.RedundancyPolicyType + redType esv1.RedundancyPolicyType shards int }{ - {redType: esv1alpha1.ZeroRedundancy, dataNodes: 1, shards: 0}, - {redType: esv1alpha1.ZeroRedundancy, dataNodes: 1, shards: 0}, - {redType: esv1alpha1.SingleRedundancy, dataNodes: 1, shards: 1}, - {redType: esv1alpha1.SingleRedundancy, dataNodes: 20, shards: 1}, - {redType: esv1alpha1.MultipleRedundancy, dataNodes: 1, shards: 0}, - {redType: esv1alpha1.MultipleRedundancy, dataNodes: 20, shards: 9}, - {redType: esv1alpha1.FullRedundancy, dataNodes: 1, shards: 0}, - {redType: esv1alpha1.FullRedundancy, dataNodes: 20, shards: 19}, + {redType: esv1.ZeroRedundancy, dataNodes: 1, shards: 0}, + {redType: esv1.ZeroRedundancy, dataNodes: 1, shards: 0}, + {redType: esv1.SingleRedundancy, dataNodes: 1, shards: 1}, + {redType: esv1.SingleRedundancy, dataNodes: 20, shards: 1}, + {redType: esv1.MultipleRedundancy, dataNodes: 1, shards: 0}, + {redType: esv1.MultipleRedundancy, dataNodes: 20, shards: 9}, + {redType: esv1.FullRedundancy, dataNodes: 1, shards: 0}, + {redType: esv1.FullRedundancy, dataNodes: 20, shards: 19}, } for _, test := range tests { assert.Equal(t, test.shards, calculateReplicaShards(test.redType, test.dataNodes)) diff --git a/pkg/strategy/strategy.go b/pkg/strategy/strategy.go index 7d44e7422..232f857e0 100644 --- a/pkg/strategy/strategy.go +++ b/pkg/strategy/strategy.go @@ -8,7 +8,7 @@ import ( "k8s.io/api/core/v1" "k8s.io/api/extensions/v1beta1" - esv1alpha1 "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1alpha1" + esv1 "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1" ) // S knows what type of deployments to build based on a given spec @@ -20,7 +20,7 @@ type S struct { daemonSets []appsv1.DaemonSet dependencies []batchv1.Job deployments []appsv1.Deployment - elasticsearches []esv1alpha1.Elasticsearch + elasticsearches []esv1.Elasticsearch ingresses []v1beta1.Ingress routes []osv1.Route services []v1.Service @@ -89,7 +89,7 @@ func (s S) WithDependencies(deps []batchv1.Job) S { } // WithElasticsearches returns the strategy with the given list of elastic search instances -func (s S) WithElasticsearches(es []esv1alpha1.Elasticsearch) S { +func (s S) WithElasticsearches(es []esv1.Elasticsearch) S { s.elasticsearches = es return s } @@ -144,7 +144,7 @@ func (s S) Deployments() []appsv1.Deployment { } // Elasticsearches returns the list of elastic search instances for this strategy -func (s S) Elasticsearches() []esv1alpha1.Elasticsearch { +func (s S) Elasticsearches() []esv1.Elasticsearch { return s.elasticsearches } diff --git a/pkg/strategy/strategy_test.go b/pkg/strategy/strategy_test.go index a6dbd7ece..47155df17 100644 --- a/pkg/strategy/strategy_test.go +++ b/pkg/strategy/strategy_test.go @@ -11,7 +11,7 @@ import ( "k8s.io/api/core/v1" "k8s.io/api/extensions/v1beta1" - esv1alpha1 "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1alpha1" + esv1 "github.com/jaegertracing/jaeger-operator/pkg/storage/elasticsearch/v1" ) func TestWithAccounts(t *testing.T) { @@ -45,7 +45,7 @@ func TestWithDeployments(t *testing.T) { } func TestWithElasticsearches(t *testing.T) { - c := New().WithElasticsearches([]esv1alpha1.Elasticsearch{{}}) + c := New().WithElasticsearches([]esv1.Elasticsearch{{}}) assert.Len(t, c.Elasticsearches(), 1) }