Skip to content

Commit

Permalink
keep
Browse files Browse the repository at this point in the history
Signed-off-by: dntosas <ntosas@gmail.com>
  • Loading branch information
dntosas committed Aug 21, 2023
1 parent d4d9762 commit f3449cb
Show file tree
Hide file tree
Showing 2,568 changed files with 1,436,747 additions and 5 deletions.
53 changes: 53 additions & 0 deletions .github/config/goreleaser-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
dist: bin
project_name: capi2argo-cluster-operator
env:
- DOCKER_REPO="ghcr.io/dntosas"
builds:
- env:
- CGO_ENABLED=0
binary: "{{ .ProjectName }}"
goos:
- linux
goarch:
- amd64
- arm64
flags:
- -trimpath
- -mod=vendor
ldflags:
- -s -w
- -X {{ .ProjectName }}/cmd.Version=dev
- -X {{ .ProjectName }}/cmd.CommitHash={{ .FullCommit }}
main: .

dockers:
# amd64
- image_templates:
- ghcr.io/dntosas/{{ .ProjectName }}:dev-amd64
dockerfile: Dockerfile
use: buildx
goos: linux
goarch: amd64
build_flag_templates:
- "--pull"
- "--platform=linux/amd64"
# arm64
- image_templates:
- ghcr.io/dntosas/{{ .ProjectName }}:dev-arm64
dockerfile: Dockerfile
use: buildx
goos: linux
goarch: arm64
build_flag_templates:
- "--pull"
- "--platform=linux/arm64/v8"

docker_manifests:
# https://goreleaser.com/customization/docker_manifest/
- name_template: ghcr.io/dntosas/{{ .ProjectName }}:dev
image_templates:
- ghcr.io/dntosas/{{ .ProjectName }}:dev-amd64
- ghcr.io/dntosas/{{ .ProjectName }}:dev-arm64

release:
disable: true
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ changelog:
filters:
exclude:
- '^Merge\spull\srequest\s'

groups:
- title: 'New Features'
regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
order: 100
- title: 'Security updates'
regexp: '^.*?sec(\([[:word:]]+\))??!?:.+$'
order: 150
- title: 'Bug fixes'
regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'
order: 200
- title: 'Documentation updates'
regexp: ^.*?
- title: Dependency updates
regexp: '^.*?(feat|fix)\(deps\)!?:.+$'
order: 300
# release:
# draft: true
41 changes: 41 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: E2E Tests
on:
workflow_dispatch:
jobs:
e2e:
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v4.0.0
with:
go-version: '1.20.3'

- name: Checkout code
uses: actions/checkout@v3.5.2
with:
fetch-depth: 0

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
logout: false

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
args: release --clean --config .github/config/goreleaser-dev.yaml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COSIGN_PASSWORD: ${{ secrets.COSIGN_PRIVATE_KEY }}

- name: Create k8s Kind Cluster
uses: helm/kind-action@v1.5.0

- name: Run E2E tests
run: make e2e
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml → .github/workflows/go-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4.1.0
with:
go-version: '1.20.2'
go-version: '1.20.3'

- name: Checkout code
uses: actions/checkout@v3.5.3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/go-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4.1.0
with:
go-version: '1.20.2'
go-version: '1.20.3'

