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 draft support for namespace annotations #180

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import (
"github.com/networkservicemesh/sdk/pkg/tools/opentelemetry"
)

var namespace_annotations map[string]map[string]string
var deserializer = serializer.NewCodecFactory(runtime.NewScheme()).UniversalDeserializer()

type admissionWebhookServer struct {
Expand All @@ -69,6 +70,21 @@ func (s *admissionWebhookServer) Review(in *admissionv1.AdmissionRequest) *admis
return resp
}

if in.Kind.Kind == "Namespace" {
var namespace_kind corev1.Namespace
// var target interface{}
target := &namespace_kind
labels := &namespace_kind.ObjectMeta.Labels
if err := json.Unmarshal(in.Object.Raw, target); err != nil {
resp.Result = &v1.Status{
Status: err.Error(),
}
return resp
}
namespace_annotations[in.Name] = *labels
return resp
}

podMetaPtr, spec := s.unmarshal(in)
p := ""
if in.Kind.Kind != "Pod" {
Expand All @@ -81,6 +97,11 @@ func (s *admissionWebhookServer) Review(in *admissionv1.AdmissionRequest) *admis
return resp
}
annotation := podMetaPtr.Annotations[s.config.Annotation]
if _, ok := namespace_annotations[in.Namespace]; ok {
for k, v := range namespace_annotations[in.Namespace] {
annotation = annotation + "," + k + v
}
}

if annotation != "" {
bytes, err := json.Marshal([]jsonpatch.JsonPatchOperation{
Expand Down