-
Notifications
You must be signed in to change notification settings - Fork 771
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
sidecarset support inject&upgrade pod annotations #992
Conversation
072c35a
to
6b66c7b
Compare
6b66c7b
to
b877b92
Compare
Codecov Report
@@ Coverage Diff @@
## master #992 +/- ##
==========================================
- Coverage 49.64% 49.60% -0.04%
==========================================
Files 124 124
Lines 12078 12156 +78
==========================================
+ Hits 5996 6030 +34
- Misses 5166 5198 +32
- Partials 916 928 +12
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
annotationsInOthers[key] = fmt.Sprintf("%s#%s", set.Name, patch.PatchPolicy) | ||
} | ||
} | ||
if set.Spec.PatchPodMetadata != 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.
SA9003: empty branch
Reply with "@sonatype-lift help" for info about LiftBot commands.
Reply with "@sonatype-lift ignore" to tell LiftBot to leave out the above finding from this PR.
Reply with "@sonatype-lift ignoreall" to tell LiftBot to leave out all the findings from this PR and from the status bar in Github.
When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands.
Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]
@@ -21,6 +21,7 @@ import ( | |||
"encoding/json" | |||
"flag" | |||
"fmt" | |||
"sigs.k8s.io/controller-runtime/pkg/predicate" |
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
Reply with "@sonatype-lift help" for info about LiftBot commands.
Reply with "@sonatype-lift ignore" to tell LiftBot to leave out the above finding from this PR.
Reply with "@sonatype-lift ignoreall" to tell LiftBot to leave out all the findings from this PR and from the status bar in Github.
When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands.
Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]
pkg/control/sidecarcontrol/util.go
Outdated
} | ||
|
||
func ValidateSidecarSetPatchMetadataWhitelist(sidecarSet *appsv1alpha1.SidecarSet) error { | ||
if !utilfeature.DefaultFeatureGate.Enabled(features.SidecarSetPatchPodMetadataWhitelistGate) || |
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.
i think SidecarSetPatchPodMetadataWhitelistGate should be enabled by default
pkg/webhook/sidecarset/validating/sidecarset_create_update_handler.go
Outdated
Show resolved
Hide resolved
pkg/webhook/sidecarset/validating/sidecarset_create_update_handler.go
Outdated
Show resolved
Hide resolved
pkg/webhook/sidecarset/validating/sidecarset_create_update_handler.go
Outdated
Show resolved
Hide resolved
b877b92
to
3caf9bb
Compare
/lgtm |
3caf9bb
to
922698b
Compare
@@ -2,6 +2,8 @@ package validating | |||
|
|||
import ( | |||
"fmt" |
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
Reply with "@sonatype-lift help" for info about LiftBot commands.
Reply with "@sonatype-lift ignore" to tell LiftBot to leave out the above finding from this PR.
Reply with "@sonatype-lift ignoreall" to tell LiftBot to leave out all the findings from this PR and from the status bar in Github.
When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands.
Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]
82f0a2d
to
eba9b58
Compare
PatchPolicy PatchPolicyType `json:"patchPolicy,omitempty"` | ||
} | ||
|
||
type PatchPodFields struct { |
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.
PatchPodMetadataFields
as it is a sub structure in PatchPodMetadata
PatchPodMetadata []PatchPodMetadata `json:"patchPodMetadata,omitempty"` | ||
} | ||
|
||
type PatchPodMetadata struct { |
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.
PatchPodMetadata
, PatchPodFields
, PatchPolicyType
, OverwritePatchPolicy
, ..., all these definitions should have SidecarSet
prefix to avoid conflict with other resources.
pkg/util/settings/settings.go
Outdated
|
||
const ( | ||
// kruise configmap name | ||
KruiseConfigmapName = "kruise-cm" |
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.
kruise-config
orkruise-configuration
, so do the package and variable names- There is no need to init or set up the single Informer. Just
GetSidecarSetPatchMetadataWhiteList(r client.Reader)
to get ConfigMap from cache.
@@ -110,7 +111,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error { | |||
} | |||
|
|||
// Watch WorkloadSpread | |||
err = c.Watch(&source.Kind{Type: &appsv1alpha1.WorkloadSpread{}}, &handler.EnqueueRequestForObject{}) | |||
err = c.Watch(&source.Kind{Type: &appsv1alpha1.WorkloadSpread{}}, &handler.EnqueueRequestForObject{}, predicate.GenerationChangedPredicate{}) |
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.
Should we use GenerationChangedPredicate
here? If webhook modified the workloadspread status, doesn't controller need to reconcile it?
pkg/features/kruise_features.go
Outdated
PodWebhook: {Default: true, PreRelease: featuregate.Beta}, | ||
KruiseDaemon: {Default: true, PreRelease: featuregate.Beta}, | ||
DaemonWatchingPod: {Default: true, PreRelease: featuregate.Beta}, | ||
SidecarSetPatchPodMetadataWhitelistGate: {Default: true, PreRelease: featuregate.Alpha}, |
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.
Alpha featureGate should be false by default.
pkg/util/settings/types.go
Outdated
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
const ( | ||
SidecarSetPatchPodMetadataWhiteListKey = "kruise.sidecarset.patch.pod.metadata.whitelist" |
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.
I'm not sure, does K8s have any configuration stored in ConfigMap that gives us examples of the key format?
Is sidecarset-patchpodmetadata-writelist
or SidecarSet_PatchPodMetadata_WriteList
better?
pkg/util/settings/types.go
Outdated
// If selector is nil, assume that the rules should apply for every sidecarSets | ||
Selector *metav1.LabelSelector `json:"selector,omitempty"` | ||
// Support for regular expressions | ||
AnnotationKeyExprs []string `json:"annotationKeyExprs"` |
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.
AllowedAnnotationKeyExprs
is better to understand, and also in case we will add a DeniedAnnotationKeyExprs
in future.
pkg/util/tools.go
Outdated
@@ -189,3 +190,10 @@ func IsReferenceEqual(ref1, ref2 appsv1alpha1.TargetReference) bool { | |||
} | |||
return gv1.Group == gv2.Group && ref1.Kind == ref2.Kind && ref1.Name == ref2.Name | |||
} | |||
|
|||
func GetKruiseNamespace() string { |
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.
It's weird to put this in tools.go, how about a new meta.go
file?
@@ -132,7 +132,30 @@ func validateSidecarSetSpec(obj *appsv1alpha1.SidecarSet, fldPath *field.Path) f | |||
} else { | |||
allErrs = append(allErrs, validateContainersForSidecarSet(spec.InitContainers, spec.Containers, vols, fldPath.Root())...) | |||
} | |||
// validating metadata | |||
annotations := sets.NewString() |
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.
annotationKeys
allErrs = append(allErrs, field.Required(fldPath.Child("patchPodMetadata"), "no annotations defined for SidecarSet")) | ||
} else { | ||
metadata := metav1.ObjectMeta{Annotations: patch.Annotations, Name: "fake-name"} | ||
allErrs = append(allErrs, genericvalidation.ValidateObjectMeta(&metadata, false, validateSidecarSetName, field.NewPath("metadata"))...) |
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.
fldPath.Child("patchPodMetadata")..Child("annotations")
eba9b58
to
ddc0646
Compare
pkg/control/sidecarcontrol/util.go
Outdated
"github.com/openkruise/kruise/pkg/util" | ||
|
||
utilfeature "github.com/openkruise/kruise/pkg/util/feature" | ||
"github.com/openkruise/kruise/pkg/util/kruise-configuration" |
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
Reply with "@sonatype-lift help" for info about LiftBot commands.
Reply with "@sonatype-lift ignore" to tell LiftBot to leave out the above finding from this PR.
Reply with "@sonatype-lift ignoreall" to tell LiftBot to leave out all the findings from this PR and from the status bar in Github.
When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands.
Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]
"testing" | ||
|
||
appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1" | ||
|
||
"github.com/openkruise/kruise/pkg/util" | ||
"github.com/openkruise/kruise/pkg/util/kruise-configuration" |
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
Reply with "@sonatype-lift help" for info about LiftBot commands.
Reply with "@sonatype-lift ignore" to tell LiftBot to leave out the above finding from this PR.
Reply with "@sonatype-lift ignoreall" to tell LiftBot to leave out all the findings from this PR and from the status bar in Github.
When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands.
Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]
ddc0646
to
d82913d
Compare
d82913d
to
ec4d8ba
Compare
limitations under the License. | ||
*/ | ||
|
||
package kruise_configuration |
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.
Usually we don't recommend to put -
or _
into go package path. How about just configuration
?
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
const ( | ||
SidecarSetPatchPodMetadataWhiteListKey = "SidecarSet_PatchPodMetadata_WriteList" |
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.
SidecarSet_PatchPodMetadata_WhiteList
, must be my typo in #992 (comment) ...
5f1f35d
to
92f1041
Compare
Signed-off-by: liheng.zms <liheng.zms@alibaba-inc.com>
92f1041
to
71e638e
Compare
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.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: FillZpp The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Signed-off-by: liheng.zms <liheng.zms@alibaba-inc.com> Signed-off-by: Liu Zhenwei <zwliu@thoughtworks.com>
Signed-off-by: liheng.zms liheng.zms@alibaba-inc.com
Ⅰ. Describe what this PR does