@@ -3,8 +3,9 @@ package kube
3
3
import (
4
4
"bytes"
5
5
"context"
6
+
6
7
"github.com/pkg/errors"
7
- log "github.com/sirupsen/logrus"
8
+ "github.com/sirupsen/logrus"
8
9
v1 "k8s.io/api/core/v1"
9
10
networkingv1 "k8s.io/api/networking/v1"
10
11
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -22,7 +23,7 @@ type Kubernetes struct {
22
23
}
23
24
24
25
func NewKubernetesForContext (context string ) (* Kubernetes , error ) {
25
- log .Debugf ("instantiating k8s Clientset for context %s" , context )
26
+ logrus .Debugf ("instantiating k8s Clientset for context %s" , context )
26
27
kubeConfig , err := clientcmd .NewNonInteractiveDeferredLoadingClientConfig (
27
28
clientcmd .NewDefaultClientConfigLoadingRules (),
28
29
& clientcmd.ConfigOverrides {CurrentContext : context }).ClientConfig ()
@@ -70,13 +71,13 @@ func (k *Kubernetes) CreateNamespace(ns *v1.Namespace) (*v1.Namespace, error) {
70
71
}
71
72
72
73
func (k * Kubernetes ) DeleteAllNetworkPoliciesInNamespace (ns string ) error {
73
- log .Debugf ("deleting all network policies in namespace %s" , ns )
74
+ logrus .Debugf ("deleting all network policies in namespace %s" , ns )
74
75
netpols , err := k .ClientSet .NetworkingV1 ().NetworkPolicies (ns ).List (context .TODO (), metav1.ListOptions {})
75
76
if err != nil {
76
77
return errors .Wrapf (err , "unable to list network policies in ns %s" , ns )
77
78
}
78
79
for _ , np := range netpols .Items {
79
- log .Debugf ("deleting network policy %s/%s" , ns , np .Name )
80
+ logrus .Debugf ("deleting network policy %s/%s" , ns , np .Name )
80
81
err = k .DeleteNetworkPolicy (np .Namespace , np .Name )
81
82
if err != nil {
82
83
return err
@@ -99,13 +100,13 @@ func (k *Kubernetes) GetNetworkPoliciesInNamespace(namespace string) ([]networki
99
100
}
100
101
101
102
func (k * Kubernetes ) UpdateNetworkPolicy (policy * networkingv1.NetworkPolicy ) (* networkingv1.NetworkPolicy , error ) {
102
- log .Debugf ("updating network policy %s/%s" , policy .Namespace , policy .Name )
103
+ logrus .Debugf ("updating network policy %s/%s" , policy .Namespace , policy .Name )
103
104
np , err := k .ClientSet .NetworkingV1 ().NetworkPolicies (policy .Namespace ).Update (context .TODO (), policy , metav1.UpdateOptions {})
104
105
return np , errors .Wrapf (err , "unable to update network policy %s/%s" , policy .Namespace , policy .Name )
105
106
}
106
107
107
108
func (k * Kubernetes ) CreateNetworkPolicy (policy * networkingv1.NetworkPolicy ) (* networkingv1.NetworkPolicy , error ) {
108
- log .Debugf ("creating network policy %s/%s" , policy .Namespace , policy .Name )
109
+ logrus .Debugf ("creating network policy %s/%s" , policy .Namespace , policy .Name )
109
110
110
111
createdPolicy , err := k .ClientSet .NetworkingV1 ().NetworkPolicies (policy .Namespace ).Create (context .TODO (), policy , metav1.CreateOptions {})
111
112
return createdPolicy , errors .Wrapf (err , "unable to create network policy %s/%s" , policy .Namespace , policy .Name )
@@ -118,7 +119,7 @@ func (k *Kubernetes) GetService(namespace string, name string) (*v1.Service, err
118
119
119
120
func (k * Kubernetes ) CreateService (svc * v1.Service ) (* v1.Service , error ) {
120
121
ns := svc .Namespace
121
- log .Debugf ("creating service %s/%s" , ns , svc .Name )
122
+ logrus .Debugf ("creating service %s/%s" , ns , svc .Name )
122
123
createdService , err := k .ClientSet .CoreV1 ().Services (ns ).Create (context .TODO (), svc , metav1.CreateOptions {})
123
124
if err != nil {
124
125
return nil , errors .Wrapf (err , "unable to create service %s/%s" , ns , svc .Name )
@@ -127,7 +128,7 @@ func (k *Kubernetes) CreateService(svc *v1.Service) (*v1.Service, error) {
127
128
}
128
129
129
130
func (k * Kubernetes ) DeleteService (namespace string , name string ) error {
130
- log .Debugf ("deleting service %s/%s" , namespace , name )
131
+ logrus .Debugf ("deleting service %s/%s" , namespace , name )
131
132
err := k .ClientSet .CoreV1 ().Services (namespace ).Delete (context .TODO (), name , metav1.DeleteOptions {})
132
133
return errors .Wrapf (err , "unable to delete service %s/%s" , namespace , name )
133
134
}
@@ -165,14 +166,14 @@ func (k *Kubernetes) SetPodLabels(namespace string, podName string, labels map[s
165
166
166
167
func (k * Kubernetes ) CreatePod (pod * v1.Pod ) (* v1.Pod , error ) {
167
168
ns := pod .Namespace
168
- log .Debugf ("creating pod %s/%s" , ns , pod .Name )
169
+ logrus .Debugf ("creating pod %s/%s" , ns , pod .Name )
169
170
170
171
createdPod , err := k .ClientSet .CoreV1 ().Pods (ns ).Create (context .TODO (), pod , metav1.CreateOptions {})
171
172
return createdPod , errors .Wrapf (err , "unable to create pod %s/%s" , ns , pod .Name )
172
173
}
173
174
174
175
func (k * Kubernetes ) DeletePod (namespace string , podName string ) error {
175
- log .Debugf ("deleting pod %s/%s" , namespace , podName )
176
+ logrus .Debugf ("deleting pod %s/%s" , namespace , podName )
176
177
err := k .ClientSet .CoreV1 ().Pods (namespace ).Delete (context .TODO (), podName , metav1.DeleteOptions {})
177
178
return errors .Wrapf (err , "unable to delete pod %s/%s" , namespace , podName )
178
179
}
0 commit comments