Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Switch apiversion from betav1 to v1 #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
37 changes: 19 additions & 18 deletions pkg/k8s/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,21 @@ import (
"context"
"crypto/x509"
"encoding/pem"
"log"
"time"

"github.com/Trendyol/kubectl-view-webhook/pkg/printer"
"k8s.io/api/admissionregistration/v1beta1"
v1 "k8s.io/api/admissionregistration/v1"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
typedV1beta1 "k8s.io/client-go/kubernetes/typed/admissionregistration/v1beta1"
typedV1 "k8s.io/client-go/kubernetes/typed/admissionregistration/v1"
typedCoreV1 "k8s.io/client-go/kubernetes/typed/core/v1"
"log"
"time"
)

type WebHookClient struct {
client *kubernetes.Clientset
wClient typedV1beta1.MutatingWebhookConfigurationInterface
vClient typedV1beta1.ValidatingWebhookConfigurationInterface
wClient typedV1.MutatingWebhookConfigurationInterface
vClient typedV1.ValidatingWebhookConfigurationInterface
nClient typedCoreV1.NamespaceInterface
context context.Context
}
Expand All @@ -43,8 +44,8 @@ type WebHookClient struct {
func NewWebHookClient(client *kubernetes.Clientset) *WebHookClient {
return &WebHookClient{
client: client,
wClient: client.AdmissionregistrationV1beta1().MutatingWebhookConfigurations(),
vClient: client.AdmissionregistrationV1beta1().ValidatingWebhookConfigurations(),
wClient: client.AdmissionregistrationV1().MutatingWebhookConfigurations(),
vClient: client.AdmissionregistrationV1().ValidatingWebhookConfigurations(),
nClient: client.CoreV1().Namespaces(),
context: context.Background(),
}
Expand All @@ -56,8 +57,8 @@ type Resource struct {
}

// Run
//args[0]: self executable
//args[1]: may be 'webhookname' or '--kubeconfig'
// args[0]: self executable
// args[1]: may be 'webhookname' or '--kubeconfig'
func (w *WebHookClient) Run(args []string) (*printer.PrintModel, error) {
var items []printer.PrintItem

Expand Down Expand Up @@ -86,7 +87,7 @@ func (w *WebHookClient) Run(args []string) (*printer.PrintModel, error) {
}, nil
}

func (w *WebHookClient) fillMutatingWebhookConfigurations(mwc v1beta1.MutatingWebhookConfiguration, items *[]printer.PrintItem) {
func (w *WebHookClient) fillMutatingWebhookConfigurations(mwc v1.MutatingWebhookConfiguration, items *[]printer.PrintItem) {
item := printer.PrintItem{
Kind: "Mutating",
Name: mwc.Name, //TODO: typeMeta nil
Expand Down Expand Up @@ -114,7 +115,7 @@ func (w *WebHookClient) fillMutatingWebhookConfigurations(mwc v1beta1.MutatingWe
*items = append(*items, item)
}
}
func (w *WebHookClient) fillValidatingWebhookConfigurations(mwc v1beta1.ValidatingWebhookConfiguration, items *[]printer.PrintItem) {
func (w *WebHookClient) fillValidatingWebhookConfigurations(mwc v1.ValidatingWebhookConfiguration, items *[]printer.PrintItem) {
item := printer.PrintItem{
Kind: "Validating",
Name: mwc.Name, //TODO: typeMeta nil
Expand Down Expand Up @@ -142,7 +143,7 @@ func (w *WebHookClient) fillValidatingWebhookConfigurations(mwc v1beta1.Validati
*items = append(*items, item)
}
}
func (w *WebHookClient) fillRulesForMutating(webhook v1beta1.MutatingWebhook) []printer.ResourceModel {
func (w *WebHookClient) fillRulesForMutating(webhook v1.MutatingWebhook) []printer.ResourceModel {
var resources []printer.ResourceModel

for _, rule := range webhook.Rules {
Expand All @@ -161,7 +162,7 @@ func (w *WebHookClient) fillRulesForMutating(webhook v1beta1.MutatingWebhook) []
}
return resources
}
func (w *WebHookClient) fillRulesForValidating(webhook v1beta1.ValidatingWebhook) []printer.ResourceModel {
func (w *WebHookClient) fillRulesForValidating(webhook v1.ValidatingWebhook) []printer.ResourceModel {
var resources []printer.ResourceModel
var ops, rs []string
for _, rule := range webhook.Rules {
Expand All @@ -179,7 +180,7 @@ func (w *WebHookClient) fillRulesForValidating(webhook v1beta1.ValidatingWebhook
}
return resources
}
func (w *WebHookClient) fillActiveNamespacesForMutating(webhook v1beta1.MutatingWebhook, activeNamespaces *[]string) {
func (w *WebHookClient) fillActiveNamespacesForMutating(webhook v1.MutatingWebhook, activeNamespaces *[]string) {
if webhook.NamespaceSelector != nil {
ncList, _ := w.nClient.List(w.context, metaV1.ListOptions{})

Expand All @@ -198,7 +199,7 @@ func (w *WebHookClient) fillActiveNamespacesForMutating(webhook v1beta1.Mutating
}
}
}
func (w *WebHookClient) fillActiveNamespacesForValidating(webhook v1beta1.ValidatingWebhook, activeNamespaces *[]string) {
func (w *WebHookClient) fillActiveNamespacesForValidating(webhook v1.ValidatingWebhook, activeNamespaces *[]string) {
if webhook.NamespaceSelector != nil {
ncList, _ := w.nClient.List(w.context, metaV1.ListOptions{})

Expand Down Expand Up @@ -250,8 +251,8 @@ func (w *WebHookClient) GenerateServiceItem(ns, name string, path *string, port
return result
}

//retrieveValidDateCount returns remaining time of the given
//webhook's CABundle certificate.
// retrieveValidDateCount returns remaining time of the given
// webhook's CABundle certificate.
func retrieveValidDateCount(certificate []byte) time.Duration {
if certificate == nil {
return 0
Expand Down