Merge pull request #2096 from fluxcd/e2e-image-automation

Add e2e test for image automation
pull/2101/head
Stefan Prodan 3 years ago committed by GitHub
commit e4dc56b59d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -91,16 +91,24 @@ jobs:
run: |
/tmp/flux uninstall -s --keep-namespace
kubectl delete ns flux-system --timeout=10m --wait=true
- name: bootstrap reinstall
- name: test image automation
run: |
make setup-image-automation
/tmp/flux bootstrap github --manifests ./manifests/install/ \
--owner=fluxcd-testing \
--repository=${{ steps.vars.outputs.test_repo_name }} \
--branch=main \
--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:
GITHUB_TOKEN: ${{ secrets.GITPROVIDER_BOT_TOKEN }}
GITHUB_REPO_NAME: ${{ steps.vars.outputs.test_repo_name }}
GITHUB_ORG_NAME: fluxcd-testing
- name: delete repository
run: |
curl \

@ -64,6 +64,9 @@ install-envtest: setup-envtest
setup-bootstrap-patch:
go run ./tests/bootstrap/main.go
setup-image-automation:
cd tests/image-automation && go run main.go
# Find or download setup-envtest
setup-envtest:
ifeq (, $(shell which setup-envtest))

@ -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

@ -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"}

@ -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)
}
}
Loading…
Cancel
Save