Skip to content

Commit

Permalink
refactor ansible integration (#376)
Browse files Browse the repository at this point in the history
Signed-off-by: Xiangjing Li <xiangli@redhat.com>
  • Loading branch information
xiangjingli committed Dec 19, 2023
1 parent 8b5df27 commit 0167248
Show file tree
Hide file tree
Showing 24 changed files with 782 additions and 372 deletions.
34 changes: 26 additions & 8 deletions build/e2e-kc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,24 @@ echo "STARTING test case 06-ansiblejob-post"
kubectl config use-context kind-hub
kubectl apply -f hack/test/tower.ansible.com_ansiblejobs_crd.yaml
kubectl apply -f test/e2e/cases/06-ansiblejob-post/
sleep 30
sleep 70

if kubectl get subscriptions.apps.open-cluster-management.io ansible-hook -o yaml | grep lastposthookjob | grep posthook-test; then
echo "06-ansiblejob-post: found ansiblejob CR name in subscription output"
else
echo "06-ansiblejob-post: FAILED: ansiblejob CR name is not in the subscription output"
exit 1
fi


kubectl get pods -n open-cluster-management
kubectl logs -n open-cluster-management -l app=multicluster-operators-hub-subscription

kubectl get placementdecisions -n default -o yaml
kubectl get appsub -n default ansible-hook -o yaml
kubectl get appsubreport -n default ansible-hook -o yaml
kubectl get appsubreport -n cluster1 cluster1 -o yaml

if kubectl get ansiblejobs.tower.ansible.com | grep posthook-test; then
echo "06-ansiblejob-post: found ansiblejobs.tower.ansible.com"
else
Expand Down Expand Up @@ -473,7 +483,7 @@ echo "STARTING test case 17-ansiblejob-pre-workflow"
kubectl config use-context kind-hub
kubectl apply -f hack/test/tower.ansible.com_ansiblejobs_crd.yaml
kubectl apply -f test/e2e/cases/17-ansiblejob-pre-workflow/
sleep 10
sleep 40

if kubectl get subscriptions.apps.open-cluster-management.io ansible-hook -o yaml | grep lastprehookjob | grep prehook-workflow-test; then
echo "17-ansiblejob-pre-workflow: found ansiblejob CR name in subscription output"
Expand Down Expand Up @@ -548,18 +558,26 @@ fi
echo "19-verify-git-pull-time-metric: patching successful subscription and expeting failed metrics"
kubectl config use-context kind-hub
kubectl apply -f test/e2e/cases/19-verify-git-pull-time-metric/failed
# with high reconcile rate, the updated appsub is handled every 2 minutes. Wait for over 2 minutes to make sure the updated appsub is handled
sleep 140
# deliver an appsub with invalid channel info, it is expected to get the failure once the appsub is deployed on the managed cluster
sleep 30

echo "19-verify-git-pull-time-metric: fetching failed managed cluster metrics"
kubectl config use-context kind-cluster1
collectedFailedMcMetrics=`kubectl exec -n open-cluster-management-agent-addon deploy/application-manager -- curl http://localhost:8388/metrics`
# FAILED metrics test
IFS=' ' read -a failedPullTimeCount <<< $(echo "$collectedFailedMcMetrics" | grep "subscription_name=\"git-pull-time-metric-sub\"" | grep git_failed_pull_time_count)
IFS=' ' read -a failedPullTimeSum <<< $(echo "$collectedFailedMcMetrics" | grep "subscription_name=\"git-pull-time-metric-sub\"" | grep git_failed_pull_time_sum)
IFS=' ' read -a failedPullTimeCount <<< $(echo "$collectedFailedMcMetrics" | grep "subscription_name=\"git-pull-time-metric-sub-failed\"" | grep git_failed_pull_time_count)

echo "============"
echo "19-verify-git-pull-time-metric: verifying expected git_failed_pull_time metrics for succesful subscription"
if [ "${failedPullTimeCount[1]}" \> 0 ] && [ "${failedPullTimeSum[1]}" \> 100 ] ; then

echo "$collectedFailedMcMetrics" | grep "subscription_name=\"git-pull-time-metric-sub-failed\"" | grep git_failed_pull_time_count

kubectl get appsub -n git-pull-time-metric-test git-pull-time-metric-sub-failed -o yaml

kubectl get pods -n open-cluster-management-agent-addon -l component=application-manager
kubectl logs -n open-cluster-management-agent-addon -l component=application-manager

if [ "${failedPullTimeCount[1]}" \> 0 ]; then
echo "19-verify-git-pull-time-metric: git_failed_pull_time metrics collected by the managed cluster's metrics service"
else
echo "19-verify-git-pull-time-metric: FAILED: git_failed_pull_time metrics not collected by the managed cluster's metrics service"
Expand Down Expand Up @@ -664,7 +682,7 @@ echo "STARTING test case 22-ansiblejob-tags"
kubectl config use-context kind-hub
kubectl apply -f hack/test/tower.ansible.com_ansiblejobs_crd.yaml
kubectl apply -f test/e2e/cases/22-ansiblejob-tags/
sleep 10
sleep 40

if kubectl get subscriptions.apps.open-cluster-management.io ansible-hook -o yaml | grep lastposthookjob | grep posthook-tags-test; then
echo "22-ansiblejob-tags: found ansiblejob CR name in subscription output"
Expand Down
3 changes: 3 additions & 0 deletions cmd/appsubsummary/exec/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"open-cluster-management.io/multicloud-operators-subscription/pkg/utils"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
k8swebhook "sigs.k8s.io/controller-runtime/pkg/webhook"
)
Expand All @@ -41,6 +42,8 @@ var (

// RunManager starts the actual manager.
func RunManager() {
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))

