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

Changes bootstrap #929

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
21 changes: 0 additions & 21 deletions .github/workflows/add-untriaged.yaml

This file was deleted.

5 changes: 3 additions & 2 deletions .github/workflows/docker-build.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: "Docker Build"
on:
workflow_dispatch:
push:
pull_request:
branches:
- "main"

jobs:
docker-build:
runs-on: ubuntu-latest
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/functional-tests.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Functional tests
on: [pull_request]
on:
workflow_dispatch:
push:
pull_request:

jobs:
operator:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/go-linting.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Golang Lint
on: [pull_request]
on:
workflow_dispatch:
push:
pull_request:

jobs:
golangci-lint:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/helm-linting.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Helm Lint
on:
workflow_dispatch:
push:
pull_request:
paths:
- 'charts/**'

jobs:
helm-lint:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/helm-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Release Helm Charts

on:
workflow_dispatch:
push:
branches:
- main
#push:
# branches:
# - main

jobs:
release:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/make-install.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Make install
on: [pull_request]
on:
workflow_dispatch:
push:
pull_request:

jobs:
make-install:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Testing
on: [pull_request]
on:
workflow_dispatch:
push:
pull_request:

jobs:
unit-tests:
Expand Down
4 changes: 4 additions & 0 deletions charts/opensearch-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ cluster:
# If jvm is not provided and resources.requests.memory does not exist then value will be -Xmx512M -Xms512M
jvm: ""

priorityClassName: ""

labels: {}

# -- bootstrap pod node selectors
nodeSelector: {}

