Skip to content

Commit 3d8f08c

Browse files
authored
[Feature] Update dependencies & workflows (#21)
1 parent 7a5085f commit 3d8f08c

File tree

14 files changed

+266
-314
lines changed

14 files changed

+266
-314
lines changed

.github/workflows/build-and-release.yml

-65
This file was deleted.
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: '[PR] Presubmit Checks'
2+
on:
3+
pull_request:
4+
types: [opened, synchronize, reopened]
5+
push:
6+
branches:
7+
- main
8+
paths:
9+
- '**.go'
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
13+
cancel-in-progress: true
14+
15+
env:
16+
GO_VERSION: 'stable'
17+
18+
jobs:
19+
lint:
20+
runs-on: ubuntu-latest
21+
env:
22+
GOLANGCI_LINT_VERSION: v1.54.1
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v3
26+
- name: Install Go
27+
uses: actions/setup-go@v4
28+
with:
29+
go-version: ${{ env.GO_VERSION }}
30+
check-latest: true
31+
- name: Lint
32+
uses: golangci/golangci-lint-action@v3
33+
with:
34+
skip-pkg-cache: true
35+
skip-build-cache: true
36+
version: ${{ env.GOLANGCI_LINT_VERSION }}
37+
38+
test:
39+
runs-on: ubuntu-latest
40+
steps:
41+
- name: Checkout code
42+
uses: actions/checkout@v3
43+
- name: Install Go
44+
uses: actions/setup-go@v4
45+
with:
46+
go-version: ${{ env.GO_VERSION }}
47+
check-latest: true
48+
- name: Test
49+
run: make test

.github/workflows/release.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: "[Release] Create GitHub Release and Update krew-index"
2+
on:
3+
push:
4+
tags: ['*']
5+
concurrency:
6+
group: ci-${{ github.event_name }}-${{ github.ref }}
7+
cancel-in-progress: true
8+
permissions:
9+
contents: write
10+
env:
11+
GO_VERSION: stable
12+
jobs:
13+
release:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
- name: Install Go
18+
uses: actions/setup-go@v4
19+
with:
20+
go-version: ${{ env.GO_VERSION }}
21+
check-latest: true
22+
- uses: goreleaser/goreleaser-action@v4
23+
with:
24+
version: latest
25+
args: release --clean
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
- name: Update new version in krew-index
29+
uses: rajatjindal/[email protected]

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
### Above combination will ignore all files without extension ###
1313

1414
.idea/
15+
dist/
1516

1617
*.swp
1718
*.[oa]

.goreleaser.yaml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
before:
2+
hooks:
3+
- go mod tidy
4+
builds:
5+
- env:
6+
- CGO_ENABLED=0
7+
main: ./cmd/client
8+
binary: kubectl-relay
9+
goos:
10+
- windows
11+
- darwin
12+
- linux
13+
goarch:
14+
- amd64
15+
- arm64
16+
ignore:
17+
- goos: windows
18+
goarch: arm64
19+
gcflags:
20+
- all=-trimpath
21+
archives:
22+
-
23+
name_template: 'kubectl-relay_v{{ .Version }}_{{ .Os }}-{{ .Arch }}'
24+
checksum:
25+
name_template: 'checksums.txt'
26+
snapshot:
27+
name_template: "{{ incpatch .Version }}-next"
28+
changelog:
29+
use: github-native
30+
31+
# modelines, feel free to remove those if you don't want/use them:
32+
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
33+
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

Makefile

+1-29
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ GOBUILD = CGO_ENABLED=0 go build -trimpath -ldflags $(GO_LDFLAGS)
77

88
.PHONY: server-image push-server-image
99
server-image:
10-
docker build -t ghcr.io/knight42/krelay-server:$(IMAGE_TAG) -f manifests/Dockerfile .
10+
docker build -t ghcr.io/knight42/krelay-server:$(IMAGE_TAG) -f manifests/Dockerfile-server .
1111
push-server-image: server-image
1212
docker push ghcr.io/knight42/krelay-server:$(IMAGE_TAG)
1313

@@ -33,31 +33,3 @@ coverage:
3333
clean:
3434
rm -rf krelay*
3535
rm -rf kubectl-relay*
36-
37-
# Release
38-
PLATFORM_LIST = \
39-
darwin-amd64 \
40-
darwin-arm64 \
41-
linux-amd64 \
42-
linux-arm64 \
43-
windows-amd64
44-
darwin-%:
45-
GOARCH=$* GOOS=darwin $(GOBUILD) -o $(NAME)_$(VERSION)_$@/$(NAME) ./cmd/client
46-
47-
linux-%:
48-
GOARCH=$* GOOS=linux $(GOBUILD) -o $(NAME)_$(VERSION)_$@/$(NAME) ./cmd/client
49-
50-
windows-%:
51-
GOARCH=$* GOOS=windows $(GOBUILD) -o $(NAME)_$(VERSION)_$@/$(NAME).exe ./cmd/client
52-
53-
gz_releases=$(addsuffix .tar.gz, $(PLATFORM_LIST))
54-
$(gz_releases): %.tar.gz : %
55-
case $@ in windows-*) \
56-
tar czf $(NAME)_$(VERSION)_$@ -C $(NAME)_$(VERSION)_$</ ../LICENSE $(NAME).exe ;; \
57-
*) \
58-
tar czf $(NAME)_$(VERSION)_$@ -C $(NAME)_$(VERSION)_$</ ../LICENSE $(NAME) ;; \
59-
esac
60-
sha256sum $(NAME)_$(VERSION)_$@ > $(NAME)_$(VERSION)_$@.sha256
61-
62-
.PHONY: releases
63-
releases: $(gz_releases)

