Skip to content

Commit 0a2046b

Browse files
Merge branch 'master' into label-selector-cli
2 parents f9aac56 + 8152452 commit 0a2046b

File tree

15 files changed

+166
-99
lines changed

15 files changed

+166
-99
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ The Index image powers the listing of the Operator on OperatorHub.
122122

123123
## Migrate from [Argo CD Community Operator](https://github.com/argoproj-labs/argocd-operator) to GitOps Operator
124124

125-
Please follow the steps mentioned in the doc to migrate from [Argo CD Community Operator](https://github.com/argoproj-labs/argocd-operator) to GitOps Operator.
125+
Please follow the [migration guide](https://github.com/redhat-developer/gitops-operator/blob/master/docs/Migration_Guide.md) when moving from the [Argo CD Community Operator](https://github.com/argoproj-labs/argocd-operator) to the GitOps Operator.
126126

127127
## Progressive Delivery
128128

controllers/argocd_controller.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ import (
4545
)
4646

4747
const (
48-
argocdNS = "openshift-gitops"
49-
depracatedArgoCDNS = "openshift-pipelines-app-delivery"
50-
consoleLinkName = "argocd"
51-
argocdRouteName = "openshift-gitops-server"
52-
iconFilePath = "/argo.png"
48+
argocdNS = "openshift-gitops"
49+
depracatedArgoCDNS = "openshift-pipelines-app-delivery"
50+
consoleLinkName = "argocd"
51+
argocdRouteName = "openshift-gitops-server"
52+
iconFilePath = "/argo.png"
53+
operatorPodNamespacePath = "/var/run/secrets/kubernetes.io/serviceaccount/namespace"
5354
)
5455

5556
var (

controllers/argocd_metrics_controller.go

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"embed"
2222
"fmt"
23+
"os"
2324
"path/filepath"
2425
"strings"
2526

@@ -41,11 +42,13 @@ import (
4142
)
4243

4344
const (
44-
readRoleNameFormat = "%s-read"
45-
readRoleBindingNameFormat = "%s-prometheus-k8s-read-binding"
46-
alertRuleName = "gitops-operator-argocd-alerts"
47-
dashboardNamespace = "openshift-config-managed"
48-
dashboardFolder = "dashboards"
45+
readRoleNameFormat = "%s-read"
46+
readRoleBindingNameFormat = "%s-prometheus-k8s-read-binding"
47+
alertRuleName = "gitops-operator-argocd-alerts"
48+
dashboardNamespace = "openshift-config-managed"
49+
dashboardFolder = "dashboards"
50+
operatorMetricsServiceName = "openshift-gitops-operator-metrics-service"
51+
operatorMetricsMonitorName = "openshift-gitops-operator-metrics-monitor"
4952
)
5053

5154
type ArgoCDMetricsReconciler struct {
@@ -170,6 +173,11 @@ func (r *ArgoCDMetricsReconciler) Reconcile(ctx context.Context, request reconci
170173
return reconcile.Result{}, err
171174
}
172175

176+
err = r.reconcileOperatorMetricsServiceMonitor(reqLogger)
177+
if err != nil {
178+
return reconcile.Result{}, err
179+
}
180+
173181
return reconcile.Result{}, nil
174182
}
175183

@@ -274,6 +282,38 @@ func (r *ArgoCDMetricsReconciler) createServiceMonitorIfAbsent(namespace string,
274282
return err
275283
}
276284

285+
func (r *ArgoCDMetricsReconciler) reconcileOperatorMetricsServiceMonitor(reqLogger logr.Logger) error {
286+
287+
data, err := os.ReadFile(operatorPodNamespacePath)
288+
if err != nil {
289+
reqLogger.Error(err, "Error retrieving operator's running namespace")
290+
return err
291+
}
292+
293+
operatorNS := string(data)
294+
desiredMetricsServerName := operatorMetricsServiceName + "." + operatorNS + ".svc"
295+
296+
existingServiceMonitor := &monitoringv1.ServiceMonitor{}
297+
err = r.Client.Get(context.TODO(), types.NamespacedName{Name: operatorMetricsMonitorName, Namespace: operatorNS}, existingServiceMonitor)
298+
299+
if err != nil {
300+
if !errors.IsNotFound(err) {
301+
reqLogger.Error(err, "Error querying for ServiceMonitor", "Namespace", operatorNS, "Name", operatorMetricsMonitorName)
302+
return err
303+
}
304+
305+
// no svc monitor found, nothing to do
306+
return nil
307+
}
308+
309+
if existingServiceMonitor.Spec.Endpoints[0].TLSConfig.ServerName != desiredMetricsServerName {
310+
existingServiceMonitor.Spec.Endpoints[0].TLSConfig.ServerName = desiredMetricsServerName
311+
return r.Client.Update(context.TODO(), existingServiceMonitor)
312+
}
313+
314+
return nil
315+
}
316+
277317
func (r *ArgoCDMetricsReconciler) createPrometheusRuleIfAbsent(namespace string, argocd *argoapp.ArgoCD, reqLogger logr.Logger) error {
278318
alertRule := newPrometheusRule(namespace)
279319
existingAlertRule := &monitoringv1.PrometheusRule{}

scripts/e2e-common.sh

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ function unexpectedError() {
2525
echo "Unexpected error occured!!"
2626
failed=1
2727

28-
(( failed )) && fail_test
28+
((failed)) && fail_test
2929
success
30-
}
30+
}
3131

3232
function make_banner() {
33-
local msg="$1$1$1$1 $2 $1$1$1$1"
34-
local border="${msg//[-0-9A-Za-z _.,\/()]/$1}"
35-
echo -e "${border}\n${msg}\n${border}"
33+
local msg="$1$1$1$1 $2 $1$1$1$1"
34+
local border="${msg//[-0-9A-Za-z _.,\/()]/$1}"
35+
echo -e "${border}\n${msg}\n${border}"
3636
}
3737

3838
# Simple header for logging purposes.
@@ -43,22 +43,26 @@ function header() {
4343

4444
function wait_until_pods_running() {
4545
echo -n "Waiting until all pods in namespace $1 are up"
46-
for i in {1..150}; do # timeout after 5 minutes
46+
for i in {1..150}; do # timeout after 5 minutes
4747
local pods="$(oc get pods --no-headers -n $1 2>/dev/null)"
48+
# write it to tempfile
49+
TempFile=$(mktemp)
50+
oc get pods --no-headers -n $1 2>/dev/null >$TempFile
51+
4852
# All pods must be running
4953
local not_running=$(echo "${pods}" | grep -v Running | grep -v Completed | wc -l)
5054
if [[ -n "${pods}" && ${not_running} -eq 0 ]]; then
5155
local all_ready=1
52-
while read pod ; do
53-
local status=(`echo -n ${pod} | cut -f2 -d' ' | tr '/' ' '`)
56+
while read pod; do
57+
local status=($(echo ${pod} | cut -f2 -d' ' | tr '/' ' '))
5458
# All containers must be ready
5559
[[ -z ${status[0]} ]] && all_ready=0 && break
5660
[[ -z ${status[1]} ]] && all_ready=0 && break
5761
[[ ${status[0]} -lt 1 ]] && all_ready=0 && break
5862
[[ ${status[1]} -lt 1 ]] && all_ready=0 && break
5963
[[ ${status[0]} -ne ${status[1]} ]] && all_ready=0 && break
60-
done <<< $(echo "${pods}" | grep -v Completed)
61-
if (( all_ready )); then
64+
done <${TempFile}
65+
if ((all_ready)); then
6266
echo -e "\nAll pods are up:\n${pods}"
6367
return 0
6468
fi
@@ -79,8 +83,8 @@ function wait_until_object_exist() {
7983
DESCRIPTION="$1 $3/$2"
8084
fi
8185
echo -n "Waiting until ${DESCRIPTION} exist"
82-
for i in {1..150}; do # timeout after 5 minutes
83-
if oc ${oc_ARGS} > /dev/null 2>&1; then
86+
for i in {1..150}; do # timeout after 5 minutes
87+
if oc ${oc_ARGS} >/dev/null 2>&1; then
8488
echo -e "\n${DESCRIPTION} exist"
8589
return 0
8690
fi
@@ -101,8 +105,8 @@ function wait_until_object_doesnt_exist() {
101105
DESCRIPTION="$1 $3/$2"
102106
fi
103107
echo -n "Waiting until ${DESCRIPTION} doesn't exist"
104-
for i in {1..150}; do # timeout after 5 minutes
105-
if ! kubectl ${KUBECTL_ARGS} > /dev/null 2>&1; then
108+
for i in {1..150}; do # timeout after 5 minutes
109+
if ! kubectl ${KUBECTL_ARGS} >/dev/null 2>&1; then
106110
echo -e "\n${DESCRIPTION} dosen't exist"
107111
return 0
108112
fi
@@ -137,7 +141,6 @@ function dump_extra_cluster_state() {
137141
kubectl -n openshift-gitops-operator logs $(get_app_pod argocd-operator openshift-gitops-operator) --all-containers=true
138142
}
139143

140-
141144
# Returns the name of the first pod of the given app.
142145
# Parameters: $1 - app name.
143146
# $2 - namespace (optional).
@@ -161,7 +164,6 @@ function fail_test() {
161164
exit 1
162165
}
163166

164-
165167
function set_test_return_code() {
166168
echo -n "$1"
167169
}
@@ -176,13 +178,13 @@ function success() {
176178
exit 0
177179
}
178180

179-
function build_and_push_catalog_image(){
180-
181+
function build_and_push_catalog_image() {
182+
181183
if [ "$E2E_SKIP_BUILD_TOOL_INSTALLATION" = false ]; then
182-
echo ">> Install operator-sdk & opm"
183-
make operator-sdk opm
184+
echo ">> Install operator-sdk & opm"
185+
make operator-sdk opm
184186
else
185-
echo ">> skipping operator-sdk & olm installation"
187+
echo ">> skipping operator-sdk & olm installation"
186188
fi
187189

188190
echo ">> Building and pushing operator images"
@@ -199,15 +201,15 @@ function build_and_push_catalog_image(){
199201

200202
}
201203

202-
function configure_operator(){
204+
function configure_operator() {
203205
header "Configuring OpenShift Gitops operator"
204206

205207
echo -e "Disabling default catalog sources"
206208
kubectl patch operatorhub.config.openshift.io/cluster -p='{"spec":{"disableAllDefaultSources":true}}' --type=merge
207209
sleep 5
208210

209211
# echo -e "Copying artifacts [catalog source, image content source policy, mapping.txt]..."
210-
cat <<EOF > $TMP_DIR/catalog-source.yaml
212+
cat <<EOF >$TMP_DIR/catalog-source.yaml
211213
apiVersion: operators.coreos.com/v1alpha1
212214
kind: CatalogSource
213215
metadata:
@@ -222,18 +224,17 @@ spec:
222224
interval: 30m
223225
EOF
224226

225-
226227
echo -e "Creating custom catalog source"
227228
kubectl apply -f $TMP_DIR/catalog-source.yaml
228229

229230
echo "Waiting for pods in namespace openshift-marketplace to be ready"
230231
# filtering out old catalog source pod that will be removed shortly
231-
pods=$(kubectl get pods -n openshift-marketplace --sort-by={metadata.creationTimestamp} -o name | \
232-
grep gitops-operator | tail -1)
232+
pods=$(kubectl get pods -n openshift-marketplace --sort-by={metadata.creationTimestamp} -o name |
233+
grep gitops-operator | tail -1)
233234

234235
for pod in ${pods}; do
235-
echo "Waiting for pod $pod in openshift-marketplace to be in ready state"
236-
kubectl wait --for=condition=Ready -n openshift-marketplace $pod --timeout=5m
236+
echo "Waiting for pod $pod in openshift-marketplace to be in ready state"
237+
kubectl wait --for=condition=Ready -n openshift-marketplace $pod --timeout=5m
237238
done
238239
}
239240

@@ -251,29 +252,29 @@ function uninstall_operator_resources() {
251252
oc wait --for=delete $deployment -n openshift-gitops --timeout=5m || fail_test "Failed to delete deployment: $deployment in openshift-gitops namespace"
252253
done
253254

254-
oc delete $(oc get csv -n openshift-gitops-operator -o name|grep gitops) -n openshift-gitops-operator || fail_test "Unable to delete CSV"
255+
oc delete $(oc get csv -n openshift-gitops-operator -o name | grep gitops) -n openshift-gitops-operator || fail_test "Unable to delete CSV"
255256

256257
oc delete -n openshift-gitops-operator installplan $(oc get subscription gitops-operator -n openshift-gitops-operator -o jsonpath='{.status.installplan.name}') || fail_test "Unable to delete installplan"
257258

258259
oc delete subscription gitops-operator -n openshift-gitops-operator --cascade=background || fail_test "Unable to delete subscription"
259260

260261
echo -e ">> Delete arogo resources accross all namespaces"
261262
for res in applications applicationsets appprojects argocds; do
262-
oc delete --ignore-not-found=true ${res}.argoproj.io --all
263+
oc delete --ignore-not-found=true ${res}.argoproj.io --all
263264
done
264265

265266
echo -e ">> Cleanup existing crds"
266267
for res in applications applicationsets appprojects argocds; do
267-
oc delete --ignore-not-found=true crds ${res}.argoproj.io
268+
oc delete --ignore-not-found=true crds ${res}.argoproj.io
268269
done
269270

270271
echo -e ">> Delete \"openshift-gitops\" project"
271272
oc delete --ignore-not-found=true project openshift-gitops
272273
}
273274

274275
function install_operator_resources() {
275-
echo -e ">>Ensure Gitops subscription exists"
276-
oc get subscription gitops-operator -n openshift-gitops-operator 2>/dev/null || \
276+
echo -e ">>Ensure Gitops subscription exists"
277+
oc get subscription gitops-operator -n openshift-gitops-operator 2>/dev/null ||
277278
cat <<EOF | oc apply -f -
278279
apiVersion: operators.coreos.com/v1alpha1
279280
kind: Subscription
@@ -287,24 +288,23 @@ spec:
287288
source: $CATALOG_SOURCE
288289
sourceNamespace: openshift-marketplace
289290
EOF
290-
291-
wait_until_pods_running "openshift-gitops-operator" || fail_test "openshift gitops Operator controller did not come up"
292291

293-
echo ">> Wait for GitopsService creation"
294-
wait_until_object_exist "gitopsservices.pipelines.openshift.io" "cluster" "openshift-gitops" || fail_test "gitops service haven't created yet"
292+
wait_until_pods_running "openshift-gitops-operator" || fail_test "openshift gitops Operator controller did not come up"
293+
294+
echo ">> Wait for GitopsService creation"
295+
wait_until_object_exist "gitopsservices.pipelines.openshift.io" "cluster" "openshift-gitops" || fail_test "gitops service haven't created yet"
295296

296-
wait_until_pods_running "openshift-gitops" || fail_test "argocd controller did not come up"
297+
wait_until_pods_running "openshift-gitops" || fail_test "argocd controller did not come up"
297298

298-
299-
#Make sure that everything is cleaned up in the current namespace.
300-
for res in applications applicationsets appprojects appprojects; do
301-
oc delete --ignore-not-found=true ${res}.argoproj.io --all
302-
done
299+
#Make sure that everything is cleaned up in the current namespace.
300+
for res in applications applicationsets appprojects appprojects; do
301+
oc delete --ignore-not-found=true ${res}.argoproj.io --all
302+
done
303303
}
304304

305305
function get_operator_namespace() {
306306
# TODO: parameterize namespace, operator can run in a namespace different from the namespace where tektonpipelines is installed
307307
local operator_namespace="argocd-operator"
308308
[[ "${TARGET}" == "openshift" ]] && operator_namespace="openshift-gitops"
309309
echo ${operator_namespace}
310-
}
310+
}

test/openshift/e2e/ignore-tests/sequential/1-064_validate_tcp_reset_error/03-wait.yaml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,26 @@ commands:
55
- script: |
66
function wait_until_pods_running() {
77
echo -n "Waiting until all pods in namespace $1 are up"
8-
for i in {1..150}; do # timeout after 5 minutes
8+
for i in {1..150}; do # timeout after 5 minutes
99
local pods="$(oc get pods --no-headers -n $1 2>/dev/null)"
10+
# write it to tempfile
11+
TempFile=$(mktemp)
12+
oc get pods --no-headers -n $1 2>/dev/null >$TempFile
13+
1014
# All pods must be running
1115
local not_running=$(echo "${pods}" | grep -v Running | grep -v Completed | wc -l)
1216
if [[ -n "${pods}" && ${not_running} -eq 0 ]]; then
1317
local all_ready=1
14-
while read pod ; do
15-
local status=(`echo -n ${pod} | cut -f2 -d' ' | tr '/' ' '`)
18+
while read pod; do
19+
local status=($(echo ${pod} | cut -f2 -d' ' | tr '/' ' '))
1620
# All containers must be ready
1721
[[ -z ${status[0]} ]] && all_ready=0 && break
1822
[[ -z ${status[1]} ]] && all_ready=0 && break
1923
[[ ${status[0]} -lt 1 ]] && all_ready=0 && break
2024
[[ ${status[1]} -lt 1 ]] && all_ready=0 && break
2125
[[ ${status[0]} -ne ${status[1]} ]] && all_ready=0 && break
22-
done <<< $(echo "${pods}" | grep -v Completed)
23-
if (( all_ready )); then
26+
done <${TempFile}
27+
if ((all_ready)); then
2428
echo -e "\nAll pods are up:\n${pods}"
2529
return 0
2630
fi

test/openshift/e2e/parallel/1-008_validate-custom-argocd-namespace/02-wait.yaml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,26 @@ commands:
55
- script: |
66
function wait_until_pods_running() {
77
echo -n "Waiting until all pods in namespace $1 are up"
8-
for i in {1..150}; do # timeout after 5 minutes
8+
for i in {1..150}; do # timeout after 5 minutes
99
local pods="$(oc get pods --no-headers -n $1 2>/dev/null)"
10+
# write it to tempfile
11+
TempFile=$(mktemp)
12+
oc get pods --no-headers -n $1 2>/dev/null >$TempFile
13+
1014
# All pods must be running
1115
local not_running=$(echo "${pods}" | grep -v Running | grep -v Completed | wc -l)
1216
if [[ -n "${pods}" && ${not_running} -eq 0 ]]; then
1317
local all_ready=1
14-
while read pod ; do
15-
local status=(`echo -n ${pod} | cut -f2 -d' ' | tr '/' ' '`)
18+
while read pod; do
19+
local status=($(echo ${pod} | cut -f2 -d' ' | tr '/' ' '))
1620
# All containers must be ready
1721
[[ -z ${status[0]} ]] && all_ready=0 && break
1822
[[ -z ${status[1]} ]] && all_ready=0 && break
1923
[[ ${status[0]} -lt 1 ]] && all_ready=0 && break
2024
[[ ${status[1]} -lt 1 ]] && all_ready=0 && break
2125
[[ ${status[0]} -ne ${status[1]} ]] && all_ready=0 && break
22-
done <<< $(echo "${pods}" | grep -v Completed)
23-
if (( all_ready )); then
26+
done <${TempFile}
27+
if ((all_ready)); then
2428
echo -e "\nAll pods are up:\n${pods}"
2529
return 0
2630
fi

0 commit comments

Comments
 (0)