forked from redhat-developer/gitops-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1-031_validate_toolchain_test.go
More file actions
190 lines (147 loc) · 6.73 KB
/
1-031_validate_toolchain_test.go
File metadata and controls
190 lines (147 loc) · 6.73 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
Copyright 2025.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package parallel
import (
"context"
"os"
// "os"
"strings"
"time"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
routev1 "github.com/openshift/api/route/v1"
"github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture"
k8sFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/k8s"
osFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/os"
fixtureUtils "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"sigs.k8s.io/controller-runtime/pkg/client"
)
var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
Context("1-031_validate_toolchain", func() {
var (
k8sClient client.Client
)
BeforeEach(func() {
fixture.EnsureParallelCleanSlate()
k8sClient, _ = fixtureUtils.GetE2ETestKubeClient()
})
// getPodName waits for there to exist a running pod with name 'name' in openshift-gitops
getPodName := func(name string) (string, error) {
var podName string
if err := wait.PollUntilContextTimeout(context.Background(), time.Second*5, time.Minute*2, true, func(ctx context.Context) (done bool, err error) {
var podList corev1.PodList
if err := k8sClient.List(ctx, &podList, client.InNamespace("openshift-gitops")); err != nil {
GinkgoWriter.Println(err)
return false, nil
}
for _, pod := range podList.Items {
if pod.Status.Phase == corev1.PodRunning {
if strings.Contains(pod.Name, name) {
podName = pod.Name
return true, nil
}
}
}
return false, nil
}); err != nil {
return "", err
}
return podName, nil
}
It("verifies that toolchain versions have the expected values", func() {
// These variables need to be maintained according to the component matrix: https://spaces.redhat.com/display/GITOPS/GitOps+Component+Matrix
expected_kustomizeVersion := "v5.8.1"
expected_helmVersion := "v3.19.4"
expected_argocdVersion := "v3.3.2"
var expected_dexVersion string
var expected_redisVersion string
if os.Getenv("CI") == "prow" {
// when running against openshift-ci
expected_dexVersion = "v2.43.0"
expected_redisVersion = "8.2.3"
} else {
// when running against RC/ released version of gitops
expected_dexVersion = "v2.43.1"
expected_redisVersion = "7.2.11"
}
By("locating pods containing toolchain in openshift-gitops")
gitops_server_pod, err := getPodName("openshift-gitops-server")
Expect(err).ToNot(HaveOccurred())
dex_pod, err := getPodName("openshift-gitops-dex-server")
Expect(err).ToNot(HaveOccurred())
redis_pod, err := getPodName("openshift-gitops-redis")
Expect(err).ToNot(HaveOccurred())
serverRoute := &routev1.Route{ObjectMeta: metav1.ObjectMeta{Name: "openshift-gitops-server", Namespace: "openshift-gitops"}}
Eventually(serverRoute).Should(k8sFixture.ExistByName())
By("extracting the kustomize version from container")
kustomizeVersion, err := osFixture.ExecCommand("bash", "-c", "oc -n openshift-gitops exec "+gitops_server_pod+" -- kustomize version")
Expect(err).NotTo(HaveOccurred())
kustomizeVersion = strings.TrimSpace(kustomizeVersion)
By("extracting the helm version from container")
helmVersion, err := osFixture.ExecCommand("bash", "-c", "oc -n openshift-gitops exec "+gitops_server_pod+" -- helm version")
Expect(err).NotTo(HaveOccurred())
// output format:
// version.BuildInfo{Version:"v3.15.4", GitCommit:"fa9efb07d9d8debbb4306d72af76a383895aa8c4", GitTreeState:"", GoVersion:"go1.22.9 (Red Hat 1.22.9-1.module+el8.10.0+22500+aee717ef)"
helmVersion = helmVersion[strings.Index(helmVersion, "Version:"):]
// After: Version:"v3.15.4" (...)
helmVersion = helmVersion[strings.Index(helmVersion, "\"")+1:]
// After: v3.15.4" (...)
helmVersion = helmVersion[:strings.Index(helmVersion, "\"")]
// After: v3.15.4
By("extracting the argo cd server version from container")
argocdVersion, err := osFixture.ExecCommand("bash", "-c", "oc -n openshift-gitops exec "+gitops_server_pod+" -- argocd version --short --server "+serverRoute.Spec.Host+" --insecure | grep 'argocd-server'")
argocdVersion = strings.ReplaceAll(argocdVersion, "+unknown", "")
// output format:
// argocd-server: v2.13.1+af54ef8
Expect(err).NotTo(HaveOccurred())
By("extracting the dex version from container")
dexVersionOutput, err := osFixture.ExecCommand("bash", "-c", "oc -n openshift-gitops exec "+dex_pod+" -- dex version")
Expect(err).ToNot(HaveOccurred())
// Output format:
// Defaulted container "dex" out of: dex, copyutil (init)
// Dex Version: v2.41.1-1-ga7854d65
var dexVersion string
dexVersionOutputSplit := strings.Split(dexVersionOutput, "\n")
for _, line := range dexVersionOutputSplit {
if strings.Contains(line, "Dex Version:") {
dexVersion = line
dexVersion = dexVersion[strings.Index(dexVersion, ":")+1:]
// After: ' v2.41.1-1-ga7854d65'
dexVersion = strings.TrimSpace(dexVersion)
// After: 'v2.41.1-1-ga7854d65'
break
}
}
Expect(dexVersion).ToNot(BeEmpty())
By("extracting the redis version from container")
redisVersion, err := osFixture.ExecCommand("bash", "-c", "oc -n openshift-gitops exec "+redis_pod+" -- redis-server -v")
// output format: Redis server v=6.2.7 sha=00000000:0 malloc=jemalloc-5.1.0 bits=64 build=5d88ce217879027a
redisVersion = redisVersion[strings.Index(redisVersion, "v=")+2:]
// After: v=6.2.7 (...)
redisVersion = redisVersion[0:strings.Index(redisVersion, " ")]
// After: v=6.2.7
Expect(err).NotTo(HaveOccurred())
By("verifying containers have expected toolchain versions")
Expect(kustomizeVersion).To(Equal(expected_kustomizeVersion))
Expect(helmVersion).To(Equal(expected_helmVersion))
Expect(dexVersion).To(Equal(expected_dexVersion))
// We are as argocdVersion contains v2.7.6+00c914a suffix addition to the version no.
// So, we are checking if expected_argocdVersion is substring of the actual version
Expect(argocdVersion).To(ContainSubstring(expected_argocdVersion))
Expect(redisVersion).To(Equal(expected_redisVersion))
})
})
})