Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make use of make container target from the release tools #146

Merged
merged 8 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/trivy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
export REGISTRY=test
export IMAGE_VERSION=latest
export DOCKER_CLI_EXPERIMENTAL=enabled
make container
make test-container

- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ FROM k8s.gcr.io/build-image/debian-base:bullseye-v1.0.0
RUN apt update && apt-mark unhold libcap2
RUN clean-install ca-certificates mount
# install updated packages to fix CVE issues
RUN clean-install libssl1.1 libgssapi-krb5-2 libk5crypto3 libkrb5-3 libkrb5support0 libgmp10
RUN clean-install libssl1.1 libgssapi-krb5-2 libk5crypto3 libkrb5-3 libkrb5support0 libgmp10


# Copy iscsiplugin.sh
COPY iscsiplugin.sh /iscsiplugin.sh
Expand Down
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ GOBIN ?= $(GOPATH)/bin
export GOPATH GOBIN

REGISTRY ?= test
IMAGE_VERSION ?= v0.1.0
IMAGENAME ?= iscsi-csi
# Output type of docker buildx build
OUTPUT_TYPE ?= docker
ARCH ?= amd64
IMAGE_TAG = $(REGISTRY)/$(IMAGENAME):$(IMAGE_VERSION)

.PHONY: container
container:
.PHONY: test-container
test-container:
make
docker buildx build --pull --output=type=$(OUTPUT_TYPE) --platform="linux/$(ARCH)" \
-t $(IMAGE_TAG) --build-arg ARCH=$(ARCH) .
Expand Down
22 changes: 11 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/kubernetes-csi/csi-lib-iscsi v0.0.0-20211110090527-5c802c48a124
github.com/kubernetes-csi/csi-lib-utils v0.10.0
github.com/spf13/cobra v1.2.1
golang.org/x/net v0.0.0-20211209124913-491a49abca63
golang.org/x/net v0.0.0-20220909164309-bea034e7d591
google.golang.org/grpc v1.40.0
k8s.io/klog/v2 v2.30.0
k8s.io/kubernetes v1.23.0
Expand All @@ -19,13 +19,13 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.2.0 // indirect
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logr/logr v1.2.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.5 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
Expand All @@ -36,22 +36,22 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/opencontainers/selinux v1.8.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_golang v1.13.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.28.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e // indirect
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
golang.org/x/sys v0.0.0-20220913175220-63ea55921009 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20210831024726-fe130286e0e2 // indirect
google.golang.org/protobuf v1.27.1 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.23.2 // indirect
k8s.io/apimachinery v0.23.2 // indirect
k8s.io/apiserver v0.23.2 // indirect
Expand Down
54 changes: 40 additions & 14 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion hack/verify-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ ${PKG_ROOT}/hack/verify-govet.sh
#${PKG_ROOT}/hack/verify-golint.sh
${PKG_ROOT}/hack/verify-yamllint.sh
${PKG_ROOT}/hack/verify-boilerplate.sh
${PKG_ROOT}/hack/verify-spelling.sh
#${PKG_ROOT}/hack/verify-spelling.sh
${PKG_ROOT}/hack/verify-gomod.sh
12 changes: 10 additions & 2 deletions pkg/lib/iscsi/OWNERS
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# See the OWNERS docs: https://git.k8s.io/community/contributors/guide/owners.md

approvers:
- saad-ali
- humblec
- j-griffith
reviews:
- jsafrane
- msau42
- saad-ali
- xing-yang
reviewers:
- humblec
- j-griffith
- jsafrane
- msau42
- saad-ali
- xing-yang
13 changes: 10 additions & 3 deletions pkg/lib/iscsi/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
module github.com/kubernetes-csi/csi-lib-iscsi

go 1.15
go 1.19

