Skip to content

Commit 6205ae0

Browse files
committed
Add Makefile target and the code to create new API
Signed-off-by: manuelbuil <[email protected]>
1 parent 00cae7b commit 6205ae0

File tree

6 files changed

+824
-13
lines changed

6 files changed

+824
-13
lines changed

Dockerfile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ RUN apk add --no-cache bash git gcc musl-dev
55
WORKDIR /src
66
COPY . .
77

8+
RUN GOPROXY=direct go install sigs.k8s.io/controller-tools/cmd/[email protected]
9+
RUN GOPROXY=direct go install github.com/elastic/[email protected]
10+
11+
RUN go generate ./...
12+
813
RUN --mount=type=cache,id=gomod,target=/go/pkg/mod \
914
--mount=type=cache,id=gobuild,target=/root/.cache/go-build \
1015
./scripts/build
@@ -16,9 +21,7 @@ COPY --from=builder /src/bin/helm-controller /bin/
1621
FROM golang:1.24-alpine3.22 AS dev
1722
ARG ARCH
1823
ENV ARCH=$ARCH
19-
RUN apk add --no-cache bash git gcc musl-dev curl
20-
RUN GOPROXY=direct go install golang.org/x/tools/cmd/goimports@gopls/v0.18.1
21-
RUN GOPROXY=direct go install sigs.k8s.io/controller-tools/cmd/[email protected]
24+
RUN apk add --no-cache bash git curl
2225
RUN if [ "${ARCH}" != "arm" ]; then \
2326
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.64.7; \
2427
fi
@@ -37,6 +40,9 @@ RUN ./scripts/package
3740
FROM scratch AS artifacts
3841
COPY --from=package /src/dist/artifacts /dist/artifacts
3942

43+
FROM scratch AS crds
44+
COPY --from=builder /src/pkg/crds/yaml/generated/ /
45+
4046
FROM alpine:3.22 AS production
4147
COPY bin/helm-controller /usr/bin/
4248
CMD ["helm-controller"]

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ IMAGE_NAME ?= helm-controller
22
ARCH ?= amd64
33

44
.DEFAULT_GOAL := ci
5-
.PHONY: build test validate package clean
5+
.PHONY: build test validate package clean generate-crd
66

7-
build:
7+
build: generate-crd
88
DOCKER_BUILDKIT=1 docker build \
99
--target binary \
1010
--output type=local,dest=. .
1111

12+
generate-crd:
13+
DOCKER_BUILDKIT=1 docker build \
14+
--target crds \
15+
--output type=local,dest=./pkg/crds/yaml/generated .
16+
1217
validate:
1318
docker build --target dev --build-arg ARCH=$(ARCH) -t $(IMAGE_NAME)-dev .
1419
docker run --rm $(IMAGE_NAME)-dev ./scripts/validate

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ helm-controller
44
A simple way to manage helm charts with Custom Resource Definitions in k8s.
55

66
## Manifests and Deploying
7-
The `./manifests` folder contains useful YAML manifests to use for deploying and developing the Helm Controller. This simple YAML deployment creates a HelmChart CRD + a Deployment using the `rancher/helm-controller` container. The YAML might need some modifications for your environment so read below for Namespaced vs Cluster deployments and how to use them properly.
7+
The `./manifests` folder contains useful YAML manifests to use for deploying and developing the Helm Controller. However, we recommend using the `deploy-cluster-scoped.yaml` or `deploy-namespaced.yaml` manifests included in the releases. The YAML might need some modifications for your environment so read below for Namespaced vs Cluster deployments and how to use them properly.
88

99
#### Namespaced Deploys
1010
Use the `deploy-namespaced.yaml` to create a namespace and add the Helm Controller and CRD to that namespace locking down the Helm Controller to only see changes to CRDs within that namespace. This is defaulted to `helm-controller` so update the YAML to your needs before running `kubectl create`
@@ -22,22 +22,26 @@ To remove the Helm Controller run `kubectl delete` and pass the deployment YAML
2222
## Developing and Building
2323
The Helm Controller is easy to get running locally, follow the instructions for your needs and requires a running k8s server + CRDs etc. When you have a working k8s cluster, you can use `./manifests/crd.yaml` to create the CRD and `./manifests/example-helmchart.yaml` which runs the `stable/traefik` helm chart.
2424

25-
#### Locally
25+
### Build
26+
Run `make build` to build the binary and, opitonally, generate new CRDs if the API changed. We recommend execute `make` to additionally run validation and testing.
27+
28+
#### Running it locally
2629
Building and running natively will start a daemon which will watch a local k8s API. See Manifests section above about how to create the CRD and Objects using the provided manifests.
2730

2831
```
2932
go build -o ./bin/helm-controller
3033
./bin/helm-controller --kubeconfig $HOME/.kube/config
3134
```
3235

33-
#### docker/k8s
34-
An easy way to get started with docker/k8s is to install docker for windows/mac and use the included k8s cluster. Once functioning you can easily build locally and get a docker container to pull the Helm Controller container and run it in k8s. Use `make` to launch a Linux container and build to create a container. Use the `./manifests/deploy-*.yaml` definitions to get it into your cluster and update `containers.image` to point to your locally image e.g. `image: rancher/helm-controller:dev`
36+
#### Running it on k8s
37+
Use the `deploy-cluster-scoped.yaml` or `deploy-namespaced.yaml` manifests in the assets of each release to run the helm-controller in Kubernetes.
3538

3639
#### Options and Usage
3740
Use `./bin/helm-controller help` to get full usage details. The outside of a k8s Pod the most important options are `--kubeconfig` or `--masterurl` or it will not run. All options have corresponding ENV variables you could use.
3841

39-
## Testing
40-
`go test ./...`
42+
## Testing/Validating
43+
`make test`
44+
`make validate`
4145

4246
## License
4347
Copyright (c) 2019 [Rancher Labs, Inc.](http://rancher.com)

0 commit comments

Comments
 (0)