Skip to content

Commit

Permalink
Unify config for sidecar and init containers (#193)
Browse files Browse the repository at this point in the history
* Unify config for sidecar and init containers

* make install do server side apply

* Update golangci-lint and use non-deprecated linter

* Update install documentation

* Refine chia version doc

* Change extracontainer API a bit to allow more granular configuration of shareEnv and shareVolume config opts

* Update documentation

* Add extra containers test
  • Loading branch information
Starttoaster authored Oct 22, 2024
1 parent e9d5456 commit a37160b
Show file tree
Hide file tree
Showing 32 changed files with 28,503 additions and 14,210 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ linters:
- goimports
- dupl
- errcheck
- exportloopref
- copyloopvar
- ginkgolinter
- goconst
- gocyclo
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ endif

.PHONY: install
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply --server-side -f -

.PHONY: uninstall
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
Expand Down Expand Up @@ -167,7 +167,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
KUSTOMIZE_VERSION ?= v5.4.1
CONTROLLER_TOOLS_VERSION ?= v0.16.2
ENVTEST_VERSION ?= latest
GOLANGCI_LINT_VERSION ?= v1.57.2
GOLANGCI_LINT_VERSION ?= v1.61.0

.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
Expand Down
31 changes: 12 additions & 19 deletions api/v1/chiacommon_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ type CommonSpec struct {

// InitContainers allows defining a list of containers that will run as init containers in the kubernetes Pods this resource creates
// +optional
InitContainers []InitContainer `json:"initContainers,omitempty"`
InitContainers []ExtraContainer `json:"initContainers,omitempty"`

// Sidecars allows defining a list of containers and volumes that will share the kubernetes Pod alongside Chia containers
// Sidecars allows defining a list of containers and volumes that will share the kubernetes Pod alongside a Chia container
// +optional
Sidecars Sidecars `json:"sidecars,omitempty"`
Sidecars []ExtraContainer `json:"sidecars,omitempty"`

//StorageConfig defines the Chia container's CHIA_ROOT storage config
// +optional
Expand Down Expand Up @@ -48,30 +48,23 @@ type CommonSpec struct {
Affinity *corev1.Affinity `json:"affinity,omitempty"`
}

// InitContainer allows defining a container that will run as an init container for a kubernetes resource
type InitContainer struct {
// Container allows defining a container that will share the kubernetes Pod alongside Chia containers.
// ExtraContainer allows defining a container spec that will share the kubernetes Pod alongside a Chia container, or run as an init container, along with some additional Pod spec configuration
type ExtraContainer struct {
// Container allows defining a container spec that will share the kubernetes Pod alongside a Chia container
// +optional
Container corev1.Container `json:"container,omitempty"`

// ShareVolumeMounts if set to true, shares any volume mounts from the main chia container to this init container
// Volumes allows defining a list of volumes that can be mounted by this container
// +optional
ShareVolumeMounts bool `json:"shareVolumeMounts,omitempty"`

// ShareEnv if set to true, shares the environment variables from the main chia container. Useful if the init container's image is a derivative of the chia-docker image.
// +optional
ShareEnv bool `json:"shareEnv,omitempty"`
}
Volumes []corev1.Volume `json:"volumes,omitempty"`

// Sidecars allows defining a list of containers that will share the kubernetes Pod alongside Chia containers
type Sidecars struct {
// Containers allows defining a list of containers that will share the kubernetes Pod alongside Chia containers
// ShareVolumeMounts if set to true, shares any volume mounts from the main chia container to this container
// +optional
Containers []corev1.Container `json:"containers,omitempty"`
ShareVolumeMounts bool `json:"shareVolumeMounts,omitempty"`

// Volumes allows defining a list of volumes that can be mounted by sidecar containers
// ShareEnv if set to true, shares the environment variables from the main chia container to this container
// +optional
Volumes []corev1.Volume `json:"volumes,omitempty"`
ShareEnv bool `json:"shareEnv,omitempty"`
}

// CommonSpecChia represents the common configuration options for a chia spec
Expand Down
64 changes: 24 additions & 40 deletions api/v1/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 a37160b

Please sign in to comment.