mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2025-09-08 02:30:23 +00:00
feat: admission webhooks (#553)
* feat: add Validating/Mutating webhook analyzer Signed-off-by: Rakshit Gondwal <rakshitgondwal3@gmail.com> * change conditions Signed-off-by: Rakshit Gondwal <rakshitgondwal3@gmail.com> * fix: use GetClient to get pods and mask pod name Signed-off-by: Rakshit Gondwal <rakshitgondwal3@gmail.com> * fix: add new cases in util.GetParent Signed-off-by: Rakshit Gondwal <rakshitgondwal3@gmail.com> * feat: implements webhooks Signed-off-by: Alex Jones <alexsimonjones@gmail.com> * feat: implements webhooks Signed-off-by: Alex Jones <alexsimonjones@gmail.com> * feat: implements webhooks Signed-off-by: Alex Jones <alexsimonjones@gmail.com> * feat: implements webhooks Signed-off-by: Alex Jones <alexsimonjones@gmail.com> --------- Signed-off-by: Rakshit Gondwal <rakshitgondwal3@gmail.com> Signed-off-by: Alex Jones <alexsimonjones@gmail.com> Co-authored-by: Rakshit Gondwal <rakshitgondwal3@gmail.com> Co-authored-by: Aris Boutselis <aris.boutselis@senseon.io>
This commit is contained in:
@@ -94,6 +94,26 @@ func GetParent(client *kubernetes.Client, meta metav1.ObjectMeta) (string, bool)
|
||||
return GetParent(client, ds.ObjectMeta)
|
||||
}
|
||||
return "Ingress/" + ds.Name, false
|
||||
|
||||
case "MutatingWebhookConfiguration":
|
||||
mw, err := client.GetClient().AdmissionregistrationV1().MutatingWebhookConfigurations().Get(context.Background(), owner.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return "", false
|
||||
}
|
||||
if mw.OwnerReferences != nil {
|
||||
return GetParent(client, mw.ObjectMeta)
|
||||
}
|
||||
return "MutatingWebhook/" + mw.Name, false
|
||||
|
||||
case "ValidatingWebhookConfiguration":
|
||||
vw, err := client.GetClient().AdmissionregistrationV1().ValidatingWebhookConfigurations().Get(context.Background(), owner.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return "", false
|
||||
}
|
||||
if vw.OwnerReferences != nil {
|
||||
return GetParent(client, vw.ObjectMeta)
|
||||
}
|
||||
return "ValidatingWebhook/" + vw.Name, false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -191,3 +211,11 @@ func EnsureDirExists(dir string) error {
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func MapToString(m map[string]string) string {
|
||||
var result string
|
||||
for k, v := range m {
|
||||
result += fmt.Sprintf("%s=%s,", k, v)
|
||||
}
|
||||
return result[:len(result)-1]
|
||||
}
|
||||
|
Reference in New Issue
Block a user