cmd/client/info.go

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package main
2+
3+
// These variables are set by goreleaser
4+
var (
5+
version string
6+
commit string
7+
date string
8+
)

cmd/client/main.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"encoding/json"
56
"errors"
67
"flag"
78
"fmt"
@@ -186,17 +187,6 @@ func (o *Options) Run(ctx context.Context, args []string) error {
186187
return nil
187188
}
188189

189-
func newSignalContext() context.Context {
190-
ctx, cancel := context.WithCancel(context.Background())
191-
sigCh := make(chan os.Signal, 1)
192-
signal.Notify(sigCh, os.Interrupt)
193-
go func() {
194-
<-sigCh
195-
cancel()
196-
}()
197-
return ctx
198-
}
199-
200190
func main() {
201191
klog.InitFlags(nil)
202192
cf := genericclioptions.NewConfigFlags(true)
@@ -212,10 +202,20 @@ func main() {
212202
service, ip and hostname rather than only pods.`,
213203
RunE: func(cmd *cobra.Command, args []string) error {
214204
if printVersion {
215-
fmt.Printf("Client version: %s\n", constants.ClientVersion)
216-
return nil
205+
return json.NewEncoder(cmd.OutOrStdout()).Encode(struct {
206+
Version string
207+
BuildDate string
208+
Commit string
209+
}{
210+
Version: version,
211+
BuildDate: date,
212+
Commit: commit,
213+
})
217214
}
218-
return o.Run(newSignalContext(), args)
215+
216+
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
217+
defer cancel()
218+
return o.Run(ctx, args)
219219
},
220220
SilenceUsage: true,
221221
}

cmd/server/main.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import (
55
"flag"
66
"fmt"
77
"net"
8+
"os"
9+
"os/signal"
10+
"syscall"
811
"time"
912

1013
"github.com/spf13/cobra"
@@ -80,7 +83,9 @@ func main() {
8083
c := cobra.Command{
8184
Use: constants.ServerName,
8285
RunE: func(cmd *cobra.Command, args []string) (err error) {
83-
return o.run(context.Background())
86+
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGTERM, os.Interrupt)
87+
defer cancel()
88+
return o.run(ctx)
8489
},
8590
SilenceUsage: true,
8691
}

0 commit comments

Comments
 (0)