-
Notifications
You must be signed in to change notification settings - Fork 777
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 patch for UnitedDeployment #1266
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -18,8 +18,12 @@ package adapter | |
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"k8s.io/apimachinery/pkg/util/strategicpatch" | ||
"k8s.io/klog/v2" | ||
|
||
appsv1 "k8s.io/api/apps/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
@@ -146,6 +150,27 @@ func (a *DeploymentAdapter) ApplySubsetTemplate(ud *alpha1.UnitedDeployment, sub | |
attachNodeAffinity(&set.Spec.Template.Spec, subSetConfig) | ||
attachTolerations(&set.Spec.Template.Spec, subSetConfig) | ||
|
||
if subSetConfig.Patch.Raw != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. plz add ut that contain patches |
||
TemplateSpecBytes, _ := json.Marshal(set.Spec.Template) | ||
modified, err := strategicpatch.StrategicMergePatch(TemplateSpecBytes, subSetConfig.Patch.Raw, &corev1.PodTemplateSpec{}) | ||
if err != nil { | ||
klog.Errorf("failed to merge patch raw %s", subSetConfig.Patch.Raw) | ||
return err | ||
} | ||
patchedTemplateSpec := corev1.PodTemplateSpec{} | ||
if err = json.Unmarshal(modified, &patchedTemplateSpec); err != nil { | ||
klog.Errorf("failed to unmarshal %s to podTemplateSpec", modified) | ||
return err | ||
} | ||
|
||
set.Spec.Template = patchedTemplateSpec | ||
klog.V(2).Infof("Deployment [%s/%s] was patched successfully: %s", set.Namespace, set.GenerateName, subSetConfig.Patch.Raw) | ||
} | ||
if set.Annotations == nil { | ||
set.Annotations = make(map[string]string) | ||
} | ||
set.Annotations[alpha1.AnnotationSubsetPatchKey] = string(subSetConfig.Patch.Raw) | ||
|
||
return nil | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -18,8 +18,11 @@ package adapter | |||||||||
|
||||||||||
import ( | ||||||||||
"context" | ||||||||||
"encoding/json" | ||||||||||
"fmt" | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. goimports: File is not ℹ️ Expand to see all @sonatype-lift commandsYou can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.
Note: When talking to LiftBot, you need to refresh the page to see its response. |
||||||||||
|
||||||||||
"k8s.io/apimachinery/pkg/util/strategicpatch" | ||||||||||
|
||||||||||
appsv1 "k8s.io/api/apps/v1" | ||||||||||
corev1 "k8s.io/api/core/v1" | ||||||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||||||||
|
@@ -157,6 +160,26 @@ func (a *StatefulSetAdapter) ApplySubsetTemplate(ud *alpha1.UnitedDeployment, su | |||||||||
|
||||||||||
attachNodeAffinity(&set.Spec.Template.Spec, subSetConfig) | ||||||||||
attachTolerations(&set.Spec.Template.Spec, subSetConfig) | ||||||||||
if subSetConfig.Patch.Raw != nil { | ||||||||||
TemplateSpecBytes, _ := json.Marshal(set.Spec.Template) | ||||||||||
modified, err := strategicpatch.StrategicMergePatch(TemplateSpecBytes, subSetConfig.Patch.Raw, &corev1.PodTemplateSpec{}) | ||||||||||
if err != nil { | ||||||||||
klog.Errorf("failed to merge patch raw %s", subSetConfig.Patch.Raw) | ||||||||||
return err | ||||||||||
} | ||||||||||
patchedTemplateSpec := corev1.PodTemplateSpec{} | ||||||||||
if err = json.Unmarshal(modified, &patchedTemplateSpec); err != nil { | ||||||||||
klog.Errorf("failed to unmarshal %s to podTemplateSpec", modified) | ||||||||||
return err | ||||||||||
} | ||||||||||
|
||||||||||
set.Spec.Template = patchedTemplateSpec | ||||||||||
klog.V(2).Infof("StatefulSet [%s/%s] was patched successfully: %s", set.Namespace, set.GenerateName, subSetConfig.Patch.Raw) | ||||||||||
} | ||||||||||
if set.Annotations == nil { | ||||||||||
set.Annotations = make(map[string]string) | ||||||||||
} | ||||||||||
set.Annotations[alpha1.AnnotationSubsetPatchKey] = string(subSetConfig.Patch.Raw) | ||||||||||
|
||||||||||
return nil | ||||||||||
} | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
goimports: File is not
goimports
-ed❗❗ 2 similar findings have been found in this PR
🔎 Expand here to view all instances of this finding
Visit the Lift Web Console to find more details in your report.
ℹ️ Expand to see all @sonatype-lift commands
You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.
@sonatype-lift ignore
@sonatype-lift ignoreall
@sonatype-lift exclude <file|issue|path|tool>
file|issue|path|tool
from Lift findings by updating your config.toml fileNote: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.