Expand Down
11 changes: 7 additions & 4 deletions opensearch-operator/api/v1/opensearch_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,11 @@ type BootstrapConfig struct {
Affinity *corev1.Affinity `json:"affinity,omitempty"`
Jvm string `json:"jvm,omitempty"`
// Extra items to add to the opensearch.yml, defaults to General.AdditionalConfig
AdditionalConfig map[string]string `json:"additionalConfig,omitempty"`
PluginsList []string `json:"pluginsList,omitempty"`
Keystore []KeystoreValue `json:"keystore,omitempty"`
AdditionalConfig map[string]string `json:"additionalConfig,omitempty"`
PluginsList []string `json:"pluginsList,omitempty"`
Keystore []KeystoreValue `json:"keystore,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
}

type DashboardsServiceSpec struct {
Expand Down Expand Up @@ -274,7 +276,8 @@ type SecurityConfig struct {

// Specific configs for the SecurityConfig update job
type SecurityUpdateJobConfig struct {
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
}

type ImageSpec struct {
Expand Down
7 changes: 7 additions & 0 deletions opensearch-operator/api/v1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,10 @@ spec:
x-kubernetes-map-type: atomic
type: object
type: array
labels:
additionalProperties:
type: string
type: object
nodeSelector:
additionalProperties:
type: string
Expand All @@ -868,6 +872,8 @@ spec:
items:
type: string
type: array
priorityClassName:
type: string
resources:
description: ResourceRequirements describes the compute resource
requirements.
Expand Down Expand Up @@ -5268,6 +5274,8 @@ spec:
description: Specific configs for the SecurityConfig update
job
properties:
priorityClassName:
type: string
resources:
description: ResourceRequirements describes the compute
resource requirements.
Expand Down
15 changes: 12 additions & 3 deletions opensearch-operator/pkg/builders/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,9 +759,10 @@ func NewBootstrapPod(
volumes []corev1.Volume,
volumeMounts []corev1.VolumeMount,
) *corev1.Pod {
labels := map[string]string{
helpers.ClusterLabel: cr.Name,
}
labels := make(map[string]string)
labels[helpers.ClusterLabel] = cr.Name
labels["opster.io/bootstrap-node"] = "true"

resources := cr.Spec.Bootstrap.Resources

var jvm string
Expand All @@ -771,6 +772,11 @@ func NewBootstrapPod(
jvm = cr.Spec.Bootstrap.Jvm
}

// cr.Spec.Bootstrap.labels
for key, value := range cr.Spec.Bootstrap.Labels {
labels[key] = value
}

image := helpers.ResolveImage(cr, nil)
initHelperImage := helpers.ResolveInitHelperImage(cr)
masterRole := helpers.ResolveClusterManagerRole(cr.Spec.General.Version)
Expand Down Expand Up @@ -1001,6 +1007,7 @@ func NewBootstrapPod(
Affinity: cr.Spec.Bootstrap.Affinity,
ImagePullSecrets: image.ImagePullSecrets,
SecurityContext: podSecurityContext,
PriorityClassName: cr.Spec.Bootstrap.PriorityClassName,
},
}

Expand Down Expand Up @@ -1109,6 +1116,7 @@ func NewSecurityconfigUpdateJob(
securityContext := instance.Spec.General.SecurityContext
podSecurityContext := instance.Spec.General.PodSecurityContext
resources := instance.Spec.Security.GetConfig().GetUpdateJob().Resources
priorityClassName := instance.Spec.Security.GetConfig().GetUpdateJob().PriorityClassName
return batchv1.Job{
ObjectMeta: metav1.ObjectMeta{Name: jobName, Namespace: namespace, Annotations: annotations},
Spec: batchv1.JobSpec{
Expand All @@ -1132,6 +1140,7 @@ func NewSecurityconfigUpdateJob(
RestartPolicy: corev1.RestartPolicyNever,
ImagePullSecrets: image.ImagePullSecrets,
SecurityContext: podSecurityContext,
PriorityClassName: priorityClassName,
},
},
},
Expand Down
64 changes: 64 additions & 0 deletions opensearch-operator/pkg/builders/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,27 @@ func ClusterDescWithAdditionalConfigs(addtitionalConfig map[string]string, boots
}
}

func ClusterDescWithBootstrapPriorityClassNameAndLabel(prioClassName string, labels map[string]string) opsterv1.OpenSearchCluster {
return opsterv1.OpenSearchCluster{
Spec: opsterv1.ClusterSpec{
Bootstrap: opsterv1.BootstrapConfig{
PriorityClassName: prioClassName,
Labels: labels,
},
},
}
}

func ClusterDescWithBootstrapResources(resources corev1.ResourceRequirements) opsterv1.OpenSearchCluster {
return opsterv1.OpenSearchCluster{
Spec: opsterv1.ClusterSpec{
Bootstrap: opsterv1.BootstrapConfig{
Resources: resources,
},
},
}
}

var _ = Describe("Builders", func() {
When("Constructing a STS for a NodePool", func() {
It("should include the init containers as SKIP_INIT_CONTAINER is not set", func() {
Expand Down Expand Up @@ -934,4 +955,47 @@ var _ = Describe("Builders", func() {
Expect(job.Spec.Template.Spec.Containers[0].Resources).To(Equal(clusterObject.Spec.Security.Config.UpdateJob.Resources))
})
})

When("Constructing a bootstrap pod with priorityClass and label Values", func() {
It("should create a proper bootstrap spec with priorityClass and labels", func() {
prioClassName := "testprioclass"

labels := map[string]string{
"testlabel1": "testvalue1",
"testlabel2": "testvalue2",
}

clusterObject := ClusterDescWithBootstrapPriorityClassNameAndLabel(prioClassName, labels)

result := NewBootstrapPod(&clusterObject, nil, nil)
Expect(result.Spec.PriorityClassName).To(Equal(prioClassName))
Expect(result.Labels).To(Equal(map[string]string{
"opster.io/opensearch-cluster": "",
"opster.io/bootstrap-node": "true",
"testlabel1": "testvalue1",
"testlabel2": "testvalue2",
}))
})
})

When("Constructing a bootstrap pod with resources", func() {
It("should create a proper spec with resources", func() {

resources := corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1000m"),
corev1.ResourceMemory: resource.MustParse("1Gi"),
},
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("500m"),
corev1.ResourceMemory: resource.MustParse("2Gi"),
},
}

clusterObject := ClusterDescWithBootstrapResources(resources)

result := NewBootstrapPod(&clusterObject, nil, nil)
Expect(result.Spec.Containers[0].Resources).To(Equal(resources))
})
})
})