Skip to content

Commit

Permalink
[fix] Dockerfile base image (#9)
Browse files Browse the repository at this point in the history
* update Dockerfile base image

Signed-off-by: dongjiang1989 <[email protected]>
  • Loading branch information
dongjiang1989 authored Dec 26, 2023
1 parent 2f88d65 commit ef401fa
Show file tree
Hide file tree
Showing 21 changed files with 84 additions and 143 deletions.
51 changes: 1 addition & 50 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:

env:
# Common versions
GO_VERSION: '1.18'
GO_VERSION: '1.19'
GOLANGCI_VERSION: 'v1.49'

jobs:
Expand Down Expand Up @@ -59,9 +59,6 @@ jobs:
- name: Static Check
run: staticcheck ./...

- name: License Header Check
run: make check-license-header

lint:
runs-on: ubuntu-20.04
needs: detect-noop
Expand Down Expand Up @@ -93,49 +90,3 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
version: ${{ env.GOLANGCI_VERSION }}

check-diff:
runs-on: ubuntu-20.04
needs: detect-noop
if: needs.detect-noop.outputs.noop != 'true'

steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: true

- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

- name: Setup node
uses: actions/setup-node@v2
with:
node-version: '14'

- name: Install StaticCheck
run: go install honnef.co/go/tools/cmd/[email protected]

- name: Cache Go Dependencies
uses: actions/cache@v2
with:
path: .work/pkg
key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-pkg-

- name: Check code formatting
run: go install golang.org/x/tools/cmd/goimports && make fmt

- name: Run cross-build
run: make cross-build

- name: Check Diff
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.49.0
export PATH=$(pwd)/bin/:$PATH
make check-diff
- name: Cleanup binary
run: make build-cleanup
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ require (
github.com/stretchr/testify v1.8.0
golang.org/x/net v0.17.0
google.golang.org/grpc v1.56.3
k8s.io/api v0.22.0
k8s.io/apimachinery v0.22.5
k8s.io/client-go v0.22.0
k8s.io/kubernetes v1.19.15
k8s.io/api v0.24.17
k8s.io/apimachinery v0.24.17
k8s.io/client-go v0.24.17
k8s.io/kubernetes v1.24.17
k8s.io/utils v0.0.0-20211116205334-6203023598ed
)

Expand Down Expand Up @@ -57,7 +57,7 @@ require (
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/kube-openapi v0.0.0-20200805222855-6aeccd4b50c6 // indirect
sigs.k8s.io/structured-merge-diff/v3 v3.0.0 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace (
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,8 @@ sigs.k8s.io/kustomize v2.0.3+incompatible/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5
sigs.k8s.io/structured-merge-diff/v3 v3.0.0 h1:dOmIZBMfhcHS09XZkMyUgkq5trg3/jRyJYFZUiaOp8E=
sigs.k8s.io/structured-merge-diff/v3 v3.0.0/go.mod h1:PlARxl6Hbt/+BC80dRLi1qAmnMqwqDg62YvvVkZjemw=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3QxT9HOBeFhu6RdvsftgpsbFHBF5Cas6cDKZ0=
vbom.ml/util v0.0.0-20160121211510-db5cfe13f5cc/go.mod h1:so/NYdZXCz+E3ZpW0uAoCj6uzU2+8OWDFv/HxUSs7kI=
2 changes: 1 addition & 1 deletion hack/local/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.18.5-alpine as builder
FROM golang:1.19.13-alpine as builder

MAINTAINER [email protected]
LABEL blog="https://kubeservice.cn"
Expand Down
20 changes: 10 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
)

func init() {
flag.Set("logtostderr", "true")
_ = flag.Set("logtostderr", "true")
}

const (
Expand All @@ -60,12 +60,9 @@ const (
)

var (
endpoint = flag.String("endpoint", "unix://tmp/csi.sock", "CSI endpoint")
nodeID = flag.String("nodeid", "", "node id")
runAsController = flag.Bool("run-as-controller", false, "Only run as controller service")
driver = flag.String("driver", TypePluginLocal, "CSI Driver")
// Deprecated: rootDir is instead by KUBELET_ROOT_DIR env.
rootDir = flag.String("rootdir", "/var/lib/kubelet/csi-plugins", "Kubernetes root directory")
endpoint = flag.String("endpoint", "unix://tmp/csi.sock", "CSI endpoint")
nodeID = flag.String("nodeid", "", "node id")
driver = flag.String("driver", TypePluginLocal, "CSI Driver")
)

// CSI Plugin
Expand Down Expand Up @@ -162,7 +159,7 @@ func setLogAttribute(driver string) {
return
}

os.MkdirAll(LogfilePrefix, os.FileMode(0755))
_ = os.MkdirAll(LogfilePrefix, os.FileMode(0755))
logFile := LogfilePrefix + driver + ".log"
f, err := os.OpenFile(logFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
Expand All @@ -174,7 +171,10 @@ func setLogAttribute(driver string) {
f.Close()
timeStr := time.Now().Format("-2006-01-02-15:04:05")
timedLogfile := LogfilePrefix + driver + timeStr + ".log"
os.Rename(logFile, timedLogfile)
err = os.Rename(logFile, timedLogfile)
if err != nil {
os.Exit(1)
}
f, err = os.OpenFile(logFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
os.Exit(1)
Expand All @@ -191,5 +191,5 @@ func setLogAttribute(driver string) {
func healthHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
message := "Liveness probe is OK, time:" + time.Now().String()
w.Write([]byte(message))
_, _ = w.Write([]byte(message))
}
2 changes: 1 addition & 1 deletion pkg/local/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
}

volumeID := req.GetName()
response := &csi.CreateVolumeResponse{}
var response *csi.CreateVolumeResponse

// Get nodeID if pvc in topology mode.
nodeID := pickNodeID(req.GetAccessibilityRequirements())
Expand Down
3 changes: 0 additions & 3 deletions pkg/local/lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ type LVM struct {
idServer *identityServer
nodeServer csi.NodeServer
controllerServer *controllerServer

cap []*csi.VolumeCapability_AccessMode
cscap []*csi.ControllerServiceCapability
}

const (
Expand Down
2 changes: 1 addition & 1 deletion pkg/local/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
}

// xfs filesystem works on targetpath.
if volumeNewCreated == false {
if !volumeNewCreated {
if err := ns.resizeVolume(ctx, volumeID, vgName, targetPath); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
Expand Down
18 changes: 3 additions & 15 deletions pkg/local/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package lvm
import (
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"os/exec"
"path/filepath"
Expand All @@ -42,7 +42,7 @@ const (
)

// ErrParse is an error that is returned when parse operation fails
var ErrParse = errors.New("Cannot parse output of blkid")
var ErrParse = errors.New("cannot parse output of blkid")

// GetMetaData get host regionid, zoneid
func GetMetaData(resource string) string {
Expand All @@ -51,7 +51,7 @@ func GetMetaData(resource string) string {
return ""
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return ""
}
Expand Down Expand Up @@ -98,18 +98,6 @@ func checkFSType(devicePath string) (string, error) {
return "", ErrParse
}

func isVgExist(vgName string) (bool, error) {
vgCmd := fmt.Sprintf("%s vgdisplay %s | grep 'VG Name' | grep %s | grep -v grep | wc -l", NsenterCmd, vgName, vgName)
vgline, err := utils.Run(vgCmd)
if err != nil {
return false, err
}
if strings.TrimSpace(vgline) == "1" {
return true, nil
}
return false, nil
}

func getLocalDeviceNum() (int, error) {
return 0, nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/om/om.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ func CheckMessageFileIssue() {
// Fix Block Volume Reference Issue;
if GlobalConfigVar.IssueBlockReference && strings.Contains(line, "is still referenced from other Pods") {
if FixReferenceMountIssue(line) {

return
}
// Fix Orphaned Pod Issue
} else if GlobalConfigVar.IssueOrphanedPod && strings.Contains(line, "rphaned pod") && strings.Contains(line, "found, but volume paths are still present on disk") {
if FixOrphanedPodIssue(line) {

return
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/om/orphaned.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package om

import (
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -61,7 +60,7 @@ func FixOrphanedPodIssue(line string) bool {

// check kubernetes csi volumes
csiPodPath := filepath.Join(utils.KubeletRootDir, "/pods", orphanUID, "volumes/kubernetes.io~csi")
volumes, err := ioutil.ReadDir(csiPodPath)
volumes, err := os.ReadDir(csiPodPath)
if err != nil {
log.Warnf("OrphanPod: List Volumes with error: %s, line: %s", err.Error(), line)
return false
Expand Down
3 changes: 2 additions & 1 deletion pkg/options/genericoptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (

func TestFlag(t *testing.T) {
assert := assert.New(t)
flag.Set("kubeconfig", "aa")
err := flag.Set("kubeconfig", "aa")
assert.Nil(err)
assert.Equal("aa", Kubeconfig)
assert.Equal("", MasterURL)
}
1 change: 1 addition & 0 deletions pkg/utils/io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func TestGetBpsLimt(t *testing.T) {

bps, err = getBpsLimt("aa")
assert.NotNil(err)
assert.Equal(bps, 0)
}

func TestSetVolumeIOLimit(t *testing.T) {
Expand Down
13 changes: 1 addition & 12 deletions pkg/utils/mounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,6 @@ const (
expectedNumFieldsPerLine = 6
)

type findmntResponse struct {
FileSystems []fileSystem `json:"filesystems"`
}

type fileSystem struct {
Target string `json:"target"`
Propagation string `json:"propagation"`
FsType string `json:"fstype"`
Options string `json:"options"`
}

// MountPoint represents a single line in /proc/mounts or /etc/fstab.
type MountPoint struct { // nolint: golint
Device string
Expand Down Expand Up @@ -400,7 +389,7 @@ func (m *mounter) IsNotMountPoint(file string) (bool, error) {
return notMnt, notMntErr
}
// identified as mountpoint, so return this fact.
if notMnt == false {
if !notMnt {
return notMnt, nil
}

Expand Down
9 changes: 6 additions & 3 deletions pkg/utils/mounter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ func TestFormat(t *testing.T) {
testFsType = "ext4"
err = testMounter.Format(testSource, testFsType)
assert.NotNil(t, err)
RemoveContents(testSource)
err = RemoveContents(testSource)
assert.NotNil(t, err)
}

func TestMount(t *testing.T) {
Expand All @@ -44,7 +45,9 @@ func TestMount(t *testing.T) {
err = testMounter.MountBlock(mountedDevice, mountErrDir)
assert.NotNil(t, err)

RemoveContents(mountErrDir)
RemoveContents(".mounted/")
err = RemoveContents(mountErrDir)
assert.Nil(t, err)
err = RemoveContents(".mounted/")
assert.NotNil(t, err)

}
Loading

0 comments on commit ef401fa

Please sign in to comment.