Skip to content
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

Conversation

anastasia-malysheva
Copy link
Contributor

Add support of namespace annotations

Issue
#126

MarinaShustowa and others added 3 commits August 9, 2022 12:14
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
Comment on lines 297 to 308
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
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
}

Copy link
Member

@denis-tingaikin denis-tingaikin left a 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(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
clientset: getClientSet(),

logger: logger.Named("admissionWebhookServer"),
config: conf,
logger: logger.Named("admissionWebhookServer"),
clientset: getClientSet(),
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}
_ , clientset, err := k8s.NewVersionedClient()
if err != nil {
logger.Fatal(err.Error())
}

Copy link
Contributor Author

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{})
Copy link
Member

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{})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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>
@denis-tingaikin denis-tingaikin merged commit f61ab27 into networkservicemesh:main Aug 17, 2022
nsmbot pushed a commit to networkservicemesh/deployments-k8s that referenced this pull request Aug 17, 2022
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants