Skip to content

Commit

Permalink
Merge pull request #198 from ThetaDR/namespace-annotation-fix
Browse files Browse the repository at this point in the history
Prevent double applying annotation when namespace annotation is used
  • Loading branch information
denis-tingaikin authored Nov 9, 2022
2 parents 677922a + 5db2406 commit 36b6bbe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,7 @@ issues:
exclude-use-default: false
max-issues-per-linter: 0
max-same-issues: 0
exclude-rules:
- path: main.go
linters:
- goconst
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,13 @@ func (s *admissionWebhookServer) Review(ctx context.Context, in *admissionv1.Adm
}
annotation := podMetaPtr.Annotations[s.config.Annotation]

if annotation == "" && in.Kind.Kind != "Pod" {
resp.Allowed = true
return resp
}

// use namespace annotation only if resource doesn't have it's own
if annotation == "" {
if annotation == "" && in.Kind.Kind == "Pod" {
timeoutCtx, cancel := context.WithTimeout(ctx, time.Second)
defer cancel()
namespace, err := s.clientset.CoreV1().Namespaces().Get(timeoutCtx, in.Namespace, v1.GetOptions{})
Expand Down

0 comments on commit 36b6bbe

Please sign in to comment.