require (
github.com/prashantv/gostub v1.0.0
github.com/stretchr/testify v1.7.0
github.com/prashantv/gostub v1.1.0
github.com/stretchr/testify v1.8.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
11 changes: 11 additions & 0 deletions pkg/lib/iscsi/go.sum
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prashantv/gostub v1.0.0 h1:wTzvgO04xSS3gHuz6Vhuo0/kvWelyJxwNS0IRBPAwGY=
github.com/prashantv/gostub v1.0.0/go.mod h1:dP1v6T1QzyGJJKFocwAU0lSZKpfjstjH8TlhkEU0on0=
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
19 changes: 15 additions & 4 deletions pkg/lib/iscsi/iscsi/iscsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,10 @@ func (c *Connector) Connect() (string, error) {
c.MountTargetDevice = mountTargetDevice
if err != nil {
debug.Printf("Connect failed: %v", err)
RemoveSCSIDevices(c.Devices...)
err := RemoveSCSIDevices(c.Devices...)
if err != nil {
return "", err
}
c.MountTargetDevice = nil
c.Devices = []Device{}
return "", err
Expand Down Expand Up @@ -390,15 +393,21 @@ func (c *Connector) discoverTarget(targetIqn string, iFace string, portal string
func Disconnect(targetIqn string, targets []string) {
for _, target := range targets {
targetPortal := strings.Split(target, ":")[0]
Logout(targetIqn, targetPortal)
err := Logout(targetIqn, targetPortal)
if err != nil {
return
}
}

deleted := map[string]bool{}
if _, ok := deleted[targetIqn]; ok {
return
}
deleted[targetIqn] = true
DeleteDBEntry(targetIqn)
err := DeleteDBEntry(targetIqn)
if err != nil {
return
}
}

// Disconnect performs a disconnect operation from an appliance.
Expand Down Expand Up @@ -667,7 +676,9 @@ func GetConnectorFromFile(filePath string) (*Connector, error) {
for _, device := range c.Devices {
devicePaths = append(devicePaths, device.GetPath())
}

if c.MountTargetDevice == nil {
return nil, fmt.Errorf("mountTargetDevice in the connector is nil")
}
if devices, err := GetSCSIDevices([]string{c.MountTargetDevice.GetPath()}, false); err != nil {
return nil, err
} else {
Expand Down
18 changes: 11 additions & 7 deletions pkg/lib/iscsi/iscsi/iscsi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,23 @@ node.conn[0].iscsi.OFMarker = No
# END RECORD
`

const emptyTransportName = "iface.transport_name = \n"
const emptyDbRecord = "\n\n\n"
const testRootFS = "/tmp/iscsi-tests"
const (
emptyTransportName = "iface.transport_name = \n"
emptyDbRecord = "\n\n\n"
testRootFS = "/tmp/iscsi-tests"
)

func makeFakeExecCommand(exitStatus int, stdout string) func(string, ...string) *exec.Cmd {
return func(command string, args ...string) *exec.Cmd {
cs := []string{"-test.run=TestExecCommandHelper", "--", command}
cs = append(cs, args...)
cmd := exec.Command(os.Args[0], cs...)
es := strconv.Itoa(exitStatus)
cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1",
cmd.Env = []string{
"GO_WANT_HELPER_PROCESS=1",
"STDOUT=" + stdout,
"EXIT_STATUS=" + es}
"EXIT_STATUS=" + es,
}
return cmd
}
}
Expand Down Expand Up @@ -165,7 +169,7 @@ func preparePaths(devices []Device) error {
}

for _, filename := range []string{"delete", "state"} {
if err := ioutil.WriteFile(filepath.Join(devicePath, filename), []byte(""), 0600); err != nil {
if err := ioutil.WriteFile(filepath.Join(devicePath, filename), []byte(""), 0o600); err != nil {
return err
}
}
Expand Down Expand Up @@ -735,7 +739,7 @@ func TestConnectorPersistance(t *testing.T) {
assert.NotNil(err)
assert.IsType(&os.PathError{}, err)

ioutil.WriteFile("/tmp/connector.json", []byte("not a connector"), 0600)
ioutil.WriteFile("/tmp/connector.json", []byte("not a connector"), 0o600)
_, err = GetConnectorFromFile("/tmp/connector.json")
assert.NotNil(err)
assert.IsType(&json.SyntaxError{}, err)
Expand Down
29 changes: 19 additions & 10 deletions pkg/lib/iscsi/iscsi/iscsiadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func iscsiadmDebug(output string, cmdError error) {
}

// ListInterfaces returns a list of all iscsi interfaces configured on the node
/// along with the raw output in Response.StdOut we add the convenience of
// along with the raw output in Response.StdOut we add the convenience of
// returning a list of entries found
func ListInterfaces() ([]string, error) {
debug.Println("Begin ListInterface...")
Expand All @@ -65,16 +65,21 @@ func CreateDBEntry(tgtIQN, portal, iFace string, discoverySecrets, sessionSecret

if discoverySecrets.SecretsType == "chap" {
debug.Printf("Setting CHAP Discovery...")
createCHAPEntries(baseArgs, discoverySecrets, true)
err := createCHAPEntries(baseArgs, discoverySecrets, true)
if err != nil {
return err
}
}

if sessionSecrets.SecretsType == "chap" {
debug.Printf("Setting CHAP Session...")
createCHAPEntries(baseArgs, sessionSecrets, false)
err := createCHAPEntries(baseArgs, sessionSecrets, false)
if err != nil {
return err
}
}

return err

}

// Discoverydb discovers the iscsi target
Expand All @@ -94,7 +99,7 @@ func Discoverydb(tp, iface string, discoverySecrets Secrets, chapDiscovery bool)

_, err = iscsiCmd(append(baseArgs, []string{"--discover"}...)...)
if err != nil {
//delete the discoverydb record
// delete the discoverydb record
iscsiCmd(append(baseArgs, []string{"-o", "delete"}...)...)
return fmt.Errorf("failed to sendtargets to portal %s, err: %v", tp, err)
}
Expand All @@ -105,10 +110,12 @@ func createCHAPEntries(baseArgs []string, secrets Secrets, discovery bool) error
args := []string{}
debug.Printf("Begin createCHAPEntries (discovery=%t)...", discovery)
if discovery {
args = append(baseArgs, []string{"-o", "update",
args = append(baseArgs, []string{
"-o", "update",
"-n", "discovery.sendtargets.auth.authmethod", "-v", "CHAP",
"-n", "discovery.sendtargets.auth.username", "-v", secrets.UserName,
"-n", "discovery.sendtargets.auth.password", "-v", secrets.Password}...)
"-n", "discovery.sendtargets.auth.password", "-v", secrets.Password,
}...)
if secrets.UserNameIn != "" {
args = append(args, []string{"-n", "discovery.sendtargets.auth.username_in", "-v", secrets.UserNameIn}...)
}
Expand All @@ -118,10 +125,12 @@ func createCHAPEntries(baseArgs []string, secrets Secrets, discovery bool) error

} else {

args = append(baseArgs, []string{"-o", "update",
args = append(baseArgs, []string{
"-o", "update",
"-n", "node.session.auth.authmethod", "-v", "CHAP",
"-n", "node.session.auth.username", "-v", secrets.UserName,
"-n", "node.session.auth.password", "-v", secrets.Password}...)
"-n", "node.session.auth.password", "-v", secrets.Password,
}...)
if secrets.UserNameIn != "" {
args = append(args, []string{"-n", "node.session.auth.username_in", "-v", secrets.UserNameIn}...)
}
Expand Down Expand Up @@ -150,7 +159,7 @@ func Login(tgtIQN, portal string) error {
debug.Println("Begin Login...")
baseArgs := []string{"-m", "node", "-T", tgtIQN, "-p", portal}
if _, err := iscsiCmd(append(baseArgs, []string{"-l"}...)...); err != nil {
//delete the node record from database
// delete the node record from database
iscsiCmd(append(baseArgs, []string{"-o", "delete"}...)...)
return fmt.Errorf("failed to sendtargets to portal %s, err: %v", portal, err)
}
Expand Down
1 change: 0 additions & 1 deletion pkg/lib/iscsi/iscsi/iscsiadm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ func TestCreateDBEntry(t *testing.T) {
}
})
}

}

func TestListInterfaces(t *testing.T) {
Expand Down
11 changes: 6 additions & 5 deletions pkg/lib/iscsi/iscsi/multipath.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package iscsi

import (
"context"
"errors"
"fmt"
"os"
"os/exec"
Expand All @@ -17,7 +18,7 @@ type path struct {
Device string `json:"dev"`
}

// ExecWithTimeout execute a command with a timeout and returns an error if timeout is excedeed
// ExecWithTimeout execute a command with a timeout and returns an error if timeout is exceeded
func ExecWithTimeout(command string, args []string, timeout time.Duration) ([]byte, error) {
debug.Printf("Executing command '%v' with args: '%v'.\n", command, args)

Expand All @@ -35,13 +36,14 @@ func ExecWithTimeout(command string, args []string, timeout time.Duration) ([]by
// We want to check the context error to see if the timeout was executed.
// The error returned by cmd.Output() will be OS specific based on what
// happens when a process is killed.
if ctx.Err() == context.DeadlineExceeded {
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
debug.Printf("Command '%s' timeout reached.\n", command)
return nil, ctx.Err()
}

if err != nil {
if ee, ok := err.(*exec.ExitError); ok {
var ee *exec.ExitError
if ok := errors.Is(err, ee); ok {
debug.Printf("Non-zero exit code: %s\n", err)
err = fmt.Errorf("%s", ee.Stderr)
}
Expand All @@ -58,7 +60,6 @@ func FlushMultipathDevice(device *Device) error {

timeout := 5 * time.Second
_, err := execWithTimeout("multipath", []string{"-f", devicePath}, timeout)

if err != nil {
if _, e := osStat(devicePath); os.IsNotExist(e) {
debug.Printf("Multipath device %v has been removed.\n", devicePath)
Expand All @@ -71,7 +72,7 @@ func FlushMultipathDevice(device *Device) error {
}
}

debug.Printf("Finshed flushing multipath device %v.\n", devicePath)
debug.Printf("Finished flushing multipath device %v.\n", devicePath)
return nil
}

Expand Down
Loading