Skip to content

Commit

Permalink
feat: plugin management w/ helm
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerGillson committed Aug 28, 2023
1 parent 21de985 commit 537faac
Show file tree
Hide file tree
Showing 42 changed files with 1,931 additions and 87 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Dockerfile.cross
!vendor/**/zz_generated.*

# editor and IDE paraphernalia
.devspace
.idea
.vscode
*.swp
Expand Down
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
repos:
- repo: https://github.com/zricethezav/gitleaks
rev: v8.18.0
hooks:
- id: gitleaks
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v2.4.0
hooks:
- id: conventional-pre-commit
stages: [commit-msg]
11 changes: 9 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Build the manager binary
FROM golang:1.20 AS builder
FROM golang:alpine3.17 AS builder
ARG TARGETOS
ARG TARGETARCH

RUN apk add --no-cache curl

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
Expand All @@ -14,7 +16,11 @@ RUN go mod download
# Copy the go source
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY internal/controller/ internal/controller/
COPY internal/ internal/

# Get Helm
RUN curl -s https://get.helm.sh/helm-v3.10.1-linux-amd64.tar.gz | tar -xzf - && \
mv linux-amd64/helm . && rm -rf linux-amd64

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
Expand All @@ -28,6 +34,7 @@ RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o ma
FROM gcr.io/distroless/static:nonroot AS production
WORKDIR /
COPY --from=builder /workspace/manager .
COPY --from=builder /workspace/helm .
USER 65532:65532

ENTRYPOINT ["/manager"]
32 changes: 32 additions & 0 deletions Dockerfile.devspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Build the manager binary
FROM golang:alpine3.17 AS builder
ARG TARGETOS
ARG TARGETARCH

RUN apk add --no-cache bash curl git

# Install Delve for debugging
RUN go install github.com/go-delve/delve/cmd/dlv@latest

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

# Copy the go source
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY internal/ internal/

RUN curl -s https://get.helm.sh/helm-v3.10.1-linux-amd64.tar.gz | tar -xzf - && \
mv linux-amd64/helm . && rm -rf linux-amd64

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ $(HELMIFY): $(LOCALBIN)
helm-build: helm helmify manifests kustomize
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) && cd ../../
$(KUSTOMIZE) build config/default | $(HELMIFY) -crd-dir
cat hack/plugin-values.yaml >> chart/valid8or/values.yaml
cat hack/extra-values.yaml >> chart/valid8or/values.yaml

.PHONY: helm-package
helm-package: generate manifests
Expand Down
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,13 @@ resources:
kind: ValidationResult
path: github.com/spectrocloud-labs/valid8or/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: spectrocloud.labs
group: validation
kind: Valid8orConfig
path: github.com/spectrocloud-labs/valid8or/api/v1alpha1
version: v1alpha1
version: "3"
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ make undeploy
## Contributing
All contributions are welcome! Feel free to reach out on the [Spectro Cloud community Slack](https://spectrocloudcommunity.slack.com/join/shared_invite/zt-g8gfzrhf-cKavsGD_myOh30K24pImLA#/shared-invite/email).

Make sure `pre-commit` is [installed](https://pre-commit.com#install).

Install the `pre-commit` scripts:

```console
pre-commit install --hook-type commit-msg
pre-commit install --hook-type pre-commit
```

### How it works
This project aims to follow the Kubernetes [Operator pattern](https://kubernetes.io/docs/concepts/extend-kubernetes/operator/).

Expand Down
104 changes: 104 additions & 0 deletions api/v1alpha1/valid8orconfig_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
Copyright 2023.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// Valid8orConfigSpec defines the desired state of Valid8orConfig
type Valid8orConfigSpec struct {
Plugins []HelmRelease `json:"plugins,omitempty"`
}

type HelmRelease struct {
Chart HelmChart `json:"chart"`
Values string `json:"values"`
}

type HelmChart struct {
Name string `json:"name"`
Repository string `json:"repository"`
Version string `json:"version"`
}

// Valid8orConfigStatus defines the observed state of Valid8orConfig
type Valid8orConfigStatus struct {
// +optional
// +patchMergeKey=type
// +patchStrategy=merge
Conditions []Valid8orPluginCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
}

type Valid8orPluginCondition struct {
// Type of condition in CamelCase or in foo.example.com/CamelCase.
// Many .condition.type values are consistent across resources like Available, but because arbitrary conditions
// can be useful (see .node.status.conditions), the ability to deconflict is important.
// +required
Type ConditionType `json:"type"`

// Name of the Valid8or plugin.
// +required
PluginName string `json:"pluginName"`

// Status of the condition, one of True, False, Unknown.
// +required
Status corev1.ConditionStatus `json:"status"`

// A human readable message indicating details about the transition.
// This field may be empty.
// +optional
Message string `json:"message,omitempty"`

// Last time the condition transitioned from one status to another.
// This should be when the underlying condition changed. If that is not known, then using the time when
// the API field changed is acceptable.
// +required
LastTransitionTime metav1.Time `json:"lastUpdatedTime"`
}

// ConditionType is a valid value for Condition.Type.
type ConditionType string

// HelmChartDeployedCondition defines the helm chart deployed condition type that defines if the helm chart was deployed correctly.
const HelmChartDeployedCondition ConditionType = "HelmChartDeployed"

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// Valid8orConfig is the Schema for the valid8orconfigs API
type Valid8orConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec Valid8orConfigSpec `json:"spec,omitempty"`
Status Valid8orConfigStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// Valid8orConfigList contains a list of Valid8orConfig
type Valid8orConfigList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Valid8orConfig `json:"items"`
}

func init() {
SchemeBuilder.Register(&Valid8orConfig{}, &Valid8orConfigList{})
}
148 changes: 148 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 537faac

Please sign in to comment.