Skip to content

Commit

Permalink
Merge pull request #208 from red-hat-storage/sync_us--main
Browse files Browse the repository at this point in the history
Syncing latest changes from upstream main for kubernetes-csi-addons
  • Loading branch information
openshift-merge-bot[bot] authored Sep 25, 2024
2 parents a2e9251 + b0ae317 commit ecc4d7b
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup Golang
uses: actions/setup-go@v5
with:
go-version: "1.22"
go-version-file: go.mod

- name: Generate the bundle contents
run: make bundle
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.22'
go-version-file: go.mod
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/kind-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Set up Golang
uses: actions/setup-go@v5
with:
go-version: "1.22"
go-version-file: go.mod

- name: Build container container image
uses: docker/build-push-action@v6
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tag-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup Golang
uses: actions/setup-go@v5
with:
go-version: "1.22"
go-version-file: go.mod

- name: Generate the bundle contents
run: make bundle TAG=${{ github.ref_name }}
Expand Down Expand Up @@ -129,7 +129,7 @@ jobs:
- name: Setup Golang
uses: actions/setup-go@v5
with:
go-version: "1.22"
go-version-file: go.mod

- name: Generate manifests for installation by kubectl
run: make manifests TAG=${{ github.ref_name }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup Golang
uses: actions/setup-go@v5
with:
go-version: "1.22"
go-version-file: go.mod

- name: Generate the bundle contents
run: make bundle
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test-golang.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Set up Golang
uses: actions/setup-go@v5
with:
go-version: "1.22"
go-version-file: go.mod

- name: Install Protoc
# action @v1.3.0 can install protoc 3.19, @v2 installs protoc v21.0+
Expand Down Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Set up Golang
uses: actions/setup-go@v5
with:
go-version: "1.22"
go-version-file: go.mod

- name: Verify Go modules
run: go mod verify
Expand All @@ -61,7 +61,7 @@ jobs:
- name: Set up Golang
uses: actions/setup-go@v5
with:
go-version: "1.22"
go-version-file: go.mod

- name: Vendor all dependencies
run: go mod vendor
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/csi-addons/kubernetes-csi-addons

go 1.22.6
go 1.22.5

toolchain go1.22.6

require (
github.com/container-storage-interface/spec v1.10.0
Expand Down
20 changes: 9 additions & 11 deletions internal/controller/csiaddons/csiaddonsnode_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,6 @@ func (r *CSIAddonsNodeReconciler) resolveEndpoint(ctx context.Context, rawURL st
return rawURL, nil
} else if err != nil {
return "", err
} else if namespace == "" {
return "", fmt.Errorf("failed to get namespace from endpoint %q", rawURL)
} else if podname == "" {
return "", fmt.Errorf("failed to get pod from endpoint %q", rawURL)
}

pod := &corev1.Pod{}
Expand Down Expand Up @@ -250,15 +246,17 @@ func parseEndpoint(rawURL string) (string, string, string, error) {
}

// split hostname -> pod.namespace
parts := strings.Split(endpoint.Hostname(), ".")
podname := parts[0]
namespace := ""
if len(parts) == 2 {
namespace = parts[1]
} else if len(parts) > 2 {
return "", "", "", fmt.Errorf("hostname %q is not in <pod>.<namespace> format", endpoint.Hostname())
hostName := endpoint.Hostname()
lastIndex := strings.LastIndex(hostName, ".")

// check for empty podname and namespace
if lastIndex <= 0 || lastIndex == len(hostName)-1 {
return "", "", "", fmt.Errorf("hostname %q is not in <pod>.<namespace> format", hostName)
}

podname := hostName[0:lastIndex]
namespace := hostName[lastIndex+1:]

return namespace, podname, endpoint.Port(), nil
}

Expand Down
22 changes: 16 additions & 6 deletions internal/controller/csiaddons/csiaddonsnode_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,30 @@ func TestParseEndpoint(t *testing.T) {
_, _, _, err := parseEndpoint("1.2.3.4:5678")
assert.True(t, errors.Is(err, errLegacyEndpoint))

namespace, podname, port, err := parseEndpoint("pod://pod-name:5678")
// test empty namespace
_, _, _, err = parseEndpoint("pod://pod-name:5678")
assert.Error(t, err)

// test empty namespace
_, _, _, err = parseEndpoint("pod://pod-name.:5678")
assert.Error(t, err)

namespace, podname, port, err := parseEndpoint("pod://pod-name.csi-addons:5678")
assert.NoError(t, err)
assert.Equal(t, namespace, "")
assert.Equal(t, namespace, "csi-addons")
assert.Equal(t, podname, "pod-name")
assert.Equal(t, port, "5678")

namespace, podname, port, err = parseEndpoint("pod://pod-name.csi-addons:5678")
namespace, podname, port, err = parseEndpoint("pod://csi.pod.ns-cluster.local:5678")
assert.NoError(t, err)
assert.Equal(t, namespace, "csi-addons")
assert.Equal(t, podname, "pod-name")
assert.Equal(t, namespace, "local")
assert.Equal(t, podname, "csi.pod.ns-cluster")
assert.Equal(t, port, "5678")

_, _, _, err = parseEndpoint("pod://pod.ns.cluster.local:5678")
// test empty podname
_, _, _, err = parseEndpoint("pod://.local:5678")
assert.Error(t, err)

}

func TestParseCapabilities(t *testing.T) {
Expand Down

0 comments on commit ecc4d7b

Please sign in to comment.