Fix Istio sidecar injection by moving from annotations to labels (#2527)

* Fix Istio sidecar injection by moving from annotations to labels

Signed-off-by: madmecodes <[email protected]>

* Update Istio sidecar injection from annotations to labels across the codebase
Replace annotations with labels for Istio sidecar injection according to Istio recommendations. Update conformance tests, examples, constants, composers, and utilities to use the new label-based approach consistently.

Signed-off-by: madmecodes <[email protected]>

* fix: Update SuggestionLabels function and composer implementation for Istio label injection

Signed-off-by: madmecodes <[email protected]>

* Fix linting issues in mpi-job-horovod.py

Signed-off-by: madmecodes <[email protected]>

* update: function moved from annotations to labels

Signed-off-by: madmecodes <[email protected]>

---------

Signed-off-by: madmecodes <[email protected]>
This commit is contained in:
Ayush Gupta
2025-05-09 17:52:41 +00:00
committed by GitHub
parent e528adf086
commit 1c19d3a6eb
19 changed files with 39 additions and 75 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
# Run conformance test and generate test report.
python test/e2e/v1beta1/scripts/gh-actions/run-e2e-experiment.py --experiment-path examples/v1beta1/hp-tuning/random.yaml --namespace kf-conformance \
--trial-pod-annotations '{"sidecar.istio.io/inject": "false"}' | tee /tmp/katib-conformance.log
--trial-pod-labels '{"sidecar.istio.io/inject": "false"}' | tee /tmp/katib-conformance.log
# Create the done file.
@@ -180,7 +180,7 @@ SucceededCondition: Succeeded
Previously, we had problems with Istio sidecar containers,
check [kubeflow/issue#1081](https://github.com/kubeflow/kubeflow/issues/4742).
In some cases, it is unable to properly download datasets in training pod.
It was fixed by adding annotation `sidecar.istio.io/inject: false` to appropriate Trial job in Katib controller.
It was fixed by adding label `sidecar.istio.io/inject: false` to appropriate Trial job in Katib controller.
Various CRD can have unified design and it is hard to understand where annotation must be specified
to disable Istio injection for the running pods.
@@ -222,7 +222,7 @@
" \"spec\": {\n",
" \"template\": {\n",
" \"metadata\": {\n",
" \"annotations\": {\n",
" \"labels\": {\n",
" \"sidecar.istio.io/inject\": \"false\"\n",
" }\n",
" },\n",
@@ -210,7 +210,7 @@
" \"restartPolicy\": \"OnFailure\",\n",
" \"template\": {\n",
" \"metadata\": {\n",
" \"annotations\": {\n",
" \"labels\": {\n",
" \"sidecar.istio.io/inject\": \"false\"\n",
" }\n",
" },\n",
@@ -236,7 +236,7 @@
" \"restartPolicy\": \"OnFailure\",\n",
" \"template\": {\n",
" \"metadata\": {\n",
" \"annotations\": {\n",
" \"labels\": {\n",
" \"sidecar.istio.io/inject\": \"false\"\n",
" }\n",
" },\n",
@@ -360,7 +360,7 @@
" \"restartPolicy\": \"OnFailure\",\n",
" \"template\": {\n",
" \"metadata\": {\n",
" \"annotations\": {\n",
" \"labels\": {\n",
" \"sidecar.istio.io/inject\": \"false\"\n",
" }\n",
" },\n",
@@ -401,7 +401,7 @@
" \"restartPolicy\": \"OnFailure\",\n",
" \"template\": {\n",
" \"metadata\": {\n",
" \"annotations\": {\n",
" \"labels\": {\n",
" \"sidecar.istio.io/inject\": \"false\"\n",
" }\n",
" },\n",
@@ -600,7 +600,7 @@
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAAAAABXZoBIAAAA1ElEQVR4nN3QPwtBYRQG8EMU0e0uZLIw+QKXRZlMGC0GX8CglE0pk0VxPwQmE5YrJYPVIjYMlImSwXNiMOi97319AM/6O6fzh+g/Y5hr5mrRNByseAZba4D7EnlSN8wy3uAYXJOwDEw0ohKwD9mtxehqRLQBCnZr8GPkJ/Ll79y0m37GiIjiK2AQsGMYiIbryyvjmZO20U9gAIcjTg43GhfethOROToO+En6xRUlZhnSjd+I6BY7xVIRY79w4XapR9IOSTWWYSWUqE0xlH771R7UrULefm5U2pxVCt0AAAAASUVORK5CYII=\n",
"image/png": "iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAAAAABXZoBIAAAA1ElEQVR4nN3QPwtBYRQG8EMU0e0uZLIw+QKXRZlMGC0GX8CglE0pk0VxPwQmE5YrJYPVIjYMlImSwXNiMOi97319AM/6O6fzh+g/Y5hr5mrRNByseAZba4D7EnlSN8wy3uAYXJOwDEw0ohKwD9mtxehqRLQBCnZr8GPkJ/Ll79y0m37GiIjiK2AQsGMYiIbryyvjmZO20U9gAIcjTg43GhfethOROToO+En6xRUlZhnSjd+I6BY7xVIRY79w4XapR9IOSTWWYSWUqE0xlH771R7UrULefm5U2pxVCt0AAAAASUVORK5CYII=",
"text/plain": [
"<PIL.BmpImagePlugin.BmpImageFile image mode=L size=28x28 at 0x7F9A711F33A0>"
]
@@ -96,9 +96,7 @@ def horovod_mnist_hpo(
"Launcher": {
"replicas": 1,
"template": {
"metadata": {
"annotations": {"sidecar.istio.io/inject": "false"}
},
"metadata": {"labels": {"sidecar.istio.io/inject": "false"}},
"spec": {
"containers": [
{
@@ -141,9 +139,7 @@ def horovod_mnist_hpo(
"Worker": {
"replicas": 2,
"template": {
"metadata": {
"annotations": {"sidecar.istio.io/inject": "false"}
},
"metadata": {"labels": {"sidecar.istio.io/inject": "false"}},
"spec": {
"containers": [
{
@@ -125,7 +125,7 @@
" \"spec\": {\n",
" \"template\": {\n",
" \"metadata\": {\n",
" \"annotations\": {\n",
" \"labels\": {\n",
" \"sidecar.istio.io/inject\": \"false\"\n",
" }\n",
" },\n",
+1 -1
View File
@@ -224,7 +224,7 @@
" \"spec\": {\n",
" \"template\": {\n",
" \"metadata\": {\n",
" \"annotations\": {\n",
" \"labels\": {\n",
" \"sidecar.istio.io/inject\": \"false\"\n",
" }\n",
" },\n",
@@ -15,10 +15,10 @@ spec:
metadata:
labels:
katib.kubeflow.org/component: controller
sidecar.istio.io/inject: "false"
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "8080"
sidecar.istio.io/inject: "false"
spec:
serviceAccountName: katib-controller
containers:
@@ -15,7 +15,6 @@ spec:
metadata:
labels:
katib.kubeflow.org/component: db-manager
annotations:
sidecar.istio.io/inject: "false"
spec:
containers:
@@ -17,7 +17,6 @@ spec:
metadata:
labels:
katib.kubeflow.org/component: mysql
annotations:
sidecar.istio.io/inject: "false"
spec:
securityContext:
@@ -17,8 +17,8 @@ spec:
metadata:
labels:
katib.kubeflow.org/component: postgres
annotations:
sidecar.istio.io/inject: "false"
annotations:
spec:
containers:
- name: katib-postgres
-1
View File
@@ -15,7 +15,6 @@ spec:
metadata:
labels:
katib.kubeflow.org/component: ui
annotations:
sidecar.istio.io/inject: "false"
spec:
containers:
@@ -6,5 +6,5 @@ metadata:
spec:
template:
metadata:
annotations:
labels:
sidecar.istio.io/inject: "true"
+4 -4
View File
@@ -119,11 +119,11 @@ const (
// JobKindJob is the kind of the Kubernetes Job.
JobKindJob = "Job"
// AnnotationIstioSidecarInjectName is the annotation of Istio Sidecar
AnnotationIstioSidecarInjectName = "sidecar.istio.io/inject"
// LabelIstioSidecarInjectName is the label of Istio Sidecar
LabelIstioSidecarInjectName = "sidecar.istio.io/inject"
// AnnotationIstioSidecarInjectValue is the value of Istio Sidecar annotation
AnnotationIstioSidecarInjectValue = "false"
// LabelIstioSidecarInjectValue is the value of Istio Sidecar label
LabelIstioSidecarInjectValue = "false"
// LabelTrialTemplateConfigMapName is the label name for the Trial templates configMap
LabelTrialTemplateConfigMapName = "katib.kubeflow.org/component"
@@ -104,7 +104,7 @@ func (g *General) DesiredDeployment(s *suggestionsv1beta1.Suggestion) (*appsv1.D
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: util.SuggestionLabels(s),
Annotations: util.SuggestionAnnotations(s),
Annotations: s.Annotations,
},
Spec: corev1.PodSpec{
Containers: g.desiredContainers(s, suggestionConfigData, earlyStoppingConfigData),
@@ -72,15 +72,15 @@ var (
}
deploymentLabels = map[string]string{
"custom-label": "test",
consts.LabelDeploymentName: suggestionName + "-" + suggestionAlgorithm,
consts.LabelExperimentName: suggestionName,
consts.LabelSuggestionName: suggestionName,
"custom-label": "test",
consts.LabelDeploymentName: suggestionName + "-" + suggestionAlgorithm,
consts.LabelExperimentName: suggestionName,
consts.LabelSuggestionName: suggestionName,
consts.LabelIstioSidecarInjectName: consts.LabelIstioSidecarInjectValue,
}
podAnnotations = map[string]string{
"custom-annotation": "test",
"sidecar.istio.io/inject": "false",
"custom-annotation": "test",
}
namespace = "kubeflow"
@@ -1,40 +0,0 @@
/*
Copyright 2022 The Kubeflow Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package util
import (
suggestionsv1beta1 "github.com/kubeflow/katib/pkg/apis/controller/suggestions/v1beta1"
"github.com/kubeflow/katib/pkg/controller.v1beta1/consts"
)
// SuggestionAnnotations returns the expected suggestion annotations.
func SuggestionAnnotations(instance *suggestionsv1beta1.Suggestion) map[string]string {
return appendAnnotation(
instance.Annotations,
consts.AnnotationIstioSidecarInjectName,
consts.AnnotationIstioSidecarInjectValue)
}
func appendAnnotation(annotations map[string]string, newAnnotationName string, newAnnotationValue string) map[string]string {
res := make(map[string]string)
for k, v := range annotations {
res[k] = v
}
res[newAnnotationName] = newAnnotationValue
return res
}
+12 -1
View File
@@ -22,6 +22,7 @@ import (
"github.com/kubeflow/katib/pkg/controller.v1beta1/consts"
)
// SuggestionLabels returns the expected suggestion labels.
// SuggestionLabels returns the expected suggestion labels.
func SuggestionLabels(instance *suggestionsv1beta1.Suggestion) map[string]string {
res := make(map[string]string)
@@ -31,7 +32,7 @@ func SuggestionLabels(instance *suggestionsv1beta1.Suggestion) map[string]string
res[consts.LabelDeploymentName] = GetSuggestionDeploymentName(instance)
res[consts.LabelExperimentName] = instance.Name
res[consts.LabelSuggestionName] = instance.Name
res[consts.LabelIstioSidecarInjectName] = consts.LabelIstioSidecarInjectValue
return res
}
@@ -45,3 +46,13 @@ func TrialLabels(instance *experimentsv1beta1.Experiment) map[string]string {
return res
}
// AppendIstioSidecarLabel adds the Istio sidecar injection label to a labels map
func AppendIstioSidecarLabel(labels map[string]string) map[string]string {
res := make(map[string]string)
for k, v := range labels {
res[k] = v
}
res[consts.LabelIstioSidecarInjectName] = consts.LabelIstioSidecarInjectValue
return res
}
@@ -95,7 +95,7 @@ def generate_trial_template() -> V1beta1TrialTemplate:
"kind": "Job",
"spec": {
"template": {
"metadata": {"annotations": {"sidecar.istio.io/inject": "false"}},
"metadata": {"labels": {"sidecar.istio.io/inject": "false"}},
"spec": {
"containers": [
{