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

build: include -version option for csi-addons executable #397

Merged
merged 3 commits into from
Jun 27, 2023
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ FROM quay.io/projectquay/golang:1.20 as builder
# Copy the contents of the repository
ADD . /workspace/go/src/github.com/csi-addons/kubernetes-csi-addons

ENV GOPATH=/workspace/go
ENV GOPATH=/workspace/go CGO_ENABLED=0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GOOS=linux seems to be dropped.
I hope it makes no difference

WORKDIR /workspace/go/src/github.com/csi-addons/kubernetes-csi-addons

# Build
RUN CGO_ENABLED=0 GOOS=linux go build -mod=vendor -a -o /workspace/manager cmd/manager/main.go
RUN make build

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/manager .
COPY --from=builder /workspace/go/src/github.com/csi-addons/kubernetes-csi-addons/bin/csi-addons-manager .
USER 65532:65532

ENTRYPOINT ["/manager"]
ENTRYPOINT ["/csi-addons-manager"]
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ bundle-validate: container-cmd operator-sdk

.PHONY: build
build: generate fmt vet ## Build manager binary.
go build -ldflags '$(LDFLAGS)' -o bin/manager cmd/manager/main.go
go build -ldflags '$(LDFLAGS)' -o bin/sidecar sidecar/main.go
go build -o bin/csi-addons ./cmd/csi-addons
go build -ldflags '$(LDFLAGS)' -a -o bin/csi-addons-manager cmd/manager/main.go
go build -ldflags '$(LDFLAGS)' -a -o bin/csi-addons-sidecar sidecar/main.go
go build -ldflags '$(LDFLAGS)' -a -o bin/csi-addons ./cmd/csi-addons

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
Expand Down
14 changes: 6 additions & 8 deletions build/Containerfile.sidecar
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@ FROM quay.io/projectquay/golang:1.20 as builder
# Copy the contents of the repository
ADD . /workspace/go/src/github.com/csi-addons/kubernetes-csi-addons

ENV GOPATH=/workspace/go
ENV GOPATH=/workspace/go CGO_ENABLED=0
WORKDIR /workspace/go/src/github.com/csi-addons/kubernetes-csi-addons

# Build
RUN CGO_ENABLED=0 GOOS=linux go build -mod=vendor -a -o /workspace/csi-addons-sidecar ./sidecar

# Build the csi-addons tool for admin usage and testing
RUN CGO_ENABLED=0 GOOS=linux go build -mod=vendor -a -o /workspace/csi-addons ./cmd/csi-addons
# Build the sidecar and csi-addons tool for admin usage and testing
RUN make build

# Use distroless as minimal base image to package the sidecar binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:latest
WORKDIR /
COPY --from=builder /workspace /usr/bin/
COPY --from=builder /workspace/go/src/github.com/csi-addons/kubernetes-csi-addons/bin/csi-addons-sidecar /usr/sbin/
COPY --from=builder /workspace/go/src/github.com/csi-addons/kubernetes-csi-addons/bin/csi-addons /usr/bin/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be copied to /usr/sbin?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/usr/sbin is the path for executables that act like servers or are for admin users. csi-addons is a tool that can be used by any user to talk to the csi-driver. I though it would be more suitable in /usr/bin. The distinction between the paths is not very important to me, I am happy yo change either, both should be in the $PATH when an admin user logs in the pod.


ENTRYPOINT ["/usr/bin/csi-addons-sidecar"]
ENTRYPOINT ["/usr/sbin/csi-addons-sidecar"]
10 changes: 10 additions & 0 deletions cmd/csi-addons/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"fmt"
"os"

"github.com/csi-addons/kubernetes-csi-addons/internal/version"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"k8s.io/client-go/kubernetes"
Expand All @@ -47,12 +49,15 @@ type command struct {
var cmd = &command{}

func init() {
var showVersion bool

flag.StringVar(&cmd.endpoint, "endpoint", endpoint, "CSI-Addons endpoint")
flag.StringVar(&cmd.stagingPath, "stagingpath", stagingPath, "staging path")
flag.StringVar(&cmd.operation, "operation", "", "csi-addons operation")
flag.StringVar(&cmd.persistentVolume, "persistentvolume", "", "name of the PersistentVolume")
flag.StringVar(&cmd.drivername, "drivername", "", "name of the CSI driver")
flag.BoolVar(&cmd.legacy, "legacy", false, "use legacy format for old Kubernetes versions")
flag.BoolVar(&showVersion, "version", false, "print Version details")

// output to show when --help is passed
flag.Usage = func() {
Expand All @@ -66,6 +71,11 @@ func init() {
}

flag.Parse()

if showVersion {
version.PrintVersion()
os.Exit(0)
}
}

func main() {
Expand Down
2 changes: 1 addition & 1 deletion config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ spec:
runAsNonRoot: true
containers:
- command:
- /manager
- /csi-addons-manager
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same change should also be made to CSV? might be missed to updated CSV with git push

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I don't think the command is included there. I can not find it in config/manifests/bases/clusterserviceversion.yaml.in.

args:
- --leader-elect
image: controller:latest
Expand Down
2 changes: 1 addition & 1 deletion deploy/controller/install-all-in-one.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,7 @@ spec:
- --leader-elect
- --enable-admission-webhooks=true
command:
- /manager
- /csi-addons-manager
env:
- name: POD_NAMESPACE
valueFrom:
Expand Down
2 changes: 1 addition & 1 deletion deploy/controller/setup-controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ spec:
- --leader-elect
- --enable-admission-webhooks=false
command:
- /manager
- /csi-addons-manager
env:
- name: POD_NAMESPACE
valueFrom:
Expand Down