Skip to content

Commit

Permalink
Change ES operator apiversion (#360)
Browse files Browse the repository at this point in the history
* Change ES operator apiversion

Signed-off-by: Gary Brown <[email protected]>

* Fix unit tests

Signed-off-by: Gary Brown <[email protected]>
  • Loading branch information
objectiser authored Apr 4, 2019
1 parent 67e6d0f commit 7f314b5
Show file tree
Hide file tree
Showing 17 changed files with 175 additions and 144 deletions.
8 changes: 6 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/apis/addtoscheme_jaegertracing_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
13 changes: 6 additions & 7 deletions pkg/apis/io/v1alpha1/jaeger_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions pkg/apis/jaegertracing/v1/jaeger_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/jaeger/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions pkg/controller/jaeger/elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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,
},
Expand All @@ -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,
Expand All @@ -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"}

Expand All @@ -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
}

Expand All @@ -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,
Expand All @@ -112,7 +112,7 @@ func TestElasticsearchesDelete(t *testing.T) {
Name: "TestElasticsearchesDelete",
}

orig := esv1alpha1.Elasticsearch{}
orig := esv1.Elasticsearch{}
orig.Name = nsn.Name

objs := []runtime.Object{
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/jaeger/jaeger_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions pkg/inventory/elasticsearch.go
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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)
}
Expand Down
24 changes: 12 additions & 12 deletions pkg/inventory/elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,47 @@ 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)
assert.Equal(t, "to-create", inv.Create[0].Name)

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)
Expand Down
Loading

0 comments on commit 7f314b5

Please sign in to comment.