Skip to content

Commit a307886

Browse files
authored
Updates to move from static SDK files to "go get" SDK module. (#24)
* Setting up for prebuilt go get SM SDK with binaries * Updates from testing with temporary "go get" module * Replacing the temporary module with the final SDK module
1 parent 5b1c1c1 commit a307886

24 files changed

+84
-1632
lines changed

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
# Ignore build and test binaries.
33
bin/
44
!bin/libbitwarden_c.so
5-
bw-sdk/internal/cinterface/lib/*

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ Dockerfile.cross
4949
*~
5050

5151
sm-operator.tar
52-
bw-sdk/internal/cinterface/lib/*
5352
**/__debug_bin*
5453
**/temp.zip
5554
**/.env

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"mode": "debug",
1212
"program": "${workspaceFolder}/cmd/main.go",
1313
"cwd": "${workspaceFolder}",
14-
"buildFlags": ["-ldflags='-linkmode external -extldflags \"-static\"'"],
14+
"buildFlags": ["-ldflags='-linkmode external -extldflags \"-static -Wl,-unresolved-symbols=ignore-all\"'"],
1515
"envFile": "${workspaceFolder}/.env",
1616
"env": {
1717
"CC": "musl-gcc"
@@ -24,7 +24,7 @@
2424
"mode": "test",
2525
"program": "${relativeFileDirname}",
2626
"cwd": "${relativeFileDirname}",
27-
"buildFlags": ["-ldflags='-linkmode external -extldflags \"-static\"'"],
27+
"buildFlags": ["-ldflags='-linkmode external -extldflags \"-static -Wl,-unresolved-symbols=ignore-all\"'"],
2828
"env": {
2929
"CC": "musl-gcc"
3030
}

Dockerfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ WORKDIR /workspace
66

77
COPY go.mod go.mod
88
COPY go.sum go.sum
9-
COPY bw-sdk/ bw-sdk/
109

1110
RUN go mod download
1211

@@ -18,11 +17,9 @@ COPY Makefile Makefile
1817

1918
RUN apt update && apt install unzip musl-tools -y
2019

21-
RUN GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} make binaries
22-
2320
RUN mkdir state
2421

25-
RUN CC=musl-gcc CGO_ENABLED=1 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -ldflags '-linkmode external -extldflags "-static"' -o manager cmd/main.go
22+
RUN CC=musl-gcc CGO_ENABLED=1 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -ldflags '-linkmode external -extldflags "-static -Wl,-unresolved-symbols=ignore-all"' -o manager cmd/main.go
2623

2724
FROM gcr.io/distroless/base-debian12:nonroot
2825
WORKDIR /

Makefile

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -96,26 +96,8 @@ all: build
9696
help: ## Display this help.
9797
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
9898

99-
.PHONY: binaries
100-
OS=$(shell go env GOOS)
101-
ARCH=$(shell go env GOARCH)
102-
OS_STRING=unknown-linux-gnu
103-
ARCH_STRING=x86_64
104-
ifeq ($(OS),windows)
105-
OS_STRING=pc-windows-msvc
106-
endif
107-
ifeq ($(OS),darwin)
108-
OS_STRING=apple-darwin
109-
endif
110-
ifeq ($(ARCH),arm64)
111-
ARCH_STRING=aarch64
112-
endif
113-
binaries: ## Setting up the SDK binaries. The URL in use is temporary.
114-
mkdir -p bw-sdk/internal/cinterface/lib
115-
curl -sSLo temp.zip --url https://github.com/coltonhurst/go-module-test/releases/download/test-release/libbitwarden_c_files-$(ARCH_STRING)-$(OS_STRING)-$(SDKBINARYVERSION).zip && unzip -o -q temp.zip -d bw-sdk/internal/cinterface/lib && rm temp.zip
116-
11799
.PHONY: setup
118-
setup: binaries ## Setting up the SDK binaries and setting up the sample .env file for use. The URL in use is temporary.
100+
setup: ## Setting up the sample .env file for use.
119101
ifeq ("$(wildcard .env)","")
120102
cp .env.example .env
121103
endif
@@ -140,17 +122,17 @@ vet: ## Run go vet against code.
140122

141123
.PHONY: test
142124
test: manifests generate fmt vet envtest ## Run tests.
143-
CC=musl-gcc KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -ldflags '-linkmode external -extldflags "-static"' ./... -coverprofile cover.out
125+
CC=musl-gcc KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -ldflags '-linkmode external -extldflags "-static -Wl,-unresolved-symbols=ignore-all"' ./... -coverprofile cover.out
144126

145127
##@ Build
146128

147129
.PHONY: build
148130
build: manifests generate fmt vet ## Build manager binary.
149-
CC=musl-gcc go build -ldflags '-linkmode external -extldflags "-static"' -o bin/manager cmd/main.go
131+
CC=musl-gcc go build -ldflags '-linkmode external -extldflags "-static -Wl,-unresolved-symbols=ignore-all"' -o bin/manager cmd/main.go
150132

151133
.PHONY: run
152134
run: manifests generate fmt vet ## Run a controller from your host.
153-
CC=musl-gcc go run -ldflags '-linkmode external -extldflags "-static"' ./cmd/main.go
135+
CC=musl-gcc go run -ldflags '-linkmode external -extldflags "-static -Wl,-unresolved-symbols=ignore-all"' ./cmd/main.go
154136

155137
# If you wish built the manager image targeting other platforms you can use the --platform flag.
156138
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
@@ -246,6 +228,7 @@ $(CONTROLLER_GEN): $(LOCALBIN)
246228
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
247229
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
248230

231+
## This has been locked down to an older version of envtest that supports 1.21. When Operator-SDK supports 1.22, we can move back to using latest
249232
.PHONY: envtest
250233
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
251234
$(ENVTEST): $(LOCALBIN)

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ You will need a Kubernetes cluster to run against. We recommend [KIND](https://s
1414

1515
**Note:** Your controller will automatically use the current context in your kubeconfig file (i.e. whatever cluster `kubectl cluster-info` shows).
1616

17-
This project uses the Secrets Manager golang SDK. This SDK requires some binaries exist inside the project. Run `make setup` to download the appropriate binaries into the project. If you are using the Dev Container, this step has already been completed for you.
17+
Run `make setup` to generate an example `.env` file. If you are using the Dev Container, this step has already been completed for you.
1818

1919
### Pre-requisites
2020

@@ -35,7 +35,6 @@ For manual Linux setups:
3535
* [Visual Studio Code Go Extension](https://marketplace.visualstudio.com/items?itemName=golang.go)
3636
* [kubectl](https://kubernetes.io/docs/tasks/tools/)
3737
* [Docker](https://www.docker.com/) or [Podman](https://podman.io/) or another container engine
38-
* [Download the appropriate libbitwarden_c binary](https://github.com/bitwarden/sdk) for your OS and architecture to [bw-sdk/internal/cinterface/lib](bw-sdk/internal/cinterface/lib). This can be done using `make setup`
3938
* A [Bitwarden Organization with Secrets Manager](https://bitwarden.com/help/sign-up-for-secrets-manager/). You will need the organization ID GUID for your organization.
4039
* An [access token](https://bitwarden.com/help/access-tokens/) for a Secrets Manager machine account tied to the projects you want to pull.
4140
* A [Kind Cluster](https://kind.sigs.k8s.io/docs/user/quick-start/) or other local Kubernetes environment with Kubectl pointed to it as the current context for local development.

bw-sdk/README.md

Lines changed: 0 additions & 115 deletions
This file was deleted.

bw-sdk/bitwarden_client.go

Lines changed: 0 additions & 78 deletions
This file was deleted.

bw-sdk/command_runner.go

Lines changed: 0 additions & 37 deletions
This file was deleted.

bw-sdk/go.mod

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)