enableLeaderElection := false

if _, err := rest.InClusterConfig(); err == nil {
Expand Down
3 changes: 3 additions & 0 deletions cmd/manager/exec/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"

Expand Down Expand Up @@ -67,6 +68,8 @@ const (
)

func RunManager() {
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))

enableLeaderElection := false

if _, err := rest.InClusterConfig(); err == nil {
Expand Down
3 changes: 3 additions & 0 deletions cmd/placementrule/exec/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"k8s.io/client-go/rest"
"k8s.io/klog/v2"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
k8swebhook "sigs.k8s.io/controller-runtime/pkg/webhook"
)
Expand All @@ -40,6 +41,8 @@ var (

// RunManager starts the actual manager
func RunManager() {
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))

enableLeaderElection := false

if _, err := rest.InClusterConfig(); err == nil {
Expand Down
47 changes: 47 additions & 0 deletions deploy/hub/subscription-report-operator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: multicluster-operators-subscription-report
name: multicluster-operators-subscription-report
namespace: open-cluster-management
spec:
replicas: 1
selector:
matchLabels:
app: multicluster-operators-subscription-report
template:
metadata:
labels:
app: multicluster-operators-subscription-report
spec:
serviceAccountName: multicluster-operators
containers:
- command:
- /usr/local/bin/appsubsummary
env:
- name: WATCH_NAMESPACE
- name: POD_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
- name: DEPLOYMENT_LABEL
value: multicluster-operators-subscription-report
- name: OPERATOR_NAME
value: multicluster-operators-subscription-report
image: quay.io/open-cluster-management/multicloud-operators-subscription:latest
imagePullPolicy: IfNotPresent
name: multicluster-operators-subscription-report
resources:
limits:
cpu: 750m
memory: 2Gi
requests:
cpu: 150m
memory: 128Mi
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/s3 v1.27.1
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
github.com/go-git/go-git/v5 v5.4.2
github.com/go-logr/logr v1.2.4
github.com/go-logr/logr v1.3.0
github.com/google/go-github/v42 v42.0.0
github.com/johannesboyne/gofakes3 v0.0.0-20210819161434-5c8dfcfe5310
github.com/onsi/ginkgo/v2 v2.9.5
Expand All @@ -21,7 +21,7 @@ require (
github.com/prometheus/client_golang v1.15.1
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.1
github.com/stretchr/testify v1.8.4
golang.org/x/crypto v0.5.0
golang.org/x/net v0.10.0
gomodules.xyz/jsonpatch/v3 v3.0.1
Expand Down Expand Up @@ -95,6 +95,7 @@ require (
github.com/go-git/go-billy/v5 v5.3.1 // indirect
github.com/go-git/go-git-fixtures/v4 v4.3.1 // indirect
github.com/go-gorp/gorp/v3 v3.0.2 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.1 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
Expand Down Expand Up @@ -169,6 +170,8 @@ require (
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/xlab/treeprint v1.1.0 // indirect
go.starlark.net v0.0.0-20220714194419-4cadf0a12139 // indirect
go.uber.org/multierr v1.10.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/oauth2 v0.5.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.8.0 // indirect
Expand Down
Loading

0 comments on commit 0167248

Please sign in to comment.