|
| 1 | +// |
| 2 | +// DISCLAIMER |
| 3 | +// |
| 4 | +// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany |
| 5 | +// |
| 6 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +// you may not use this file except in compliance with the License. |
| 8 | +// You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | +// |
| 18 | +// Copyright holder is ArangoDB GmbH, Cologne, Germany |
| 19 | +// |
| 20 | + |
| 21 | +package storage |
| 22 | + |
| 23 | +import ( |
| 24 | + "context" |
| 25 | + "testing" |
| 26 | + |
| 27 | + api "github.com/arangodb/kube-arangodb/pkg/apis/storage/v1alpha" |
| 28 | + "github.com/arangodb/kube-arangodb/pkg/util/kclient" |
| 29 | + |
| 30 | + "github.com/stretchr/testify/require" |
| 31 | + v1 "k8s.io/api/core/v1" |
| 32 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 33 | +) |
| 34 | + |
| 35 | +// TestEnsureDaemonSet tests ensureDaemonSet() method |
| 36 | +func TestEnsureDaemonSet(t *testing.T) { |
| 37 | + testNamespace := "testNs" |
| 38 | + testLsName := "testDsName" |
| 39 | + |
| 40 | + testPodName := "testPodName" |
| 41 | + testImage := "test-image" |
| 42 | + |
| 43 | + testPullSecrets := []v1.LocalObjectReference{ |
| 44 | + { |
| 45 | + Name: "custom-docker", |
| 46 | + }, |
| 47 | + } |
| 48 | + |
| 49 | + ls := &LocalStorage{ |
| 50 | + apiObject: &api.ArangoLocalStorage{ |
| 51 | + ObjectMeta: metav1.ObjectMeta{ |
| 52 | + Name: testLsName, |
| 53 | + Namespace: testNamespace, |
| 54 | + }, |
| 55 | + Spec: api.LocalStorageSpec{}, |
| 56 | + }, |
| 57 | + deps: Dependencies{ |
| 58 | + Client: kclient.NewFakeClient(), |
| 59 | + }, |
| 60 | + config: Config{ |
| 61 | + Namespace: testNamespace, |
| 62 | + PodName: testPodName, |
| 63 | + }, |
| 64 | + image: testImage, |
| 65 | + imagePullSecrets: testPullSecrets, |
| 66 | + imagePullPolicy: v1.PullAlways, |
| 67 | + } |
| 68 | + |
| 69 | + err := ls.ensureDaemonSet(ls.apiObject) |
| 70 | + require.NoError(t, err) |
| 71 | + |
| 72 | + // verify if DaemonSet has been created with correct values |
| 73 | + ds, err := ls.deps.Client.Kubernetes().AppsV1().DaemonSets(testNamespace).Get(context.Background(), testLsName, metav1.GetOptions{}) |
| 74 | + require.NoError(t, err) |
| 75 | + |
| 76 | + pod := ds.Spec.Template.Spec |
| 77 | + |
| 78 | + require.Equal(t, ds.GetName(), testLsName) |
| 79 | + require.Equal(t, pod.ImagePullSecrets, testPullSecrets) |
| 80 | + require.Equal(t, len(pod.Containers), 1) |
| 81 | + |
| 82 | + c := pod.Containers[0] |
| 83 | + require.Equal(t, c.Image, testImage) |
| 84 | + require.Equal(t, c.ImagePullPolicy, v1.PullAlways) |
| 85 | +} |
0 commit comments