- name: Checkout code
uses: actions/checkout@v3.5.3
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
args: release --clean --config .github/config/goreleaser.yaml
args: release --clean --config .github/config/goreleaser-prod.yaml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COSIGN_PASSWORD: ${{ secrets.COSIGN_PRIVATE_KEY }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/helm-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Install Helm
uses: azure/setup-helm@v3.5
with:
version: v3.9.0
version: v3.11.3

- name: Add Helm dependency repos
run: |
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ lint: ## Run golangci-lint against code.
test: envtest ## Run go tests against code.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -v -mod=vendor `go list ./...` -coverprofile cover.out

.PHONY: e2e
e2e: ## Run e2e tests
cd tests && go mod vendor && go test -mod=vendor -v .

.PHONY: ci
ci: fmt vet lint test ## Run go fmt/vet/lint/tests against the code.

Expand Down
86 changes: 86 additions & 0 deletions tests/e2e_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package test

import (
"fmt"
"strings"
"testing"
"time"

"github.com/gruntwork-io/terratest/modules/helm"
http_helper "github.com/gruntwork-io/terratest/modules/http-helper"
"github.com/gruntwork-io/terratest/modules/k8s"
"github.com/gruntwork-io/terratest/modules/random"
// metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestE2ECapi2Argo(t *testing.T) {
// Path to the helm chart we will test
helmChartPath := "../charts/capi2argo-cluster-operator"

// Setup the kubectl config and context. Here we choose to use the defaults, which is:
// - HOME/.kube/config for the kubectl config file
// - Current context of the kubectl config file
// We also specify that we are working in the default namespace (required to get the Pod)
// kubectlOptions := k8s.NewKubectlOptions("", "", "default")

// We generate a unique release name so that we can refer to after deployment.
// By doing so, we can schedule the delete call here so that at the end of the test, we run
// `helm delete RELEASE_NAME` to clean up any resources that were created.
releaseName := fmt.Sprintf("caco-%s", strings.ToLower(random.UniqueId()))

// Setup the chart options. For this test, we will set the following input values:
options := &helm.Options{
SetValues: map[string]string{
"fullnameOverride": releaseName,
"image.tag": "dev",
},
ExtraArgs: map[string][]string{
"upgrade": {"--wait"},
},
}

// Clean up deployment on when finished
defer helm.Delete(t, options, releaseName, true)

// Deploy the chart using `helm upgrade`. Note that we use the version without `E`, since we want to assert the
// install succeeds without any errors.
helm.Upgrade(t, options, helmChartPath, releaseName)

// Now that the chart is deployed, verify the deployment and get the name of working pod.
// filter := &metav1.ListOptions{
// LabelSelector: fmt.Sprintf("app.kubernetes.io/instance=%s", releaseName),
// }
// pod := k8s.ListPods(t, kubectlOptions, *filter)
// podName := pod[0].Name

// This function will open a tunnel to the Pod and hit astrolavos container endpoint.
// VerifyExposedMetrics(t, kubectlOptions, podName)
}

// VerifyExposedMetrics will open a tunnel to the Pod and hit the endpoint to verify the metrics are exposed.
func VerifyExposedMetrics(t *testing.T, kubectlOptions *k8s.KubectlOptions, podName string) {
// Wait for the pod to come up. It takes some time for the Pod to start, so retry a few times.
retries := 15
sleep := 5 * time.Second
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, retries, sleep)

// We will first open a tunnel to the pod, making sure to close it at the end of the test.
tunnel := k8s.NewTunnel(kubectlOptions, k8s.ResourceTypePod, podName, 0, 3000)
defer tunnel.Close()
tunnel.ForwardPort(t)

// Now that we have the tunnel, we will verify that we get back a 200 OK on /metrics endpoint plus metrics
// for our defined target.
// It takes some time for the Pod to start, so retry a few times.
endpoint := fmt.Sprintf("http://%s/metrics", tunnel.Endpoint())
http_helper.HttpGetWithRetryWithCustomValidation(
t,
endpoint,
nil,
retries,
sleep,
func(statusCode int, body string) bool {
return statusCode == 200 && strings.Contains(body, "endpoint=\"https://kubernetes\"")
},
)
}
60 changes: 60 additions & 0 deletions tests/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
module github.com/dntosas/astrolavos/tests

go 1.20

require (
github.com/gruntwork-io/terratest v0.41.10
k8s.io/apimachinery v0.20.6
)

require (
cloud.google.com/go v0.83.0 // indirect
github.com/aws/aws-sdk-go v1.40.56 // indirect
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/spdystream v0.0.0-20181023171402-6480d4af844c // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-errors/errors v1.0.2-0.20180813162953-d98b870cc4e0 // indirect
github.com/go-logr/logr v0.2.0 // indirect
github.com/go-sql-driver/mysql v1.4.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/uuid v1.2.0 // indirect
github.com/googleapis/gnostic v0.4.1 // indirect
github.com/gruntwork-io/go-commons v0.8.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.0 // indirect
github.com/imdario/mergo v0.3.11 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/json-iterator/go v1.1.11 // indirect
github.com/mattn/go-zglob v0.0.2-0.20190814121620-e3c945676326 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pquerna/otp v1.2.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.7.0 // indirect
github.com/urfave/cli v1.22.2 // indirect
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c // indirect
golang.org/x/sys v0.0.0-20220517195934-5e4e11fc645e // indirect
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect
golang.org/x/text v0.3.6 // indirect
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.26.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/api v0.20.6 // indirect
k8s.io/client-go v0.20.6 // indirect
k8s.io/klog/v2 v2.4.0 // indirect
k8s.io/utils v0.0.0-20201110183641-67b214c5f920 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.0.3 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)
Loading

0 comments on commit f3449cb

Please sign in to comment.