diff --git a/.github/workflows/ci-release.yaml b/.github/workflows/ci-release.yaml new file mode 100644 index 0000000..3704b37 --- /dev/null +++ b/.github/workflows/ci-release.yaml @@ -0,0 +1,29 @@ +name: Go Build via release +on: + pull_request: + paths: + - "cmd/**" + - "pkg/**" + - .goreleaser.yaml + - Dockerfile +jobs: + ci-build: + runs-on: ubuntu-latest + name: Build & Test + steps: + - uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - uses: actions/setup-go@v5 + with: + go-version: 1.18 + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v6 + with: + args: release --snapshot --clean --skip=publish,sign diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 295313d..7ebd9e6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -17,20 +17,15 @@ jobs: runs-on: ${{ matrix.os }} name: Build & Test steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - uses: actions/setup-go@v2 - with: - go-version: 1.17 + - uses: actions/setup-go@v5 + with: + go-version: 1.18 - - run: go mod download + - run: go mod download - - name: Build & Test - run: | - go build -v . - go test ./... - - - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v2 - with: - args: release --snapshot --skip-publish --skip-sign --rm-dist + - name: Build & Test + run: | + go build -v . + go test ./... diff --git a/.github/workflows/helm-release.yaml b/.github/workflows/helm-release.yaml index 617c6a0..606e418 100644 --- a/.github/workflows/helm-release.yaml +++ b/.github/workflows/helm-release.yaml @@ -1,6 +1,6 @@ name: helm release on: - push: + push: tags: - "chart-*" @@ -8,7 +8,7 @@ jobs: helm-release: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Publish Helm chart uses: stefanprodan/helm-gh-pages@master with: diff --git a/.github/workflows/helm-tests.yaml b/.github/workflows/helm-tests.yaml index 6924e29..b1db035 100644 --- a/.github/workflows/helm-tests.yaml +++ b/.github/workflows/helm-tests.yaml @@ -2,15 +2,15 @@ name: helm tests on: pull_request: paths: - - 'charts/**' - - '.github/workflows/helm-tests.yaml' + - "charts/**" + - ".github/workflows/helm-tests.yaml" jobs: helm-tests: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: fetch-depth: 0 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 34be22f..81c8bc7 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -9,14 +9,14 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v5 with: - go-version: 1.17 + go-version: 1.18 - name: Import GPG key id: import_gpg @@ -40,6 +40,12 @@ jobs: restore-keys: | ${{ runner.os }}-go- + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Docker Login uses: docker/login-action@v1 with: @@ -47,11 +53,12 @@ jobs: password: ${{ secrets.DOCKER_TOKEN }} - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v2 + uses: goreleaser/goreleaser-action@v6 if: success() && startsWith(github.ref, 'refs/tags/') with: + distribution: goreleaser version: latest - args: release --rm-dist + args: release --clean env: GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 5eb2016..2e65604 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ bin/ vendor/ ./label-watch +label-watch *.exe *.test *.prof diff --git a/.goreleaser.yaml b/.goreleaser.yaml index a566750..cbdfdf3 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,6 +1,8 @@ +version: 2 project_name: label-watch builds: - env: [CGO_ENABLED=0] + binary: label-watch goos: - linux - darwin @@ -9,41 +11,64 @@ builds: - arm64 ignore: - goos: darwin - goarch: '386' - - goos: linux - goarch: arm64 + goarch: "386" dockers: -- image_templates: - - "kolikons/{{.ProjectName}}:{{ .Version }}" - - "kolikons/{{.ProjectName}}:latest" - dockerfile: Dockerfile - goos: linux - goarch: amd64 - build_flag_templates: - - --label=org.opencontainers.image.title={{ .ProjectName }} - - --label=org.opencontainers.image.description={{ .ProjectName }} - - --label=org.opencontainers.image.url=https://github.com/kolikons/label-watch - - --label=org.opencontainers.image.source=https://github.com/kolikons/label-watch - - --label=org.opencontainers.image.version={{ .Version }} - - --label=org.opencontainers.image.revision={{ .FullCommit }} - - "--label=org.opencontainers.image.created={{.Date}}" - - --label=org.opencontainers.image.licenses=MIT + - image_templates: + - "kolikons/{{.ProjectName}}:{{ .Version }}-amd64" + use: buildx + dockerfile: Dockerfile + goos: linux + goarch: amd64 + build_flag_templates: + - "--platform=linux/amd64" + - --label=org.opencontainers.image.title={{ .ProjectName }} + - --label=org.opencontainers.image.description={{ .ProjectName }} + - --label=org.opencontainers.image.url=https://github.com/kolikons/label-watch + - --label=org.opencontainers.image.source=https://github.com/kolikons/label-watch + - --label=org.opencontainers.image.version={{ .Version }} + - --label=org.opencontainers.image.revision={{ .FullCommit }} + - "--label=org.opencontainers.image.created={{.Date}}" + - --label=org.opencontainers.image.licenses=MIT + - image_templates: + - "kolikons/{{.ProjectName}}:{{ .Version }}-arm64" + use: buildx + dockerfile: Dockerfile + goos: linux + goarch: arm64 + build_flag_templates: + - "--platform=linux/arm64" + - --label=org.opencontainers.image.title={{ .ProjectName }} + - --label=org.opencontainers.image.description={{ .ProjectName }} + - --label=org.opencontainers.image.url=https://github.com/kolikons/label-watch + - --label=org.opencontainers.image.source=https://github.com/kolikons/label-watch + - --label=org.opencontainers.image.version={{ .Version }} + - --label=org.opencontainers.image.revision={{ .FullCommit }} + - "--label=org.opencontainers.image.created={{.Date}}" + - --label=org.opencontainers.image.licenses=MIT +docker_manifests: + - name_template: "kolikons/{{.ProjectName}}:{{ .Version }}" + image_templates: + - "kolikons/{{.ProjectName}}:{{ .Version }}-amd64" + - "kolikons/{{.ProjectName}}:{{ .Version }}-arm64" + - name_template: "kolikons/{{.ProjectName}}:latest" + image_templates: + - "kolikons/{{.ProjectName}}:{{ .Version }}-amd64" + - "kolikons/{{.ProjectName}}:{{ .Version }}-arm64" changelog: sort: asc filters: exclude: - - '^doc:' - - 'typo' + - "^doc:" + - "typo" signs: - artifacts: checksum args: ["--batch", "-u", "{{ .Env.GPG_FINGERPRINT }}", "--output", "${signature}", "--detach-sign", "${artifact}"] brews: - name: label-watch - tap: + repository: owner: kolikons name: homebrew-tap token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}" - folder: Formula homepage: "https://github.com/kolikons/label-watch" description: "label-watch checks a specific label on worker node then create an label" install: | diff --git a/README.md b/README.md index 1fbb281..179e5dd 100644 --- a/README.md +++ b/README.md @@ -12,11 +12,14 @@ When Kubernetes cluster's created, worker nodes is tagged as none. --- ## Usage of label-watch + label-watch supports two mode of running. The first one is outside kubernetes cluster and inside #### Example label-watch outside kuberntes cluster: + 1. You must have `kube config` that uses for connecting `kubectl` 2. Run command with the following flags: + ```sh $ kubectl get node AME STATUS ROLES AGE VERSION @@ -46,8 +49,10 @@ kind-worker2 Ready 2m36s v1.20.2 ``` #### Example label-watch inside kubernetes cluster: + 1. Modify ARGs in [scripts/deployment.yml](scripts/deployment.yml#22) 2. Deploy the kubernetes manifest from [scripts/deployment.yml](scripts/deployment.yml) + ```sh $ kubectl get node NAME STATUS ROLES AGE VERSION @@ -67,12 +72,15 @@ kind-worker2 Ready 13m v1.20.2 ``` # Helm + Add kolikons repository to Helm repos: + ```bash helm repo add kolikons https://kolikons.github.io/charts/ ``` Install label-watch + ```bash helm install label-watch kolikons/label-watch \ --namespace kube-system @@ -85,6 +93,7 @@ helm install label-watch kolikons/label-watch \ ```sh docker run kolikons/label-watch:latest ``` + --- # Homebrew @@ -92,14 +101,16 @@ docker run kolikons/label-watch:latest ```sh brew install kolikons/tap/label-watch ``` + --- ## label-watch ARGS + ```sh label-watch --help Usage of label-watch: -interval string - (optional) Start application in deamon mode. Supports format: 's', 'm', 'h'. + (optional) Start application in daemon mode. Supports format: 's', 'm', 'h'. -kubeconfig string (optional) absolute path to the kubeconfig file -label string diff --git a/charts/label-watch/Chart.yaml b/charts/label-watch/Chart.yaml index 403c2a5..e81a64a 100644 --- a/charts/label-watch/Chart.yaml +++ b/charts/label-watch/Chart.yaml @@ -7,5 +7,5 @@ maintainers: url: https://github.com/kolikons/label-watch sources: - https://github.com/kolikons/label-watch -version: 0.0.2 -appVersion: "0.0.2" +version: 1.0.0 +appVersion: "0.1.0" diff --git a/charts/label-watch/templates/deployment.yaml b/charts/label-watch/templates/deployment.yaml index 674efc5..67dcb99 100644 --- a/charts/label-watch/templates/deployment.yaml +++ b/charts/label-watch/templates/deployment.yaml @@ -17,9 +17,9 @@ spec: {{- end }} labels: {{- include "app.selectorLabels" . | nindent 8 }} -{{- range $key, $value := $.Values.podLabels }} + {{- range $key, $value := $.Values.podLabels }} {{ $key }}: {{ $value | quote }} -{{- end }} + {{- end }} spec: {{- with .Values.imagePullSecrets }} imagePullSecrets: @@ -43,7 +43,6 @@ spec: {{- toYaml .Values.resources | nindent 12 }} {{- with .Values.nodeSelector }} nodeSelector: - {{- toYaml . | nindent 8 }} {{- end }} {{- with .Values.affinity }} diff --git a/charts/label-watch/values.yaml b/charts/label-watch/values.yaml index 526ca67..08cb60a 100644 --- a/charts/label-watch/values.yaml +++ b/charts/label-watch/values.yaml @@ -21,10 +21,12 @@ podAnnotations: {} # -- Key/value pairs that are attached to pods. podLabels: {} -podSecurityContext: {} +podSecurityContext: + {} # fsGroup: 2000 -securityContext: {} +securityContext: + {} # capabilities: # drop: # - ALL @@ -36,7 +38,8 @@ securityContext: {} # choice for the user. This also increases chances charts run on environments with little # resources, such as Minikube. If you do want to specify resources, uncomment the following # lines, adjust them as necessary, and remove the curly braces after 'resources:'. -resources: {} +resources: + {} # limits: # cpu: 20m # memory: 20Mi @@ -45,11 +48,11 @@ resources: {} # memory: 10Mi label_watch: -# -- Supports format: 's', 'm', 'h' + # -- Supports format: 's', 'm', 'h' interval: 30m -# -- Label that's checking on worker nodes then set label in format node-role.kubernetes.io/VALUE_FROM_LABEL=true. -# Supports multiple labels via coma separator. -# Example: node-type,type,etc + # -- Label that's checking on worker nodes then set label in format node-role.kubernetes.io/VALUE_FROM_LABEL=true. + # Supports multiple labels via coma separator. + # Example: node-type,type,etc labels: node-type # -- Create Cluster Role to allow modify nodes diff --git a/cmd/cmd.go b/cmd/cmd.go index 34261a7..50d2d19 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -32,10 +32,10 @@ func opts() (c *Command, e error) { &c.Interval, "interval", "", - "(optional) Start application in deamon mode. Supports format: 's', 'm', 'h'.", + "(optional) Start application in daemon mode. Supports format: 's', 'm', 'h'.", ) - // Uses for finding label and conver to node-role. It's requered + // Uses for finding label and convert to node-role. It's required flag.StringVar( &c.Label, "label", diff --git a/go.mod b/go.mod index 17edbdf..3af8c9c 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/kolikons/label-watch -go 1.17 +go 1.18 replace k8s.io/client-go => k8s.io/client-go v0.23.4 diff --git a/go.sum b/go.sum index a9c1f5b..779ec32 100644 --- a/go.sum +++ b/go.sum @@ -45,6 +45,7 @@ github.com/Azure/go-autorest/autorest/adal v0.9.13 h1:Mp5hbtOePIzM8pJVRa3YLrWWmZ github.com/Azure/go-autorest/autorest/adal v0.9.13/go.mod h1:W/MM4U6nLxnIskrw4UwWzlHfGjwUS50aOsc/I3yuU8M= github.com/Azure/go-autorest/autorest/date v0.3.0 h1:7gUk1U5M/CQbp9WoqinNzJar+8KY+LPI6wiWrP/myHw= github.com/Azure/go-autorest/autorest/date v0.3.0/go.mod h1:BI0uouVdmngYNUzGWeSYnokU+TrmwEsOqdt8Y6sso74= +github.com/Azure/go-autorest/autorest/mocks v0.4.1 h1:K0laFcLE6VLTOwNgSxaGbUcLPuGXlNkbVvq4cW4nIHk= github.com/Azure/go-autorest/autorest/mocks v0.4.1/go.mod h1:LTp+uSrOhSkaKrUy935gNZuuIPPVsHlr9DSOxSayd+k= github.com/Azure/go-autorest/logger v0.2.1 h1:IG7i4p/mDa2Ce4TRyAO8IHnVhAVF3RFU+ZtXWSmf4Tg= github.com/Azure/go-autorest/logger v0.2.1/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZmbF5NWuPV8+WeEW8= diff --git a/pkg/label/label.go b/pkg/label/label.go index 16eaaa1..bb94d61 100644 --- a/pkg/label/label.go +++ b/pkg/label/label.go @@ -119,7 +119,7 @@ func RunLabel(c *cmd.Command) { } if nodePatched == false { - fmt.Printf("Node %s wasn't patched becuase missed Label: %s\n", node.GetName(), l) + fmt.Printf("Node %s wasn't patched because missed Label: %s\n", node.GetName(), l) } } } diff --git a/pkg/label/timer.go b/pkg/label/timer.go index 85c3f8f..dc7d3aa 100644 --- a/pkg/label/timer.go +++ b/pkg/label/timer.go @@ -13,7 +13,7 @@ import ( "golang.org/x/sync/errgroup" ) -// convertTime coverting cmd flags paramst to interval +// Convert time by converting command flags parameters to intervals. func convertTime(s string) time.Duration { d, err := time.ParseDuration(s) if err != nil { @@ -65,7 +65,7 @@ func RunTimerLabel(c *cmd.Command) { } }) - // wait for all errgroup goroutines + // wait for all err group goroutines err := g.Wait() if err != nil { if errors.Is(err, context.Canceled) { diff --git a/scripts/deployment.yml b/scripts/deployment.yml index d963e8c..ee184f1 100644 --- a/scripts/deployment.yml +++ b/scripts/deployment.yml @@ -18,14 +18,14 @@ spec: serviceAccountName: label-watch restartPolicy: Always containers: - - name: label-watch - args: - - -interval - - 30m - - -label - - node-type - image: kolikons/label-watch:0.0.1 - imagePullPolicy: Always + - name: label-watch + args: + - -interval + - 30m + - -label + - node-type + image: kolikons/label-watch:0.1.0 + imagePullPolicy: Always --- apiVersion: v1 kind: ServiceAccount @@ -40,18 +40,18 @@ kind: ClusterRole metadata: name: label-watch rules: -- apiGroups: [""] - resources: ["nodes"] - verbs: [ "list", "patch"] + - apiGroups: [""] + resources: ["nodes"] + verbs: ["list", "patch"] --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: label-watch subjects: -- kind: ServiceAccount - name: label-watch - namespace: default + - kind: ServiceAccount + name: label-watch + namespace: default roleRef: kind: ClusterRole name: label-watch