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

Adding Kubernetes Node labels to Solr nodes. (WIP) #90

Draft
wants to merge 1 commit 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
12 changes: 12 additions & 0 deletions api/v1beta1/solrcloud_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ const (
DefaultBusyBoxImageRepo = "library/busybox"
DefaultBusyBoxImageVersion = "1.28.0-glibc"

DefaultJqImageRepo = "gempesaw/curl-jq"
DefaultJqImageVersion = "latest"

DefaultZkReplicas = int32(3)
DefaultZkStorage = "5Gi"
DefaultZkRepo = "emccorp/zookeeper"
Expand Down Expand Up @@ -103,6 +106,9 @@ type SolrCloudSpec struct {
// +optional
BusyBoxImage *ContainerImage `json:"busyBoxImage,omitempty"`

// +optional
JqImage *ContainerImage `json:"jqImage,omitempty"`

// +optional
SolrJavaMem string `json:"solrJavaMem,omitempty"`

Expand Down Expand Up @@ -179,6 +185,12 @@ func (spec *SolrCloudSpec) withDefaults() (changed bool) {
}
changed = spec.BusyBoxImage.withDefaults(DefaultBusyBoxImageRepo, DefaultBusyBoxImageVersion, DefaultPullPolicy) || changed

if spec.JqImage == nil {
c := ContainerImage{}
spec.JqImage = &c
}
changed = spec.JqImage.withDefaults(DefaultJqImageRepo, DefaultJqImageVersion, DefaultPullPolicy) || changed

return changed
}

Expand Down
5 changes: 5 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

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

16 changes: 16 additions & 0 deletions config/crd/bases/solr.bloomberg.com_solrclouds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3715,6 +3715,22 @@ spec:
backing this claim.
type: string
type: object
jqImage:
description: ContainerImage defines the fields needed for a Docker repository
image. The format here matches the predominant format used in Helm
charts.
properties:
imagePullSecret:
type: string
pullPolicy:
description: PullPolicy describes a policy for if/when to pull a
container image
type: string
repository:
type: string
tag:
type: string
type: object
replicas:
description: The number of solr nodes to run
format: int32
Expand Down
35 changes: 34 additions & 1 deletion controllers/util/solr_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCl
}

// Volumes & Mounts
kubeNodeInfoVolumeName := "kube-node-info"
solrVolumes := []corev1.Volume{
{
Name: "solr-xml",
Expand All @@ -98,10 +99,15 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCl
},
},
},
{
Name: kubeNodeInfoVolumeName,
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}},
},
}

solrDataVolumeName := "data"
volumeMounts := []corev1.VolumeMount{{Name: solrDataVolumeName, MountPath: "/var/solr/data"}}
nodeInfoPath := "/kubernetes/etc/node"
volumeMounts := []corev1.VolumeMount{{Name: solrDataVolumeName, MountPath: "/var/solr/data"}, {Name: kubeNodeInfoVolumeName, MountPath: nodeInfoPath}}
var pvcs []corev1.PersistentVolumeClaim
if solrCloud.Spec.DataPvcSpec != nil {
pvcs = []corev1.PersistentVolumeClaim{
Expand Down Expand Up @@ -213,6 +219,10 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCl
Name: "GC_TUNE",
Value: solrCloud.Spec.SolrGCTune,
},
{
Name: "SOLR_INCLUDE",
Value: nodeInfoPath + "/node.sh",
},
}

// Add Custom EnvironmentVariables to the solr container
Expand Down Expand Up @@ -265,6 +275,29 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCl
},
},
},
{
Name: "kube-node-labels",
Image: solrCloud.Spec.JqImage.ToImageName(),
ImagePullPolicy: solrCloud.Spec.JqImage.PullPolicy,
Command: []string{"sh", "-c", "curl -s \"https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT}/api/v1/nodes/${NODE_NAME}\" -H \"Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)\" --cacert '/var/run/secrets/kubernetes.io/serviceaccount/ca.crt' | jq -r '.metadata.labels | to_entries | map(\"-D\"+.key+\"=\"+.value)| \"export SOLR_OPTS=\\\"${SOLR_OPTS} \" + join(\" \") + \"\\\"\"' > /node-data/node.sh"},
VolumeMounts: []corev1.VolumeMount{
{
Name: kubeNodeInfoVolumeName,
MountPath: "/node-data",
},
},
Env: []corev1.EnvVar{
{
Name: "NODE_NAME",
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
APIVersion: "v1",
FieldPath: "spec.nodeName",
},
},
},
},
},
},
HostAliases: hostAliases,
Containers: []corev1.Container{
Expand Down
16 changes: 16 additions & 0 deletions helm/solr-operator/crds/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5193,6 +5193,22 @@ spec:
backing this claim.
type: string
type: object
jqImage:
description: ContainerImage defines the fields needed for a Docker repository
image. The format here matches the predominant format used in Helm
charts.
properties:
imagePullSecret:
type: string
pullPolicy:
description: PullPolicy describes a policy for if/when to pull a
container image
type: string
repository:
type: string
tag:
type: string
type: object
replicas:
description: The number of solr nodes to run
format: int32
Expand Down