mirror of https://github.com/fluxcd/flux2.git
Merge pull request #2096 from fluxcd/e2e-image-automation
Add e2e test for image automationpull/2101/head
commit
e4dc56b59d
@ -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…
Reference in New Issue