Add e2e test for image automation
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
12
.github/workflows/bootstrap.yaml
vendored
12
.github/workflows/bootstrap.yaml
vendored
@@ -91,16 +91,24 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
/tmp/flux uninstall -s --keep-namespace
|
/tmp/flux uninstall -s --keep-namespace
|
||||||
kubectl delete ns flux-system --timeout=10m --wait=true
|
kubectl delete ns flux-system --timeout=10m --wait=true
|
||||||
- name: bootstrap reinstall
|
- name: test image automation
|
||||||
run: |
|
run: |
|
||||||
|
make setup-image-automation
|
||||||
/tmp/flux bootstrap github --manifests ./manifests/install/ \
|
/tmp/flux bootstrap github --manifests ./manifests/install/ \
|
||||||
--owner=fluxcd-testing \
|
--owner=fluxcd-testing \
|
||||||
--repository=${{ steps.vars.outputs.test_repo_name }} \
|
--repository=${{ steps.vars.outputs.test_repo_name }} \
|
||||||
--branch=main \
|
--branch=main \
|
||||||
--path=test-cluster \
|
--path=test-cluster \
|
||||||
--team=team-z
|
--read-write-key
|
||||||
|
/tmp/flux reconcile image repository podinfo
|
||||||
|
/tmp/flux reconcile image update flux-system
|
||||||
|
/tmp/flux get images all
|
||||||
|
/tmp/flux get images policy podinfo | grep "5.2.1"
|
||||||
|
/tmp/flux get image update flux-system | grep commit
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITPROVIDER_BOT_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITPROVIDER_BOT_TOKEN }}
|
||||||
|
GITHUB_REPO_NAME: ${{ steps.vars.outputs.test_repo_name }}
|
||||||
|
GITHUB_ORG_NAME: fluxcd-testing
|
||||||
- name: delete repository
|
- name: delete repository
|
||||||
run: |
|
run: |
|
||||||
curl \
|
curl \
|
||||||
|
|||||||
3
Makefile
3
Makefile
@@ -64,6 +64,9 @@ install-envtest: setup-envtest
|
|||||||
setup-bootstrap-patch:
|
setup-bootstrap-patch:
|
||||||
go run ./tests/bootstrap/main.go
|
go run ./tests/bootstrap/main.go
|
||||||
|
|
||||||
|
setup-image-automation:
|
||||||
|
cd tests/image-automation && go run main.go
|
||||||
|
|
||||||
# Find or download setup-envtest
|
# Find or download setup-envtest
|
||||||
setup-envtest:
|
setup-envtest:
|
||||||
ifeq (, $(shell which setup-envtest))
|
ifeq (, $(shell which setup-envtest))
|
||||||
|
|||||||
45
tests/image-automation/auto.yaml
Normal file
45
tests/image-automation/auto.yaml
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
apiVersion: image.toolkit.fluxcd.io/v1beta1
|
||||||
|
kind: ImageRepository
|
||||||
|
metadata:
|
||||||
|
name: podinfo
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
image: ghcr.io/stefanprodan/podinfo
|
||||||
|
interval: 1m0s
|
||||||
|
---
|
||||||
|
apiVersion: image.toolkit.fluxcd.io/v1beta1
|
||||||
|
kind: ImagePolicy
|
||||||
|
metadata:
|
||||||
|
name: podinfo
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
imageRepositoryRef:
|
||||||
|
name: podinfo
|
||||||
|
policy:
|
||||||
|
semver:
|
||||||
|
range: 5.2.x
|
||||||
|
---
|
||||||
|
apiVersion: image.toolkit.fluxcd.io/v1beta1
|
||||||
|
kind: ImageUpdateAutomation
|
||||||
|
metadata:
|
||||||
|
name: flux-system
|
||||||
|
namespace: flux-system
|
||||||
|
spec:
|
||||||
|
interval: 5m0s
|
||||||
|
sourceRef:
|
||||||
|
kind: GitRepository
|
||||||
|
name: flux-system
|
||||||
|
git:
|
||||||
|
checkout:
|
||||||
|
ref:
|
||||||
|
branch: main
|
||||||
|
commit:
|
||||||
|
author:
|
||||||
|
email: fluxcdbot@users.noreply.github.com
|
||||||
|
name: fluxcdbot
|
||||||
|
messageTemplate: '{{range .Updated.Images}}{{println .}}{{end}}'
|
||||||
|
push:
|
||||||
|
branch: main
|
||||||
|
update:
|
||||||
|
path: ./test-cluster/podinfo-auto
|
||||||
|
strategy: Setters
|
||||||
10
tests/image-automation/kustomization.yaml
Normal file
10
tests/image-automation/kustomization.yaml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
namespace: flux-system
|
||||||
|
resources:
|
||||||
|
- https://raw.githubusercontent.com/stefanprodan/podinfo/5.2.0/kustomize/deployment.yaml
|
||||||
|
- auto.yaml
|
||||||
|
images:
|
||||||
|
- name: ghcr.io/stefanprodan/podinfo
|
||||||
|
newName: ghcr.io/stefanprodan/podinfo
|
||||||
|
newTag: 5.2.0 # {"$imagepolicy": "flux-system:podinfo:tag"}
|
||||||
71
tests/image-automation/main.go
Normal file
71
tests/image-automation/main.go
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/fluxcd/go-git-providers/github"
|
||||||
|
"github.com/fluxcd/go-git-providers/gitprovider"
|
||||||
|
"k8s.io/client-go/util/retry"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
ksPath := "test-cluster/podinfo-auto/kustomization.yaml"
|
||||||
|
autoPath := "test-cluster/podinfo-auto/auto.yaml"
|
||||||
|
|
||||||
|
ksContent, err := os.ReadFile("kustomization.yaml")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
ks := string(ksContent)
|
||||||
|
|
||||||
|
autoContent, err := os.ReadFile("auto.yaml")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
auto := string(autoContent)
|
||||||
|
|
||||||
|
commitFiles := []gitprovider.CommitFile{
|
||||||
|
{
|
||||||
|
Path: &ksPath,
|
||||||
|
Content: &ks,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Path: &autoPath,
|
||||||
|
Content: &auto,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
orgName := os.Getenv("GITHUB_ORG_NAME")
|
||||||
|
repoName := os.Getenv("GITHUB_REPO_NAME")
|
||||||
|
githubToken := os.Getenv(github.TokenVariable)
|
||||||
|
client, err := github.NewClient(gitprovider.WithOAuth2Token(githubToken))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("error initializing github client: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
repoRef := gitprovider.OrgRepositoryRef{
|
||||||
|
OrganizationRef: gitprovider.OrganizationRef{
|
||||||
|
Organization: orgName,
|
||||||
|
Domain: github.DefaultDomain,
|
||||||
|
},
|
||||||
|
RepositoryName: repoName,
|
||||||
|
}
|
||||||
|
|
||||||
|
var repo gitprovider.OrgRepository
|
||||||
|
err = retry.OnError(retry.DefaultRetry, func(err error) bool {
|
||||||
|
return err != nil
|
||||||
|
}, func() error {
|
||||||
|
repo, err = client.OrgRepositories().Get(context.Background(), repoRef)
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("error getting %s repository in org %s: %s", repoRef.RepositoryName, repoRef.Organization, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = repo.Commits().Create(context.Background(), "main", "automation test", commitFiles)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("error making commit: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user