Skip to content
This repository was archived by the owner on Nov 18, 2020. It is now read-only.

Commit 00bb736

Browse files
authored
Merge pull request #37 from AlexNPavel/refactor/controller-runtime
*: forgot to add some new files...
2 parents 3c3e608 + 0fef2d2 commit 00bb736

File tree

276 files changed

+43759
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

276 files changed

+43759
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ARG BASEIMAGE
2+
FROM ${BASEIMAGE}
3+
ADD build/_output/bin/memcached-operator-test /usr/local/bin/memcached-operator-test
4+
ARG NAMESPACEDMAN
5+
ADD $NAMESPACEDMAN /namespaced.yaml
6+
ADD build/test-framework/go-test.sh /go-test.sh
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
memcached-operator-test -test.parallel=1 -test.failfast -root=/ -kubeconfig=incluster -namespacedMan=namespaced.yaml -test.v
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: memcached-operator
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: memcached-operator-test
5+
spec:
6+
restartPolicy: Never
7+
containers:
8+
- name: memcached-operator-test
9+
image: quay.io/example/memcached-operator:v0.0.1
10+
imagePullPolicy: Always
11+
command: ["/go-test.sh"]
12+
env:
13+
- name: TEST_NAMESPACE
14+
valueFrom:
15+
fieldRef:
16+
fieldPath: metadata.namespace
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2018 The Operator-SDK Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package e2e
16+
17+
import (
18+
"testing"
19+
20+
f "github.com/operator-framework/operator-sdk/pkg/test"
21+
)
22+
23+
func TestMain(m *testing.M) {
24+
f.MainEntry(m)
25+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
// Copyright 2018 The Operator-SDK Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package e2e
16+
17+
import (
18+
goctx "context"
19+
"fmt"
20+
"testing"
21+
"time"
22+
23+
apis "github.com/operator-framework/operator-sdk-samples/memcached-operator/pkg/apis"
24+
operator "github.com/operator-framework/operator-sdk-samples/memcached-operator/pkg/apis/cache/v1alpha1"
25+
26+
framework "github.com/operator-framework/operator-sdk/pkg/test"
27+
"github.com/operator-framework/operator-sdk/pkg/test/e2eutil"
28+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29+
"k8s.io/apimachinery/pkg/types"
30+
)
31+
32+
var (
33+
retryInterval = time.Second * 5
34+
timeout = time.Second * 60
35+
cleanupRetryInterval = time.Second * 1
36+
cleanupTimeout = time.Second * 5
37+
)
38+
39+
func TestMemcached(t *testing.T) {
40+
memcachedList := &operator.MemcachedList{
41+
TypeMeta: metav1.TypeMeta{
42+
Kind: "Memcached",
43+
APIVersion: "cache.example.com/v1alpha1",
44+
},
45+
}
46+
err := framework.AddToFrameworkScheme(apis.AddToScheme, memcachedList)
47+
if err != nil {
48+
t.Fatalf("failed to add custom resource scheme to framework: %v", err)
49+
}
50+
// run subtests
51+
t.Run("memcached-group", func(t *testing.T) {
52+
t.Run("Cluster", MemcachedCluster)
53+
t.Run("Cluster2", MemcachedCluster)
54+
})
55+
}
56+
57+
func memcachedScaleTest(t *testing.T, f *framework.Framework, ctx *framework.TestCtx) error {
58+
namespace, err := ctx.GetNamespace()
59+
if err != nil {
60+
return fmt.Errorf("could not get namespace: %v", err)
61+
}
62+
// create memcached custom resource
63+
exampleMemcached := &operator.Memcached{
64+
TypeMeta: metav1.TypeMeta{
65+
Kind: "Memcached",
66+
APIVersion: "cache.example.com/v1alpha1",
67+
},
68+
ObjectMeta: metav1.ObjectMeta{
69+
Name: "example-memcached",
70+
Namespace: namespace,
71+
},
72+
Spec: operator.MemcachedSpec{
73+
Size: 3,
74+
},
75+
}
76+
// use TestCtx's create helper to create the object and add a cleanup function for the new object
77+
err = f.Client.Create(goctx.TODO(), exampleMemcached, &framework.CleanupOptions{TestContext: ctx, Timeout: cleanupTimeout, RetryInterval: cleanupRetryInterval})
78+
if err != nil {
79+
return err
80+
}
81+
// wait for example-memcached to reach 3 replicas
82+
err = e2eutil.WaitForDeployment(t, f.KubeClient, namespace, "example-memcached", 3, retryInterval, timeout)
83+
if err != nil {
84+
return err
85+
}
86+
87+
err = f.Client.Get(goctx.TODO(), types.NamespacedName{Name: "example-memcached", Namespace: namespace}, exampleMemcached)
88+
if err != nil {
89+
return err
90+
}
91+
exampleMemcached.Spec.Size = 4
92+
err = f.Client.Update(goctx.TODO(), exampleMemcached)
93+
if err != nil {
94+
return err
95+
}
96+
97+
// wait for example-memcached to reach 4 replicas
98+
return e2eutil.WaitForDeployment(t, f.KubeClient, namespace, "example-memcached", 4, retryInterval, timeout)
99+
}
100+
101+
func MemcachedCluster(t *testing.T) {
102+
t.Parallel()
103+
ctx := framework.NewTestCtx(t)
104+
defer ctx.Cleanup()
105+
err := ctx.InitializeClusterResources(&framework.CleanupOptions{TestContext: ctx, Timeout: cleanupTimeout, RetryInterval: cleanupRetryInterval})
106+
if err != nil {
107+
t.Fatalf("failed to initialize cluster resources: %v", err)
108+
}
109+
t.Log("Initialized cluster resources")
110+
namespace, err := ctx.GetNamespace()
111+
if err != nil {
112+
t.Fatal(err)
113+
}
114+
// get global framework variables
115+
f := framework.Global
116+
// wait for memcached-operator to be ready
117+
err = e2eutil.WaitForDeployment(t, f.KubeClient, namespace, "memcached-operator", 1, retryInterval, timeout)
118+
if err != nil {
119+
t.Fatal(err)
120+
}
121+
122+
if err = memcachedScaleTest(t, f, ctx); err != nil {
123+
t.Fatal(err)
124+
}
125+
}

0 commit comments

Comments
 (0)