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

Add custom sidecar containers pod extension #372

Merged
merged 1 commit into from
Jan 17, 2024
Merged
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
12 changes: 10 additions & 2 deletions apis/mattermost/v1beta1/mattermost_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,19 @@ type UpdateJob struct {

// PodExtensions specify customized extensions for a pod.
type PodExtensions struct {
// Additional InitContainers injected to pods.
// Additional InitContainers injected into pods.
// The setting does not override InitContainers defined by the Operator.
InitContainers []v1.Container `json:"initContainers,omitempty"`

// Additional Container Ports injected to pod's main container.
// Additional sidecar containers injected into pods.
// The setting does not override any sidecar containers defined by the Operator.
// Note that sidecars are injected as standard pod containers alongside the
// Mattermost application server. In the future, this may be migrated to
// use the currently-feature-gated init container method introduced in k8s v1.28:
// https://kubernetes.io/blog/2023/08/25/native-sidecar-containers/
SidecarContainers []v1.Container `json:"sidecarContainers,omitempty"`

// Additional Container Ports injected into pod's main container.
// The setting does not override ContainerPorts defined by the Operator.
ContainerPorts []v1.ContainerPort `json:"containerPorts,omitempty"`
}
Expand Down
7 changes: 7 additions & 0 deletions apis/mattermost/v1beta1/zz_generated.deepcopy.go

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

1,279 changes: 1,276 additions & 3 deletions config/crd/bases/installation.mattermost.com_mattermosts.yaml

Large diffs are not rendered by default.

2,448 changes: 1,974 additions & 474 deletions docs/mattermost-operator/mattermost-operator.yaml

Large diffs are not rendered by default.

55 changes: 31 additions & 24 deletions pkg/mattermost/mattermost_v1beta.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,28 @@ func GenerateDeploymentV1Beta(mattermost *mmv1beta.Mattermost, db DatabaseConfig
revisionHistoryLimit = mattermost.Spec.DeploymentTemplate.RevisionHistoryLimit
}

containers := []corev1.Container{
{
Name: mattermostv1alpha1.MattermostAppContainerName,
Image: containerImage,
ImagePullPolicy: mattermost.Spec.ImagePullPolicy,
TerminationMessagePolicy: corev1.TerminationMessageFallbackToLogsOnError,
Command: []string{"mattermost"},
Env: envVars,
Ports: containerPorts,
ReadinessProbe: readiness,
LivenessProbe: liveness,
VolumeMounts: volumeMounts,
Resources: mattermost.Spec.Scheduling.Resources,
SecurityContext: containerSecurityContext,
},
}

// Final container extensions
if mattermost.Spec.PodExtensions.SidecarContainers != nil {
containers = append(containers, mattermost.Spec.PodExtensions.SidecarContainers...)
}

return &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: deploymentName,
Expand Down Expand Up @@ -394,30 +416,15 @@ func GenerateDeploymentV1Beta(mattermost *mmv1beta.Mattermost, db DatabaseConfig
Spec: corev1.PodSpec{
ServiceAccountName: serviceAccountName,
InitContainers: initContainers,
Containers: []corev1.Container{
{
Name: mattermostv1alpha1.MattermostAppContainerName,
Image: containerImage,
ImagePullPolicy: mattermost.Spec.ImagePullPolicy,
TerminationMessagePolicy: corev1.TerminationMessageFallbackToLogsOnError,
Command: []string{"mattermost"},
Env: envVars,
Ports: containerPorts,
ReadinessProbe: readiness,
LivenessProbe: liveness,
VolumeMounts: volumeMounts,
Resources: mattermost.Spec.Scheduling.Resources,
SecurityContext: containerSecurityContext,
},
},
ImagePullSecrets: mattermost.Spec.ImagePullSecrets,
Volumes: volumes,
DNSConfig: mattermost.Spec.DNSConfig,
DNSPolicy: mattermost.Spec.DNSPolicy,
Affinity: mattermost.Spec.Scheduling.Affinity,
NodeSelector: mattermost.Spec.Scheduling.NodeSelector,
Tolerations: mattermost.Spec.Scheduling.Tolerations,
SecurityContext: podSecurityContext,
Containers: containers,
ImagePullSecrets: mattermost.Spec.ImagePullSecrets,
Volumes: volumes,
DNSConfig: mattermost.Spec.DNSConfig,
DNSPolicy: mattermost.Spec.DNSPolicy,
Affinity: mattermost.Spec.Scheduling.Affinity,
NodeSelector: mattermost.Spec.Scheduling.NodeSelector,
Tolerations: mattermost.Spec.Scheduling.Tolerations,
SecurityContext: podSecurityContext,
},
},
},
Expand Down
45 changes: 44 additions & 1 deletion pkg/mattermost/mattermost_v1beta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,6 @@ func TestGenerateDeployment_V1Beta(t *testing.T) {
description string
mmSpec mmv1beta.MattermostSpec
dbConfig DatabaseConfig
fileStoreConfig FileStoreConfig
expectedInitContainers []corev1.Container
}{
{
Expand Down Expand Up @@ -887,6 +886,50 @@ func TestGenerateDeployment_V1Beta(t *testing.T) {
}
})

t.Run("custom sidecar container pod extension", func(t *testing.T) {
dbConfig := &ExternalDBConfig{dbType: database.PostgreSQLDatabase, hasDBCheckURL: false}
customSideBarContainers := []corev1.Container{
{Image: "my-log-exporter-image", Name: "log-exporter"},
{Image: "my-audit-image", Name: "audit"},
}

for _, testCase := range []struct {
description string
mmSpec mmv1beta.MattermostSpec
expectedSidecarContainers []corev1.Container
}{
{
description: "no custom sidebar containers",
mmSpec: mmv1beta.MattermostSpec{
PodExtensions: mmv1beta.PodExtensions{
SidecarContainers: nil,
},
},
expectedSidecarContainers: nil,
},
{
description: "custom sidebar containers",
mmSpec: mmv1beta.MattermostSpec{
PodExtensions: mmv1beta.PodExtensions{
SidecarContainers: customSideBarContainers,
},
},
expectedSidecarContainers: customSideBarContainers,
},
} {
t.Run(testCase.description, func(t *testing.T) {
mattermost := &mmv1beta.Mattermost{
Spec: testCase.mmSpec,
}
deployment := GenerateDeploymentV1Beta(mattermost, dbConfig, &ExternalFileStore{}, "", "", "", "image")
require.Equal(t, len(testCase.expectedSidecarContainers), len(deployment.Spec.Template.Spec.Containers)-1)
if testCase.mmSpec.PodExtensions.SidecarContainers != nil {
assert.Equal(t, testCase.expectedSidecarContainers, deployment.Spec.Template.Spec.Containers[1:])
}
})
}
})

t.Run("should set SiteURL env if ingress host provided", func(t *testing.T) {
mattermost := &mmv1beta.Mattermost{
Spec: mmv1beta.MattermostSpec{},
Expand Down
Empty file modified vendor/k8s.io/code-generator/generate-groups.sh
100644 → 100755
Empty file.