Skip to content

Commit 72108d0

Browse files
authored
Fix OLM upgrade scenario to sigstore based (#198)
test(e2e): wait for controller leadership before pod admission Signed-off-by: ompushkara <omotilal@redhat.com>
1 parent 89068b1 commit 72108d0

2 files changed

Lines changed: 155 additions & 106 deletions

File tree

‎.github/workflows/test-e2e.yml‎

Lines changed: 90 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
name: Run E2E Tests
1515
runs-on: ubuntu-latest
1616
steps:
17-
- name: Checkout code
17+
- name: Checkout source
1818
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
1919

2020
- name: Setup Go
@@ -23,152 +23,137 @@ jobs:
2323
go-version-file: go.mod
2424
cache: true
2525

26-
- name: Create kind cluster
26+
- name: Create Kind cluster
2727
uses: helm/kind-action@ef37e7f390d99f746eb8b610417061a60e82a6cc # v1
2828
with:
2929
cluster_name: kind
3030

31-
- name: Wait for kind cluster to be ready
31+
- name: Wait for Kind cluster to be ready
3232
run: |
3333
kubectl wait --for=condition=Ready nodes --all --timeout=300s
3434
kubectl wait --for=condition=Ready --namespace=kube-system pod --all --timeout=300s
3535
echo "Cluster is ready"
3636
3737
- name: Run E2E tests
38-
run: |
39-
make test-e2e-ci
38+
run: make test-e2e-ci
4039

4140
test-e2e-olm-upgrade:
42-
name: Test OLM upgrade
43-
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
41+
name: Test OLM Upgrade
4442
runs-on: ubuntu-latest
45-
permissions:
46-
contents: read
47-
packages: write
4843
env:
4944
CONTAINER_TOOL: podman
50-
REGISTRY: ghcr.io
51-
IMG: ghcr.io/securesign/model-validation-operator:dev-${{ github.sha }}
52-
AGENT_IMG: ghcr.io/securesign/model-validation-operator-agent:dev-${{ github.sha }}
53-
BUNDLE_IMG: ghcr.io/securesign/model-validation-operator-bundle:dev-${{ github.sha }}
54-
CATALOG_IMG: ghcr.io/securesign/model-validation-operator-fbc:dev-${{ github.sha }}
55-
OCP_VERSION: ${{ vars.OLM_INDEX_VERSION }}
45+
IMG: ghcr.io/sigstore/model-validation-operator:dev-${{ github.sha }}
46+
AGENT_IMG: ghcr.io/sigstore/model-validation-operator-agent:dev-${{ github.sha }}
47+
BUNDLE_IMG: ghcr.io/sigstore/model-validation-operator-bundle:dev-${{ github.sha }}
48+
CATALOG_IMG: ghcr.io/sigstore/model-validation-operator-catalog:dev-${{ github.sha }}
49+
BASE_IMG: ghcr.io/sigstore/model-validation-operator:olm-base-${{ github.sha }}
50+
BASE_AGENT_IMG: ghcr.io/sigstore/model-validation-operator-agent:olm-base-${{ github.sha }}
51+
BASE_BUNDLE_IMG: ghcr.io/sigstore/model-validation-operator-bundle:olm-base-${{ github.sha }}
52+
BASE_CATALOG_IMG: ghcr.io/sigstore/model-validation-operator-catalog:olm-base-${{ github.sha }}
5653
steps:
5754
- name: Checkout source
58-
uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v6
59-
60-
- name: Compute OLM upgrade version
61-
run: |
62-
CURRENT=$(grep '^VERSION ?=' Makefile | cut -d= -f2 | tr -d ' ')
63-
NEXT=$(echo "$CURRENT" | awk -F. '{print $1"."$2"."$3+1}')
64-
echo "OLM_UPGRADE_VERSION=$NEXT" >> "$GITHUB_ENV"
55+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
6556

6657
- name: Setup Go
6758
uses: actions/setup-go@def8c394e3ad351a79bc93815e4a585520fe993b # v5
6859
with:
6960
go-version-file: go.mod
7061
cache: true
7162

72-
- name: Log in to GitHub Container Registry
73-
uses: redhat-actions/podman-login@v1
74-
with:
75-
registry: ${{ env.REGISTRY }}
76-
username: ${{ github.actor }}
77-
password: ${{ secrets.GITHUB_TOKEN }}
78-
auth_file_path: /tmp/config.json
79-
80-
- name: Log in to registry.redhat.io
81-
uses: redhat-actions/podman-login@v1
82-
with:
83-
username: ${{ secrets.REGISTRY_USER }}
84-
password: ${{ secrets.REGISTRY_PASSWORD }}
85-
registry: registry.redhat.io
86-
auth_file_path: /tmp/config.json
87-
88-
- name: Log in to brew.registry.redhat.io
89-
uses: redhat-actions/podman-login@v1
63+
- name: Create Kind cluster with local registry
64+
id: kind
65+
uses: helm/kind-action@ef37e7f390d99f746eb8b610417061a60e82a6cc # v1
9066
with:
91-
username: ${{ secrets.REGISTRY_USER }}
92-
password: ${{ secrets.REGISTRY_PASSWORD }}
93-
registry: brew.registry.redhat.io
94-
auth_file_path: /tmp/config.json
95-
96-
- name: Swap to dev images
97-
run: make dev-images
98-
99-
- name: Build and push operator image
100-
run: make docker-build docker-push IMG=${{ env.IMG }} AGENT_IMG=${{ env.AGENT_IMG }}
101-
102-
- name: Build and push agent image
103-
run: make docker-build-agent docker-push-agent AGENT_IMG=${{ env.AGENT_IMG }}
104-
105-
- name: Build and push bundle
106-
run: make bundle bundle-build bundle-push IMG=${{ env.IMG }} BUNDLE_IMG=${{ env.BUNDLE_IMG }} VERSION=${{ env.OLM_UPGRADE_VERSION }} CHANNELS=tech-preview DEFAULT_CHANNEL=tech-preview
67+
cluster_name: kind
68+
registry: true
69+
registry_name: kind-registry
70+
registry_port: 5000
10771

108-
- name: Install OPM
72+
- name: Wait for Kind cluster to be ready
10973
run: |
110-
make opm
111-
echo "$(pwd)/bin" >> $GITHUB_PATH
112-
113-
- name: Checkout FBC source
114-
uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v6
115-
with:
116-
repository: securesign/fbc
117-
ref: main
118-
path: fbc
74+
kubectl wait --for=condition=Ready nodes --all --timeout=300s
75+
kubectl wait --for=condition=Ready --namespace=kube-system pod --all --timeout=300s
11976
120-
- name: Build and push FBC catalog
121-
env:
122-
BUNDLE_IMAGE: ${{ env.BUNDLE_IMG }}
123-
BUNDLE_NAME: model-validation-operator.v${{ env.OLM_UPGRADE_VERSION }}
124-
FBC_DIR: model-validation-operator
125-
GRAPH: ${{ env.OCP_VERSION }}/model-validation-operator/graph.yaml
126-
CHANNELS: tech-preview
127-
CATALOG_FILE: ${{ env.OCP_VERSION }}/model-validation-operator/catalog/model-validation-operator/catalog.json
77+
- name: Configure local registry access
78+
run: |
79+
LOCAL_REGISTRY=kind-registry:5000
80+
echo "LOCAL_REGISTRY=$LOCAL_REGISTRY" >> "$GITHUB_ENV"
81+
mkdir -p "$HOME/.config/containers/registries.conf.d"
82+
cat > "$HOME/.config/containers/registries.conf.d/kind-local-registry.conf" <<EOF
83+
[[registry]]
84+
location = "$LOCAL_REGISTRY"
85+
insecure = true
86+
EOF
87+
88+
for attempt in {1..30}; do
89+
if curl --fail --silent "http://$LOCAL_REGISTRY/v2/" >/dev/null; then
90+
break
91+
fi
92+
sleep 1
93+
done
94+
curl --fail --silent "http://$LOCAL_REGISTRY/v2/" >/dev/null
95+
96+
- name: Compute OLM upgrade versions
12897
run: |
129-
cd fbc
130-
utils/configure_bundles.sh
131-
utils/configure_channels.sh
132-
utils/render_catalog.sh
98+
CURRENT=$(grep '^VERSION ?=' Makefile | cut -d= -f2 | tr -d ' ')
99+
NEXT=$(echo "$CURRENT" | awk -F. '{print $1"."$2"."$3+1}')
100+
echo "OLM_BASE_VERSION=$CURRENT" >> "$GITHUB_ENV"
101+
echo "OLM_UPGRADE_VERSION=$NEXT" >> "$GITHUB_ENV"
133102
134-
cat $GRAPH
135-
opm validate $OCP_VERSION/model-validation-operator/catalog/model-validation-operator
136-
$CONTAINER_TOOL build $OCP_VERSION/model-validation-operator -f catalog.Dockerfile -t $CATALOG_IMG
137-
$CONTAINER_TOOL push $CATALOG_IMG
103+
- name: Set local OLM image references
104+
run: |
105+
echo "BASE_IMG_LOCAL=$LOCAL_REGISTRY/${BASE_IMG#ghcr.io/}" >> "$GITHUB_ENV"
106+
echo "BASE_AGENT_IMG_LOCAL=$LOCAL_REGISTRY/${BASE_AGENT_IMG#ghcr.io/}" >> "$GITHUB_ENV"
107+
echo "IMG_LOCAL=$LOCAL_REGISTRY/${IMG#ghcr.io/}" >> "$GITHUB_ENV"
108+
echo "AGENT_IMG_LOCAL=$LOCAL_REGISTRY/${AGENT_IMG#ghcr.io/}" >> "$GITHUB_ENV"
109+
echo "BASE_BUNDLE_IMG_LOCAL=$LOCAL_REGISTRY/${BASE_BUNDLE_IMG#ghcr.io/}" >> "$GITHUB_ENV"
110+
echo "BUNDLE_IMG_LOCAL=$LOCAL_REGISTRY/${BUNDLE_IMG#ghcr.io/}" >> "$GITHUB_ENV"
111+
echo "BASE_CATALOG_IMG_LOCAL=$LOCAL_REGISTRY/${BASE_CATALOG_IMG#ghcr.io/}" >> "$GITHUB_ENV"
112+
echo "CATALOG_IMG_LOCAL=$LOCAL_REGISTRY/${CATALOG_IMG#ghcr.io/}" >> "$GITHUB_ENV"
113+
114+
- name: Build base operator image
115+
run: |
116+
make docker-build docker-build-agent IMG="$BASE_IMG_LOCAL" AGENT_IMG="$BASE_AGENT_IMG_LOCAL"
117+
podman push --tls-verify=false "$BASE_IMG_LOCAL"
118+
podman push --tls-verify=false "$BASE_AGENT_IMG_LOCAL"
138119
139-
- name: Create kind cluster
140-
uses: helm/kind-action@ef37e7f390d99f746eb8b610417061a60e82a6cc # v1
141-
with:
142-
cluster_name: kind
143-
config: ./ci/kind-config.yaml
120+
- name: Build target operator image
121+
run: |
122+
make docker-build docker-build-agent IMG="$IMG_LOCAL" AGENT_IMG="$AGENT_IMG_LOCAL"
123+
podman push --tls-verify=false "$IMG_LOCAL"
124+
podman push --tls-verify=false "$AGENT_IMG_LOCAL"
144125
145-
- name: Wait for kind cluster to be ready
126+
- name: Build base bundle
146127
run: |
147-
kubectl wait --for=condition=Ready nodes --all --timeout=300s
148-
kubectl wait --for=condition=Ready --namespace=kube-system pod --all --timeout=300s
149-
echo "Cluster is ready"
128+
make bundle bundle-build IMG="$BASE_IMG_LOCAL" AGENT_IMG="$BASE_AGENT_IMG_LOCAL" BUNDLE_IMG="$BASE_BUNDLE_IMG_LOCAL" VERSION=$OLM_BASE_VERSION CHANNELS=tech-preview DEFAULT_CHANNEL=tech-preview
129+
podman push --tls-verify=false "$BASE_BUNDLE_IMG_LOCAL"
150130
151-
- name: Load images into Kind
131+
- name: Build target bundle
152132
run: |
153-
$CONTAINER_TOOL save ${{ env.IMG }} -o operator-oci.tar
154-
$CONTAINER_TOOL save ${{ env.AGENT_IMG }} -o agent-oci.tar
155-
$CONTAINER_TOOL save ${{ env.BUNDLE_IMG }} -o bundle-oci.tar
156-
$CONTAINER_TOOL save ${{ env.CATALOG_IMG }} -o catalog-oci.tar
133+
make bundle bundle-build IMG="$IMG_LOCAL" AGENT_IMG="$AGENT_IMG_LOCAL" BUNDLE_IMG="$BUNDLE_IMG_LOCAL" VERSION=$OLM_UPGRADE_VERSION CHANNELS=tech-preview DEFAULT_CHANNEL=tech-preview
134+
podman push --tls-verify=false "$BUNDLE_IMG_LOCAL"
157135
158-
kind load image-archive operator-oci.tar
159-
kind load image-archive agent-oci.tar
160-
kind load image-archive bundle-oci.tar
161-
kind load image-archive catalog-oci.tar
136+
- name: Build base and target catalogs
137+
run: |
138+
make opm
139+
make catalog-build CATALOG_IMG="$BASE_CATALOG_IMG_LOCAL" BUNDLE_IMGS="$BASE_BUNDLE_IMG_LOCAL"
140+
podman push --tls-verify=false "$BASE_CATALOG_IMG_LOCAL"
141+
make catalog-build CATALOG_IMG="$CATALOG_IMG_LOCAL" BUNDLE_IMGS="$BUNDLE_IMG_LOCAL" CATALOG_BASE_IMG="$BASE_CATALOG_IMG_LOCAL"
142+
podman push --tls-verify=false "$CATALOG_IMG_LOCAL"
162143
163144
- name: Install OLM
164145
run: make e2e-install-olm
165146

166-
- name: Setup namespaces
147+
- name: Setup OLM test namespaces
167148
run: make e2e-setup-namespaces
168149

169150
- name: Run OLM upgrade tests
170151
env:
171-
TEST_BASE_CATALOG: registry.redhat.io/redhat/redhat-operator-index:${{ vars.OLM_INDEX_VERSION }}
172-
TEST_TARGET_CATALOG: ${{ env.CATALOG_IMG }}
152+
TEST_BASE_CATALOG: kind-registry:5000/sigstore/model-validation-operator-catalog:olm-base-${{ github.sha }}
153+
TEST_TARGET_CATALOG: kind-registry:5000/sigstore/model-validation-operator-catalog:dev-${{ github.sha }}
154+
run: go test ./test/e2e-olm/ -v -ginkgo.v -timeout 20m
155+
156+
- name: Clean up local registry configuration
157+
if: always()
173158
run: |
174-
go test ./test/e2e-olm/ -v -ginkgo.v -timeout 20m
159+
rm -f "$HOME/.config/containers/registries.conf.d/kind-local-registry.conf"

‎test/e2e/legacy_sidecar_test.go‎

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package e2e
1919
import (
2020
"fmt"
2121
"os/exec"
22+
"strings"
2223
"time"
2324

2425
. "github.com/onsi/ginkgo/v2" //nolint:revive
@@ -29,7 +30,11 @@ import (
2930
utils "github.com/sigstore/model-validation-operator/test/utils"
3031
)
3132

32-
const legacySidecarTestNamespace = "e2e-webhook-test-ns"
33+
const (
34+
legacySidecarTestNamespace = "e2e-webhook-test-ns"
35+
legacySidecarLeaderLease = "2b2639c9.sigstore.dev"
36+
controllerPodSelector = "control-plane=controller-manager"
37+
)
3338

3439
// defaultLegacyPodData creates a standard pod configuration for legacy sidecar tests
3540
func defaultLegacyPodData(podName, namespace, modelName string) utils.PodTemplateData {
@@ -65,6 +70,27 @@ var _ = Describe("Legacy Sidecar Continuous Validation", Ordered, func() {
6570
_, err := utils.Run(cmd)
6671
return err
6772
}, 2*time.Minute, 5*time.Second).Should(Succeed())
73+
74+
By("waiting for the new controller pod to acquire the leader lease")
75+
Eventually(func() error {
76+
podName, err := currentControllerPodName()
77+
if err != nil {
78+
return err
79+
}
80+
81+
holder, err := utils.KubectlGet(
82+
"lease", legacySidecarLeaderLease, operatorNamespace,
83+
"jsonpath={.spec.holderIdentity}",
84+
)
85+
if err != nil {
86+
return err
87+
}
88+
if !strings.HasPrefix(holder, podName+"_") {
89+
return fmt.Errorf("leader lease is held by %q; waiting for controller pod %q", holder, podName)
90+
}
91+
return nil
92+
}, 2*time.Minute, time.Second).Should(Succeed(),
93+
"new controller should acquire the leader lease before the test creates a pod")
6894
})
6995

7096
AfterAll(func() {
@@ -99,6 +125,9 @@ var _ = Describe("Legacy Sidecar Continuous Validation", Ordered, func() {
99125
By("deploying a pod with the validation label")
100126
err = utils.KubectlApply(podTemplate,
101127
defaultLegacyPodData(podName, legacySidecarTestNamespace, modelName))
128+
if err != nil {
129+
logCurrentControllerPods()
130+
}
102131
Expect(err).NotTo(HaveOccurred())
103132

104133
By("verifying the init container was injected (one-shot validation)")
@@ -202,3 +231,38 @@ var _ = Describe("Legacy Sidecar Continuous Validation", Ordered, func() {
202231
})
203232
})
204233
})
234+
235+
func currentControllerPodName() (string, error) {
236+
cmd := exec.Command("kubectl", "get", "pods", "-l", controllerPodSelector,
237+
"-n", operatorNamespace,
238+
"-o", `go-template={{range .items}}{{if not .metadata.deletionTimestamp}}{{.metadata.name}}{{"\n"}}{{end}}{{end}}`)
239+
output, err := utils.Run(cmd)
240+
if err != nil {
241+
return "", err
242+
}
243+
podNames := utils.GetNonEmptyLines(output)
244+
if len(podNames) != 1 {
245+
return "", fmt.Errorf("expected one active controller pod, found %d: %v", len(podNames), podNames)
246+
}
247+
return podNames[0], nil
248+
}
249+
250+
func logCurrentControllerPods() {
251+
cmd := exec.Command("kubectl", "get", "pods", "-l", controllerPodSelector,
252+
"-n", operatorNamespace,
253+
"-o", `go-template={{range .items}}{{if not .metadata.deletionTimestamp}}{{.metadata.name}}{{"\n"}}{{end}}{{end}}`)
254+
output, err := utils.Run(cmd)
255+
if err != nil {
256+
_, _ = fmt.Fprintf(GinkgoWriter, "Failed to list current controller pods: %v\n", err)
257+
return
258+
}
259+
260+
for _, podName := range utils.GetNonEmptyLines(output) {
261+
logs, err := utils.Run(exec.Command("kubectl", "logs", podName, "-n", operatorNamespace))
262+
if err != nil {
263+
_, _ = fmt.Fprintf(GinkgoWriter, "Failed to get controller logs for %s: %v\n", podName, err)
264+
continue
265+
}
266+
_, _ = fmt.Fprintf(GinkgoWriter, "=== Controller logs for %s ===\n%s\n", podName, logs)
267+
}
268+
}

0 commit comments

Comments
 (0)