Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

split container specs #69

Merged
merged 7 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 6 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
21 changes: 17 additions & 4 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: golangci-lint
name: Lint

on:
pull_request:
Expand All @@ -7,11 +7,12 @@ on:

permissions:
contents: read
pull-requests: read
checks: write

jobs:
golangci:
name: lint
name: golangci
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -21,5 +22,17 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.59
args: --timeout=5m
version: v1.60
args: --timeout=8m --verbose

go-test:
name: go test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
check-latest: true
- name: Display Go version
run: go test ./...
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,19 @@ endif

.PHONY: install
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply --namespace ${NAMESPACE} -f -
@echo "Building CRD..."
$(KUSTOMIZE) build config/crd > /tmp/temp-crd.yaml
@echo "Applying CRD..."
@if $(KUBECTL) get -f /tmp/temp-crd.yaml >/dev/null 2>&1; then \
echo "CRD exists, replacing..."; \
$(KUBECTL) replace --namespace ${NAMESPACE} -f /tmp/temp-crd.yaml; \
else \
echo "CRD does not exist, creating..."; \
$(KUBECTL) create --namespace ${NAMESPACE} -f /tmp/temp-crd.yaml; \
fi
@echo "Cleaning up..."
rm -f /tmp/temp-crd.yaml
@echo "Done."

.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
93 changes: 90 additions & 3 deletions api/v1/store.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package v1

import (
"maps"

autoscalerv2 "k8s.io/api/autoscaling/v2"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -28,8 +30,15 @@ type StoreList struct {
}

type StoreSpec struct {
Database DatabaseSpec `json:"database"`
Container ContainerSpec `json:"container"`
Database DatabaseSpec `json:"database"`

Container ContainerSpec `json:"container"`
AdminDeploymentContainer ContainerMergeSpec `json:"adminDeploymentContainer,omitempty"`
WorkerDeploymentContainer ContainerMergeSpec `json:"workerDeploymentContainer,omitempty"`
StorefrontDeploymentContainer ContainerMergeSpec `json:"storefrontDeploymentContainer,omitempty"`
SetupJobContainer ContainerMergeSpec `json:"setupJobContainer,omitempty"`
MigrationJobContainer ContainerMergeSpec `json:"migrationJobContainer,omitempty"`

Network NetworkSpec `json:"network,omitempty"`
S3Storage S3Storage `json:"s3Storage,omitempty"`
CDNURL string `json:"cdnURL"`
Expand Down Expand Up @@ -138,9 +147,9 @@ type ContainerSpec struct {
// ReadinessProbe corev1.Probe `json:"readinessProbe,omitempty"`
// LivenessProbe corev1.Probe `json:"livenessProbe,omitempty"`

NodeSelector map[string]string `json:"nodeSelector,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
Affinity corev1.Affinity `json:"affinity,omitempty"`
Expand All @@ -159,6 +168,30 @@ type ContainerSpec struct {
ExtraEnvs []corev1.EnvVar `json:"extraEnvs,omitempty"`
}

type ContainerMergeSpec struct {
// +kubebuilder:validation:MinLength=1
Image string `json:"image,omitempty"`
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
Volumes []corev1.Volume `json:"volumes,omitempty"`
VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty"`
RestartPolicy corev1.RestartPolicy `json:"restartPolicy,omitempty"`
SecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
ExtraContainers []corev1.Container `json:"extraContainers,omitempty"`
Replicas int32 `json:"replicas,omitempty"`
ProgressDeadlineSeconds int32 `json:"progressDeadlineSeconds,omitempty"`

Annotations map[string]string `json:"annotations,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
Affinity corev1.Affinity `json:"affinity,omitempty"`

Resources corev1.ResourceRequirements `json:"resources,omitempty"`
ExtraEnvs []corev1.EnvVar `json:"extraEnvs,omitempty"`
}

type SessionCacheSpec struct {
RedisSpec `json:",inline"`

Expand Down Expand Up @@ -278,3 +311,57 @@ type SecretRef struct {
func (s *Store) GetSecretName() string {
return s.Spec.SecretName
}

func (c *ContainerSpec) Merge(from ContainerMergeSpec) {
if from.Image != "" {
c.Image = from.Image
}
if from.ImagePullPolicy != "" {
c.ImagePullPolicy = from.ImagePullPolicy
}
if from.Replicas != 0 {
c.Replicas = from.Replicas
}
if from.ProgressDeadlineSeconds != 0 {
c.ProgressDeadlineSeconds = from.ProgressDeadlineSeconds
}
if from.RestartPolicy != "" {
c.RestartPolicy = from.RestartPolicy
}
if from.ExtraEnvs != nil {
c.ExtraEnvs = from.ExtraEnvs
}
if from.VolumeMounts != nil {
c.VolumeMounts = from.VolumeMounts
}
if from.ImagePullSecrets != nil {
c.ImagePullSecrets = from.ImagePullSecrets
}
if from.Volumes != nil {
c.Volumes = from.Volumes
}
if from.Resources.Requests != nil {
c.Resources.Requests = from.Resources.Requests
}
if from.Resources.Limits != nil {
c.Resources.Limits = from.Resources.Limits
}
if from.ExtraContainers != nil {
c.ExtraContainers = from.ExtraContainers
}
if from.NodeSelector != nil {
c.NodeSelector = from.NodeSelector
}
if from.TopologySpreadConstraints != nil {
c.TopologySpreadConstraints = from.TopologySpreadConstraints
}
if from.Tolerations != nil {
c.Tolerations = from.Tolerations
}
if from.Annotations != nil {
maps.Copy(c.Annotations, from.Annotations)
}
if from.Labels != nil {
maps.Copy(c.Labels, from.Labels)
}
}
46 changes: 46 additions & 0 deletions api/v1/store_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package v1_test

import (
"testing"

v1 "github.com/shopware/shopware-operator/api/v1"
"github.com/stretchr/testify/assert"
)

func TestStoreContainer(t *testing.T) {
con := &v1.Store{
Spec: v1.StoreSpec{
Container: v1.ContainerSpec{
Image: "FirstContainer",
Replicas: 2,
Labels: map[string]string{
"test": "FirstContainer",
"test2": "FirstContainer",
},
Annotations: map[string]string{
"test": "FirstContainer",
"test2": "FirstContainer",
},
},
},
}

con2 := v1.ContainerMergeSpec{
Image: "SecondContainer",
Labels: map[string]string{
"test": "SecondContainer",
"test2": "SecondContainer",
},
Annotations: map[string]string{
"test": "SecondContainer",
},
}

con.Spec.Container.Merge(con2)
assert.Equal(t, "SecondContainer", con.Spec.Container.Image)
assert.Equal(t, int32(2), con.Spec.Container.Replicas)
assert.Equal(t, "SecondContainer", con.Spec.Container.Labels["test"])
assert.Equal(t, "SecondContainer", con.Spec.Container.Labels["test2"])
assert.Equal(t, "SecondContainer", con.Spec.Container.Annotations["test"])
assert.Equal(t, "FirstContainer", con.Spec.Container.Annotations["test2"])
}
Loading
Loading