Skip to content
Open
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
13 changes: 10 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ RUN apk add --no-cache bash git gcc musl-dev
WORKDIR /src
COPY . .

RUN GOPROXY=direct go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.19.0
RUN GOPROXY=direct go install github.com/elastic/crd-ref-docs@v0.2.0

RUN go generate ./...

RUN --mount=type=cache,id=gomod,target=/go/pkg/mod \
--mount=type=cache,id=gobuild,target=/root/.cache/go-build \
./scripts/build
Expand All @@ -16,9 +21,7 @@ COPY --from=builder /src/bin/helm-controller /bin/
FROM golang:1.24-alpine3.22 AS dev
ARG ARCH
ENV ARCH=$ARCH
RUN apk add --no-cache bash git gcc musl-dev curl
RUN GOPROXY=direct go install golang.org/x/tools/cmd/goimports@gopls/v0.18.1
RUN GOPROXY=direct go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.17.3
RUN apk add --no-cache bash git curl
RUN if [ "${ARCH}" != "arm" ]; then \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.64.7; \
fi
Expand All @@ -37,6 +40,10 @@ RUN ./scripts/package
FROM scratch AS artifacts
COPY --from=package /src/dist/artifacts /dist/artifacts

FROM scratch AS crds
COPY --from=builder /src/pkg/crds/yaml/generated/ /
COPY --from=builder /src/doc/helmchart.md /tmp_doc/

FROM alpine:3.22 AS production
COPY bin/helm-controller /usr/bin/
CMD ["helm-controller"]
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ IMAGE_NAME ?= helm-controller
ARCH ?= amd64

.DEFAULT_GOAL := ci
.PHONY: build test validate package clean
.PHONY: build test validate package clean generate-crd

build:
build: generate-crd
DOCKER_BUILDKIT=1 docker build \
--target binary \
--output type=local,dest=. .

generate-crd:
DOCKER_BUILDKIT=1 docker build \
--target crds \
--output type=local,dest=./pkg/crds/yaml/generated .
mv ./pkg/crds/yaml/generated/tmp_doc/helmchart.md ./doc/
rm -r ./pkg/crds/yaml/generated/tmp_doc/

validate:
docker build --target dev --build-arg ARCH=$(ARCH) -t $(IMAGE_NAME)-dev .
docker run --rm $(IMAGE_NAME)-dev ./scripts/validate
Expand Down
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ helm-controller
A simple way to manage helm charts with Custom Resource Definitions in k8s.

## Manifests and Deploying
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.
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.

#### Namespaced Deploys
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`
Expand All @@ -20,24 +20,28 @@ Autogenerated API docs for `helm.cattle.io/v1 HelmChart` and `HelmChartConfig` a
To remove the Helm Controller run `kubectl delete` and pass the deployment YAML used using to create the Deployment `-f` parameter.

## Developing and Building
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.
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 apply the manifests inside `./pkg/crds/yaml/generated/` to create the CRD and `./manifests/example-helmchart.yaml` which runs the `stable/traefik` helm chart.

#### Locally
### Build
Run `make build` to build the binary and, optionally, generate new CRDs if the API changed. We recommend just running `make` as the default target will also perform validation and testing.

#### Running it locally
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.

```
go build -o ./bin/helm-controller
./bin/helm-controller --kubeconfig $HOME/.kube/config
```

#### docker/k8s
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`
#### Running it on k8s
Use the `deploy-cluster-scoped.yaml` or `deploy-namespaced.yaml` manifests in the assets of each release to run the helm-controller in Kubernetes.

#### Options and Usage
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.

## Testing
`go test ./...`
## Testing/Validating
`make test`
`make validate`

## License
Copyright (c) 2019 [Rancher Labs, Inc.](http://rancher.com)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.17.3
controller-gen.kubebuilder.io/version: v0.19.0
name: helmchartconfigs.helm.cattle.io
spec:
group: helm.cattle.io
Expand Down
2 changes: 1 addition & 1 deletion pkg/crds/yaml/generated/helm.cattle.io_helmcharts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.17.3
controller-gen.kubebuilder.io/version: v0.19.0
name: helmcharts.helm.cattle.io
spec:
group: helm.cattle.io
Expand Down
2 changes: 1 addition & 1 deletion scripts/validate
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fi
echo Running validation

echo Running: golangci-lint
golangci-lint run
golangci-lint run --timeout 3m

echo Running: go fmt
test -z "$(go fmt ${PACKAGES} | tee /dev/stderr)"