From 8aca7b1b71b3293b14bfd9990bbfac1c28b4ce4d Mon Sep 17 00:00:00 2001 From: Tomofumi Hayashi Date: Tue, 3 Dec 2024 14:13:50 +0900 Subject: [PATCH] Update golang vendor and fix github ci and fix lint --- .github/workflows/build.yml | 2 +- .github/workflows/image-build.yml | 22 +++++++++++++--------- .github/workflows/test.yml | 2 +- .gitignore | 2 ++ Dockerfile | 11 +++-------- Dockerfile.openshift | 14 +++++++------- cmd/route-override/route-override.go | 11 +++++------ cmd/route-override/route-override_test.go | 2 ++ go.mod | 4 ++-- vendor/modules.txt | 2 +- 10 files changed, 37 insertions(+), 35 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 564bc7d5..f50a0d69 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,7 @@ jobs: build: strategy: matrix: - go-version: [1.17.x, 1.18.x] + go-version: [1.22.x, 1.23.x] goarch: [386, amd64, arm, arm64, ppc64le, s390x] os: [ubuntu-latest] #, macos-latest, windows-latest] runs-on: ${{ matrix.os }} diff --git a/.github/workflows/image-build.yml b/.github/workflows/image-build.yml index ea27c811..972fca8e 100644 --- a/.github/workflows/image-build.yml +++ b/.github/workflows/image-build.yml @@ -24,15 +24,19 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out code into the Go module directory - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v3 - - name: Build container image - uses: docker/build-push-action@v2 - with: - context: . - push: false - tags: ghcr.io/${{ github.repository }}:latest-origin - file: Dockerfile.openshift + - name: Download OKD Builder Dockerfile + run: curl https://raw.githubusercontent.com/okd-project/images/main/builder/Dockerfile -o okd-builder.Dockerfile + + - name: Create root for builder + run: mkdir root + + - name: Organically build golang builder image + run: docker build -t local/okdbuilder:latest -f okd-builder.Dockerfile . + + - name: Organically build Multus origin image + run: docker build -t local/multus-cni:latest-origin -f Dockerfile.openshift . diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 32ce944d..4050518d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,7 @@ jobs: test: strategy: matrix: - go-version: [1.17.x, 1.18.x] + go-version: [1.22.x, 1.23.x] os: [ubuntu-latest] runs-on: ${{ matrix.os }} steps: diff --git a/.gitignore b/.gitignore index 8084ced5..a98d6f1c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.o *.a *.so +okd-builder.Dockerfile # Folders _obj @@ -28,5 +29,6 @@ gopath/ .vagrant .idea /release-* +root/ *~ diff --git a/Dockerfile b/Dockerfile index 7af99b30..7229ac65 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,13 @@ # This Dockerfile is used to build the image available on DockerHub -FROM centos:centos7 as build +FROM golang:1.23 AS build # Add everything ADD . /usr/src/cni-route-override -ENV INSTALL_PKGS "git golang" -RUN rpm --import https://mirror.go-repo.io/centos/RPM-GPG-KEY-GO-REPO && \ - curl -s https://mirror.go-repo.io/centos/go-repo.repo | tee /etc/yum.repos.d/go-repo.repo && \ - yum install -y $INSTALL_PKGS && \ - rpm -V $INSTALL_PKGS && \ - cd /usr/src/cni-route-override && \ +RUN cd /usr/src/cni-route-override && \ ./build_linux.sh FROM alpine -LABEL org.opencontainers.image.source https://github.com/redhat-nfvpe/cni-route-override +LABEL org.opencontainers.image.source="https://github.com/redhat-nfvpe/cni-route-override" COPY --from=build /usr/src/cni-route-override/bin/route-override / WORKDIR / diff --git a/Dockerfile.openshift b/Dockerfile.openshift index cbb3c4b7..c3ac399a 100644 --- a/Dockerfile.openshift +++ b/Dockerfile.openshift @@ -1,16 +1,16 @@ -# This dockerfile is used for building for OpenShift -FROM openshift/origin-release:golang-1.16 as rhel8 +# The okd-builder image is locally built from https://raw.githubusercontent.com/okd-project/images/main/okd-builder.Dockerfile +FROM local/okdbuilder:latest AS builder + ADD . /usr/src/route-override WORKDIR /usr/src/route-override ENV CGO_ENABLED=0 ENV VERSION=rhel8 COMMIT=unset RUN ./build_linux.sh -WORKDIR / -FROM openshift/origin-base -LABEL org.opencontainers.image.source https://github.com/redhat-nfvpe/cni-route-override -COPY --from=rhel8 /usr/src/route-override/bin/route-override /usr/src/route-override/bin/route-override -COPY --from=rhel8 /usr/src/route-override/bin/route-override /usr/src/route-override/rhel8/bin/route-override +FROM quay.io/openshift/origin-base:latest +LABEL org.opencontainers.image.source="https://github.com/redhat-nfvpe/cni-route-override" +COPY --from=builder /usr/src/route-override/bin/route-override /usr/src/route-override/bin/route-override +COPY --from=builder /usr/src/route-override/bin/route-override /usr/src/route-override/rhel8/bin/route-override LABEL io.k8s.display-name="route override CNI" \ io.k8s.description="This is a component of OpenShift Container Platform and provides a CNI plugin to override routes" \ diff --git a/cmd/route-override/route-override.go b/cmd/route-override/route-override.go index bfd7573f..91d609a6 100644 --- a/cmd/route-override/route-override.go +++ b/cmd/route-override/route-override.go @@ -15,7 +15,6 @@ // This is a "meta-plugin". It reads in its own netconf, it does not create // any network interface but just changes route information given from // previous cni plugins - package main import ( @@ -65,11 +64,11 @@ type IPAMArgs struct { } /* -type RouteOverrideArgs struct { - types.CommonArgs -} + type RouteOverrideArgs struct { + types.CommonArgs + } */ -func parseConf(data []byte, envArgs string) (*RouteOverrideConfig, error) { +func parseConf(data []byte, _ string) (*RouteOverrideConfig, error) { conf := RouteOverrideConfig{FlushRoutes: false} if err := json.Unmarshal(data, &conf); err != nil { @@ -309,7 +308,7 @@ func cmdAdd(args *skel.CmdArgs) error { return types.PrintResult(newResult, overrideConf.CNIVersion) } -func cmdDel(args *skel.CmdArgs) error { +func cmdDel(_ *skel.CmdArgs) error { // TODO: the settings are not reverted to the previous values. Reverting the // settings is not useful when the whole container goes away but it could be // useful in scenarios where plugins are added and removed at runtime. diff --git a/cmd/route-override/route-override_test.go b/cmd/route-override/route-override_test.go index 210005f7..7f5436ff 100644 --- a/cmd/route-override/route-override_test.go +++ b/cmd/route-override/route-override_test.go @@ -14,6 +14,8 @@ package main +// disable dot-imports only for testing +//revive:disable:dot-imports import ( //"fmt" //"os" diff --git a/go.mod b/go.mod index fbbcae2f..af728cc0 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/redhat-nfvpe/cni-route-override -go 1.17 +go 1.22 require ( github.com/containernetworking/cni v1.1.2 @@ -14,7 +14,7 @@ require ( github.com/fsnotify/fsnotify v1.4.9 // indirect github.com/nxadm/tail v1.4.8 // indirect github.com/vishvananda/netns v0.0.0-20180720170159-13995c7128cc // indirect - golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect + golang.org/x/net v0.31.0 // indirect golang.org/x/sys v0.5.0 // indirect golang.org/x/text v0.7.0 // indirect gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect diff --git a/vendor/modules.txt b/vendor/modules.txt index 0d4ebe80..4d395ba7 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -63,7 +63,7 @@ github.com/vishvananda/netlink/nl # github.com/vishvananda/netns v0.0.0-20180720170159-13995c7128cc ## explicit github.com/vishvananda/netns -# golang.org/x/net v0.0.0-20220722155237-a158d28d115b => golang.org/x/net v0.7.0 +# golang.org/x/net v0.31.0 => golang.org/x/net v0.7.0 ## explicit; go 1.17 golang.org/x/net/html golang.org/x/net/html/atom