-
Notifications
You must be signed in to change notification settings - Fork 11
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
register podopslifecycle webhook #26
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shaofan-hs
force-pushed
the
podopslifecycle3
branch
2 times, most recently
from
August 15, 2023 13:04
cdb1bfe
to
c3d35b4
Compare
shaofan-hs
force-pushed
the
podopslifecycle3
branch
from
August 16, 2023 09:14
c3d35b4
to
23910c0
Compare
shaofan-hs
force-pushed
the
podopslifecycle3
branch
from
August 17, 2023 05:06
04b3672
to
73398cc
Compare
Eikykun
requested changes
Aug 17, 2023
shaofan-hs
force-pushed
the
podopslifecycle3
branch
from
August 17, 2023 06:08
564f452
to
6c3b3c7
Compare
Eikykun
reviewed
Aug 17, 2023
shaofan-hs
force-pushed
the
podopslifecycle3
branch
from
August 17, 2023 06:40
e3626b8
to
bf35909
Compare
shaofan-hs
force-pushed
the
podopslifecycle3
branch
from
August 17, 2023 07:18
bf35909
to
8e008b3
Compare
Eikykun
reviewed
Aug 17, 2023
Comment on lines
+31
to
+83
func (lc *OpsLifecycle) Validating(ctx context.Context, c client.Client, oldPod, newPod *corev1.Pod, operation admissionv1.Operation) error { | ||
if !utils.ControlledByPodOpsLifecycle(newPod) { | ||
return nil | ||
} | ||
|
||
expectedLabels := make(map[string]struct{}) | ||
foundLabels := make(map[string]struct{}) | ||
for label := range newPod.Labels { | ||
for _, v := range pairLabelPrefixesMap { // labels must exist together and have the same id | ||
if !strings.HasPrefix(label, v) { | ||
continue | ||
} | ||
|
||
s := strings.Split(label, "/") | ||
if len(s) != 2 { | ||
return fmt.Errorf("invalid label %s", label) | ||
} | ||
id := s[1] | ||
|
||
if id != "" { | ||
pairLabel := fmt.Sprintf("%s/%s", pairLabelPrefixesMap[v], id) | ||
_, ok := newPod.Labels[pairLabel] | ||
if !ok { | ||
return fmt.Errorf("not found label %s", pairLabel) | ||
} | ||
} | ||
} | ||
|
||
found := false | ||
for v := range expectedLabels { // try to find the expected another label prefixes | ||
if strings.HasPrefix(label, v) { | ||
foundLabels[v] = struct{}{} | ||
found = true | ||
break | ||
} | ||
} | ||
if found { | ||
continue | ||
} | ||
|
||
for _, v := range coexistingLabelPrefixesMap { // labels must exist together | ||
if !strings.HasPrefix(label, v) { | ||
continue | ||
} | ||
expectedLabels[coexistingLabelPrefixesMap[v]] = struct{}{} | ||
} | ||
} | ||
|
||
if len(expectedLabels) != len(foundLabels) { | ||
return fmt.Errorf("not found the expected label prefixes: %v", expectedLabels) | ||
} | ||
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.
func (lc *OpsLifecycle) Validating(ctx context.Context, c client.Client, oldPod, newPod *corev1.Pod, operation admissionv1.Operation) error {
if !utils.ControlledByPodOpsLifecycle(newPod) {
return nil
}
allPrefix := sets.NewString()
for label := range newPod.Labels {
s := strings.Split(label, "/")
if len(s) != 2 {
return fmt.Errorf("invalid label %s", label)
}
prefix, id := s[0], s[1]
allPrefix.Insert(prefix)
for _, v := range pairLabelPrefixesMap { // labels must exist together and have the same id
if prefix != v {
continue
}
if id != "" {
pairLabel := fmt.Sprintf("%s/%s", pairLabelPrefixesMap[v], id)
_, ok := newPod.Labels[pairLabel]
if !ok {
return fmt.Errorf("not found label %s", pairLabel)
}
}
}
}
for prefix := range allPrefix {
pair := coexistingLabelPrefixesMap[prefix]
if pair != "" && !allPrefix.Has(pair) {
return fmt.Errorf("not found the expected label prefixes: %v", pair)
}
}
return nil
}
Eikykun
approved these changes
Aug 17, 2023
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):
re #11 #28 #21
2. What is the scope of this PR (e.g. component or file name):
3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):
4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):
5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:
6. Release note
Please refer to Release Notes Language Style Guide to write a quality release note.