-
Notifications
You must be signed in to change notification settings - Fork 16
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 support of namespace annotations #181
Add support of namespace annotations #181
Conversation
Signed-off-by: Marina Shustova <marina.shustova@xored.com>
… update operations. Signed-off-by: anastasia.malysheva <anastasia.malysheva@xored.com>
Signed-off-by: anastasia.malysheva <anastasia.malysheva@xored.com>
main.go
Outdated
func getClientSet() *kubernetes.Clientset { | ||
c, err := rest.InClusterConfig() | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
clientset, err := kubernetes.NewForConfig(c) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
return clientset | ||
} | ||
|
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 getClientSet() *kubernetes.Clientset { | |
c, err := rest.InClusterConfig() | |
if err != nil { | |
panic(err.Error()) | |
} | |
clientset, err := kubernetes.NewForConfig(c) | |
if err != nil { | |
panic(err.Error()) | |
} | |
return clientset | |
} |
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.
Please re-use our sdk-k8s utils pkg https://github.com/networkservicemesh/sdk-k8s/blob/main/pkg/tools/k8s/kubeutils.go#L50
It will make webhook always up to date with sdk-k8s, k8s deps.
main.go
Outdated
logger: logger.Named("admissionWebhookServer"), | ||
config: conf, | ||
logger: logger.Named("admissionWebhookServer"), | ||
clientset: getClientSet(), |
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.
clientset: getClientSet(), |
logger: logger.Named("admissionWebhookServer"), | ||
config: conf, | ||
logger: logger.Named("admissionWebhookServer"), | ||
clientset: getClientSet(), | ||
} |
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.
} | |
} | |
_ , clientset, err := k8s.NewVersionedClient() | |
if err != nil { | |
logger.Fatal(err.Error()) | |
} |
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.
@denis-tingaikin I've added fixes as you proposed. Please, take a look.
Signed-off-by: anastasia.malysheva <anastasia.malysheva@xored.com>
main.go
Outdated
@@ -82,6 +84,15 @@ func (s *admissionWebhookServer) Review(in *admissionv1.AdmissionRequest) *admis | |||
} | |||
annotation := podMetaPtr.Annotations[s.config.Annotation] | |||
|
|||
// use namespace annotation only if resource doesn't have it's own | |||
if annotation == "" { | |||
namespace, err := s.clientset.CoreV1().Namespaces().Get(ctx, in.Namespace, v1.GetOptions{}) |
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.
Please add a timeout for the context here to avoid a potential goroutines leak/improve responsiveness.
main.go
Outdated
@@ -82,6 +84,15 @@ func (s *admissionWebhookServer) Review(in *admissionv1.AdmissionRequest) *admis | |||
} | |||
annotation := podMetaPtr.Annotations[s.config.Annotation] | |||
|
|||
// use namespace annotation only if resource doesn't have it's own | |||
if annotation == "" { | |||
namespace, err := s.clientset.CoreV1().Namespaces().Get(ctx, in.Namespace, v1.GetOptions{}) |
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.
namespace, err := s.clientset.CoreV1().Namespaces().Get(ctx, in.Namespace, v1.GetOptions{}) | |
timeoutCtx, cancel := context.WithTimeout(ctx, time.Second) | |
defer cancel() | |
namespace, err := s.clientset.CoreV1().Namespaces().Get(timeoutCtx, in.Namespace, v1.GetOptions{}) |
…ebhook-k8s into add-namespace-support � Conflicts: � go.mod � go.sum
Signed-off-by: anastasia.malysheva <anastasia.malysheva@xored.com>
…d-admission-webhook-k8s@main PR link: networkservicemesh/cmd-admission-webhook-k8s#181 Commit: f61ab27 Author: Denis Tingaikin Date: 2022-08-17 12:45:11 +0300 Message: - Merge pull request #181 from anastasia-malysheva/add-namespace-support Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
Add support of namespace annotations
Issue
#126