-
Notifications
You must be signed in to change notification settings - Fork 129
/
util.go
140 lines (125 loc) · 5.35 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package e2e
import (
"context"
"reflect"
"testing"
"time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
consoleapi "github.com/openshift/console-operator/pkg/api"
"github.com/openshift/console-operator/test/e2e/framework"
)
// Each of these tests helpers are similar, they only vary in the
// resource they are GETting and PATCHing.
// After the patch is done the test will poll the given resource.
// In case the console-operator is Managed state the patched data should
// not be equal to the one obtained after patch is applied.
// In case the console-operator is Unmanaged state the patched data should
// be equal to the one obtained after patch is applied.
var pollTimeout = 10 * time.Second
func patchAndCheckConfigMap(t *testing.T, client *framework.ClientSet, isOperatorManaged bool) error {
t.Logf("patching Data on the console ConfigMap")
configMap, err := client.Core.ConfigMaps(consoleapi.OpenShiftConsoleNamespace).Patch(context.TODO(), consoleapi.OpenShiftConsoleConfigMapName, types.MergePatchType, []byte(`{"data": {"console-config.yaml": "test"}}`), metav1.PatchOptions{})
if err != nil {
return err
}
patchedData := configMap.Data
t.Logf("polling for patched Data on the console ConfigMap")
err = wait.Poll(1*time.Second, pollTimeout, func() (stop bool, err error) {
configMap, err = framework.GetConsoleConfigMap(client)
if err != nil {
return true, err
}
newData := configMap.Data
if isOperatorManaged {
return !reflect.DeepEqual(patchedData, newData), nil
}
return reflect.DeepEqual(patchedData, newData), nil
})
return err
}
func patchAndCheckService(t *testing.T, client *framework.ClientSet, isOperatorManaged bool) error {
t.Logf("patching Annotation on the console Service")
service, err := client.Core.Services(consoleapi.OpenShiftConsoleNamespace).Patch(context.TODO(), consoleapi.OpenShiftConsoleServiceName, types.MergePatchType, []byte(`{"metadata": {"annotations": {"service.beta.openshift.io/serving-cert-secret-name": "test"}}}`), metav1.PatchOptions{})
if err != nil {
return err
}
patchedData := service.GetAnnotations()
t.Logf("polling for patched Annotation on the console Service")
err = wait.Poll(1*time.Second, pollTimeout, func() (stop bool, err error) {
service, err = framework.GetConsoleService(client)
if err != nil {
return true, err
}
newData := service.GetAnnotations()
if isOperatorManaged {
return !reflect.DeepEqual(patchedData, newData), nil
}
return reflect.DeepEqual(patchedData, newData), nil
})
return err
}
func patchAndCheckRoute(t *testing.T, client *framework.ClientSet, isOperatorManaged bool) error {
t.Logf("patching Host on the console Route")
route, err := client.Routes.Routes(consoleapi.OpenShiftConsoleNamespace).Patch(context.TODO(), consoleapi.OpenShiftConsoleRouteName, types.MergePatchType, []byte(`{"spec": {"host": "test.host"}}`), metav1.PatchOptions{})
if err != nil {
return err
}
patchedData := route.Spec.Host
t.Logf("polling for patched Host on the console Route")
err = wait.Poll(1*time.Second, pollTimeout, func() (stop bool, err error) {
route, err = framework.GetConsoleRoute(client)
if err != nil {
return true, err
}
newData := route.Spec.Host
if isOperatorManaged {
return !reflect.DeepEqual(patchedData, newData), nil
}
return reflect.DeepEqual(patchedData, newData), nil
})
return err
}
func patchAndCheckConsoleCLIDownloads(t *testing.T, client *framework.ClientSet, isOperatorManaged bool, consoleCLIDownloadName string) error {
t.Logf("patching DisplayName on the %s ConsoleCLIDownloads custom resource", consoleCLIDownloadName)
consoleCLIDownload, err := client.ConsoleCliDownloads.Patch(context.TODO(), consoleCLIDownloadName, types.MergePatchType, []byte(`{"spec": {"displayName": "test"}}`), metav1.PatchOptions{})
if err != nil {
return err
}
patchedData := consoleCLIDownload.Spec.DisplayName
t.Logf("polling for patched DisplayName on the %s ConsoleCLIDownloads custom resource", consoleCLIDownloadName)
err = wait.Poll(1*time.Second, pollTimeout, func() (stop bool, err error) {
consoleCLIDownload, err = framework.GetConsoleCLIDownloads(client, consoleCLIDownloadName)
if err != nil {
return true, err
}
newData := consoleCLIDownload.Spec.DisplayName
if isOperatorManaged {
return !reflect.DeepEqual(patchedData, newData), nil
}
return reflect.DeepEqual(patchedData, newData), nil
})
return err
}
func patchAndCheckPodDisruptionBudget(t *testing.T, client *framework.ClientSet, isOperatorManaged bool, pdbName string) error {
t.Logf("patching MaxUnavailable on the %q PodDisruptionBudget", pdbName)
pdb, err := client.PodDisruptionBudget.PodDisruptionBudgets(consoleapi.OpenShiftConsoleNamespace).Patch(context.TODO(), pdbName, types.MergePatchType, []byte(`{"spec": { "maxUnavailable": 2}}`), metav1.PatchOptions{})
if err != nil {
return err
}
patchedData := pdb.Spec.MaxUnavailable
t.Logf("polling for patched MaxUnavailable on the %q PodDisruptionBudget", pdbName)
err = wait.Poll(1*time.Second, pollTimeout, func() (stop bool, err error) {
pdb, err = framework.GetConsolePodDisruptionBudget(client, pdbName)
if err != nil {
return true, err
}
newData := pdb.Spec.MaxUnavailable
if isOperatorManaged {
return !reflect.DeepEqual(patchedData, newData), nil
}
return reflect.DeepEqual(patchedData, newData), nil
})
return err
}