Skip to content

Commit

Permalink
fix: golangci-lint errors fixed
Browse files Browse the repository at this point in the history
Signed-off-by: James Lu <[email protected]>
  • Loading branch information
mantissahz authored and derekbit committed May 30, 2024
1 parent 16f15cc commit 8d20807
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 14 deletions.
28 changes: 21 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ jobs:
build:
name: Build Binaries
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout Codes
uses: actions/checkout@v4
Expand All @@ -20,8 +23,8 @@ jobs:
run: make ci

# Run e2e test
#- name: Run E2e Test
# run: make e2e-test
- name: Run e2e Test
run: make e2e-test

# Upload binaries
- name: Upload Binaries
Expand All @@ -33,6 +36,9 @@ jobs:
build_push_image:
name: Build and Push Images
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
needs: build
if: ${{ startsWith(github.ref, 'refs/heads/') || startsWith(github.ref, 'refs/tags/') }}
steps:
Expand All @@ -59,14 +65,22 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Declare Branch
- name: Read Secrets
uses: rancher-eio/read-vault-secrets@main
if: ${{ inputs.push == true }}
with:
secrets: |
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials username | DOCKER_USERNAME ;
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials password | DOCKER_PASSWORD
- name: Login to Docker Hub
run: |
echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> "$GITHUB_ENV"
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
username: ${{ env.DOCKER_USERNAME }}
password: ${{ env.DOCKER_PASSWORD }}

# rancher/local-path-provisioner image
- name: docker-publish
Expand All @@ -75,7 +89,7 @@ jobs:
with:
context: ./
push: true
platforms: linux/amd64,linux/arm64
platforms: linux/amd64,linux/arm64, linux/arm
tags: rancher/local-path-provisioner:${{ env.branch }}-head
file: package/Dockerfile

Expand All @@ -85,6 +99,6 @@ jobs:
with:
context: ./
push: true
platforms: linux/amd64,linux/arm64
platforms: linux/amd64,linux/arm64, linux/arm
tags: rancher/local-path-provisioner:${{ github.ref_name }}
file: package/Dockerfile
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ var (
EnvConfigMountPath = "CONFIG_MOUNT_PATH"
)

func cmdNotFound(c *cli.Context, command string) {
func cmdNotFound(_ *cli.Context, command string) {
panic(fmt.Errorf("Unrecognized command: %s", command))
}

func onUsageError(c *cli.Context, err error, isSubcommand bool) error {
panic(fmt.Errorf("Usage error, please check your command"))
func onUsageError(_ *cli.Context, err error, _ bool) error {
panic(errors.Wrap(err, "Usage error, please check your command"))
}

func RegisterShutdownChannel(cancelFn context.CancelFunc) {
Expand Down
3 changes: 2 additions & 1 deletion package/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
FROM alpine

ARG TARGETPLATFORM
RUN if [ "$TARGETPLATFORM" != "linux/amd64" ] && [ "$TARGETPLATFORM" != "linux/arm64" ]; then \
RUN if [ "$TARGETPLATFORM" != "linux/amd64" ] && [ "$TARGETPLATFORM" != "linux/arm64" ] && [ "$TARGETPLATFORM" != "linux/arm/v7" ]; then \
echo "Error: Unsupported TARGETPLATFORM: $TARGETPLATFORM" && \
exit 1; \
fi

ENV ARCH ${TARGETPLATFORM#linux/}
ENV ARCH ${ARCH%/v7}

RUN apk update
RUN apk upgrade --no-cache busybox zlib
Expand Down
6 changes: 3 additions & 3 deletions provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ type pvMetadata struct {
func pathFromPattern(pattern string, opts pvController.ProvisionOptions) (string, error) {
metadata := pvMetadata{
PVName: opts.PVName,
PVC: opts.PVC.ObjectMeta,
PVC: opts.PVC.ObjectMeta,
}

tpl, err := template.New("pathPattern").Parse(pattern)
Expand All @@ -317,7 +317,7 @@ func pathFromPattern(pattern string, opts pvController.ProvisionOptions) (string
return buf.String(), nil
}

func (p *LocalPathProvisioner) Provision(ctx context.Context, opts pvController.ProvisionOptions) (*v1.PersistentVolume, pvController.ProvisioningState, error) {
func (p *LocalPathProvisioner) Provision(_ context.Context, opts pvController.ProvisionOptions) (*v1.PersistentVolume, pvController.ProvisioningState, error) {
cfg, err := p.pickConfig(opts.StorageClass.Name)
if err != nil {
return nil, pvController.ProvisioningFinished, err
Expand Down Expand Up @@ -462,7 +462,7 @@ func (p *LocalPathProvisioner) provisionFor(opts pvController.ProvisionOptions,
}, pvController.ProvisioningFinished, nil
}

func (p *LocalPathProvisioner) Delete(ctx context.Context, pv *v1.PersistentVolume) (err error) {
func (p *LocalPathProvisioner) Delete(_ context.Context, pv *v1.PersistentVolume) (err error) {
cfg, err := p.pickConfig(pv.Spec.StorageClassName)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ fi
LINKFLAGS="-X main.VERSION=$VERSION"
CGO_ENABLED=0 GOARCH=amd64 go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/local-path-provisioner-amd64
CGO_ENABLED=0 GOARCH=arm64 go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/local-path-provisioner-arm64
CGO_ENABLED=0 GOARCH=arm go build -ldflags "$LINKFLAGS $OTHER_LINKFLAGS" -o bin/local-path-provisioner-arm
if [ "$CROSS" = "true" ] && [ "$ARCH" = "amd64" ]; then
GOOS=darwin go build -ldflags "$LINKFLAGS" -o bin/local-path-provisioner-darwin
GOOS=windows go build -ldflags "$LINKFLAGS" -o bin/local-path-provisioner-windows
Expand Down
1 change: 1 addition & 0 deletions test/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
)

func createCmd(t *testing.T, cmd, kustomizeDir string, envs []string, callback func(*exec.Cmd)) *exec.Cmd {
t.Logf("creating command: %s", cmd)
c := exec.Command("bash", "-c", cmd)
c.Env = append(os.Environ(), envs...)
c.Dir = kustomizeDir
Expand Down

0 comments on commit 8d20807

Please sign in to comment.