@@ -41,9 +41,9 @@ import (
4141 "github.com/arangodb/kube-arangodb/pkg/util/kclient"
4242 "github.com/pkg/errors"
4343 "github.com/spf13/cobra"
44- corev1 "k8s.io/api/core/v1"
44+ core "k8s.io/api/core/v1"
4545 "k8s.io/apimachinery/pkg/api/resource"
46- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
46+ meta "k8s.io/apimachinery/pkg/apis/meta/v1"
4747 "k8s.io/apimachinery/pkg/fields"
4848 "k8s.io/client-go/kubernetes"
4949)
@@ -103,91 +103,91 @@ func runVolumeInspector(ctx context.Context, kube kubernetes.Interface, ns, name
103103
104104 deletePVC := true
105105 claimname := "arangodb-reboot-pvc-" + name
106- pvcspec := corev1 .PersistentVolumeClaim {
107- ObjectMeta : metav1 .ObjectMeta {
106+ pvcspec := core .PersistentVolumeClaim {
107+ ObjectMeta : meta .ObjectMeta {
108108 Name : claimname ,
109109 Labels : map [string ]string {
110110 "app" : "arangodb" ,
111111 "rebooted" : "yes" ,
112112 },
113113 },
114- Spec : corev1 .PersistentVolumeClaimSpec {
115- AccessModes : []corev1 .PersistentVolumeAccessMode {corev1 .ReadWriteOnce },
114+ Spec : core .PersistentVolumeClaimSpec {
115+ AccessModes : []core .PersistentVolumeAccessMode {core .ReadWriteOnce },
116116 VolumeName : name ,
117- Resources : corev1 .ResourceRequirements {
118- Requests : corev1 .ResourceList {
119- corev1 .ResourceStorage : * resource .NewQuantity (1024 * 1024 * 1024 , resource .DecimalSI ),
117+ Resources : core .ResourceRequirements {
118+ Requests : core .ResourceList {
119+ core .ResourceStorage : * resource .NewQuantity (1024 * 1024 * 1024 , resource .DecimalSI ),
120120 },
121121 },
122122 StorageClassName : util .NewString (storageClassName ),
123123 },
124124 }
125125
126- _ , err := kube .CoreV1 ().PersistentVolumeClaims (ns ).Create (context .Background (), & pvcspec , metav1 .CreateOptions {})
126+ _ , err := kube .CoreV1 ().PersistentVolumeClaims (ns ).Create (context .Background (), & pvcspec , meta .CreateOptions {})
127127 if err != nil {
128128 return "" , "" , errors .Wrap (err , "failed to create pvc" )
129129 }
130130 defer func () {
131131 if deletePVC {
132132 logger .Str ("pvc-name" , claimname ).Debug ("deleting pvc" )
133- kube .CoreV1 ().PersistentVolumeClaims (ns ).Delete (context .Background (), claimname , metav1 .DeleteOptions {})
133+ kube .CoreV1 ().PersistentVolumeClaims (ns ).Delete (context .Background (), claimname , meta .DeleteOptions {})
134134 }
135135 }()
136136
137137 podname := "arangodb-reboot-pod-" + name
138- podspec := corev1 .Pod {
139- ObjectMeta : metav1 .ObjectMeta {
138+ podspec := core .Pod {
139+ ObjectMeta : meta .ObjectMeta {
140140 Name : podname ,
141141 },
142- Spec : corev1 .PodSpec {
143- RestartPolicy : corev1 .RestartPolicyNever ,
144- Containers : []corev1 .Container {
145- corev1 .Container {
142+ Spec : core .PodSpec {
143+ RestartPolicy : core .RestartPolicyNever ,
144+ Containers : []core .Container {
145+ core .Container {
146146 Name : "inspector" ,
147147 Image : image ,
148- ImagePullPolicy : corev1 .PullAlways ,
148+ ImagePullPolicy : core .PullAlways ,
149149 Command : []string {"arangodb_operator" },
150150 Args : []string {"reboot" , "inspect" },
151- Env : []corev1 .EnvVar {
152- corev1 .EnvVar {
151+ Env : []core .EnvVar {
152+ core .EnvVar {
153153 Name : constants .EnvOperatorPodNamespace ,
154154 Value : ns ,
155155 },
156156 },
157- VolumeMounts : []corev1 .VolumeMount {
158- corev1 .VolumeMount {
157+ VolumeMounts : []core .VolumeMount {
158+ core .VolumeMount {
159159 MountPath : "/data" ,
160160 Name : "data" ,
161161 },
162162 },
163- Ports : []corev1 .ContainerPort {
164- corev1 .ContainerPort {
163+ Ports : []core .ContainerPort {
164+ core .ContainerPort {
165165 ContainerPort : 8080 ,
166166 },
167167 },
168- ReadinessProbe : & corev1 .Probe {
169- Handler : corev1 .Handler {
170- HTTPGet : & corev1 .HTTPGetAction {
168+ ReadinessProbe : & core .Probe {
169+ Handler : core .Handler {
170+ HTTPGet : & core .HTTPGetAction {
171171 Path : "/info" ,
172172 Port : intstr .FromInt (8080 ),
173173 },
174174 },
175175 },
176176 },
177177 },
178- Volumes : []corev1 .Volume {
178+ Volumes : []core .Volume {
179179 k8sutil .CreateVolumeWithPersitantVolumeClaim ("data" , claimname ),
180180 },
181181 },
182182 }
183183
184- _ , err = kube .CoreV1 ().Pods (ns ).Create (context .Background (), & podspec , metav1 .CreateOptions {})
184+ _ , err = kube .CoreV1 ().Pods (ns ).Create (context .Background (), & podspec , meta .CreateOptions {})
185185 if err != nil {
186186 return "" , "" , errors .Wrap (err , "failed to create pod" )
187187 }
188- defer kube .CoreV1 ().Pods (ns ).Delete (context .Background (), podname , metav1 .DeleteOptions {})
188+ defer kube .CoreV1 ().Pods (ns ).Delete (context .Background (), podname , meta .DeleteOptions {})
189189
190- podwatch , err := kube .CoreV1 ().Pods (ns ).Watch (context .Background (), metav1 .ListOptions {FieldSelector : fields .OneTermEqualSelector ("metadata.name" , podname ).String ()})
190+ podwatch , err := kube .CoreV1 ().Pods (ns ).Watch (context .Background (), meta .ListOptions {FieldSelector : fields .OneTermEqualSelector ("metadata.name" , podname ).String ()})
191191 if err != nil {
192192 return "" , "" , errors .Wrap (err , "failed to watch for pod" )
193193 }
@@ -204,18 +204,18 @@ func runVolumeInspector(ctx context.Context, kube kubernetes.Interface, ns, name
204204 }
205205
206206 // get the pod
207- pod , ok := ev .Object .(* corev1 .Pod )
207+ pod , ok := ev .Object .(* core .Pod )
208208 if ! ok {
209209 return "" , "" , fmt .Errorf ("failed to get pod" )
210210 }
211211
212212 switch pod .Status .Phase {
213- case corev1 .PodFailed :
213+ case core .PodFailed :
214214 return "" , "" , fmt .Errorf ("pod failed: %s" , pod .Status .Reason )
215- case corev1 .PodRunning :
215+ case core .PodRunning :
216216 podReady := false
217217 for _ , c := range pod .Status .Conditions {
218- if c .Type == corev1 .PodReady && c .Status == corev1 .ConditionTrue {
218+ if c .Type == core .PodReady && c .Status == core .ConditionTrue {
219219 podReady = true
220220 }
221221 }
@@ -264,22 +264,22 @@ func doVolumeInspection(ctx context.Context, kube kubernetes.Interface, ns, name
264264}
265265
266266func checkVolumeAvailable (kube kubernetes.Interface , vname string ) (VolumeInfo , error ) {
267- volume , err := kube .CoreV1 ().PersistentVolumes ().Get (context .Background (), vname , metav1 .GetOptions {})
267+ volume , err := kube .CoreV1 ().PersistentVolumes ().Get (context .Background (), vname , meta .GetOptions {})
268268 if err != nil {
269269 return VolumeInfo {}, errors .Wrapf (err , "failed to GET volume %s" , vname )
270270 }
271271
272272 switch volume .Status .Phase {
273- case corev1 .VolumeAvailable :
273+ case core .VolumeAvailable :
274274 break
275- case corev1 .VolumeReleased :
275+ case core .VolumeReleased :
276276 // we have to remove the claim reference
277277 volume .Spec .ClaimRef = nil
278- if _ , err := kube .CoreV1 ().PersistentVolumes ().Update (context .Background (), volume , metav1 .UpdateOptions {}); err != nil {
278+ if _ , err := kube .CoreV1 ().PersistentVolumes ().Update (context .Background (), volume , meta .UpdateOptions {}); err != nil {
279279 return VolumeInfo {}, errors .Wrapf (err , "failed to remove claim reference" )
280280 }
281281 default :
282- return VolumeInfo {}, fmt .Errorf ("Volume %s phase is %s, expected %s" , vname , volume .Status .Phase , corev1 .VolumeAvailable )
282+ return VolumeInfo {}, fmt .Errorf ("Volume %s phase is %s, expected %s" , vname , volume .Status .Phase , core .VolumeAvailable )
283283 }
284284
285285 return VolumeInfo {StorageClassName : volume .Spec .StorageClassName }, nil
@@ -306,7 +306,7 @@ func preflightChecks(kube kubernetes.Interface, volumes []string) (VolumeListInf
306306}
307307
308308func getMyImage (kube kubernetes.Interface , ns , name string ) (string , error ) {
309- pod , err := kube .CoreV1 ().Pods (ns ).Get (context .Background (), name , metav1 .GetOptions {})
309+ pod , err := kube .CoreV1 ().Pods (ns ).Get (context .Background (), name , meta .GetOptions {})
310310 if err != nil {
311311 return "" , err
312312 }
@@ -330,7 +330,7 @@ func createArangoDeployment(cli acli.Interface, ns, deplname, arangoimage string
330330 }
331331
332332 depl := deplv1.ArangoDeployment {
333- ObjectMeta : metav1 .ObjectMeta {
333+ ObjectMeta : meta .ObjectMeta {
334334 Name : deplname ,
335335 },
336336 Spec : deplv1.DeploymentSpec {
@@ -367,7 +367,7 @@ func createArangoDeployment(cli acli.Interface, ns, deplname, arangoimage string
367367 })
368368 }
369369
370- if _ , err := cli .DatabaseV1 ().ArangoDeployments (ns ).Create (context .Background (), & depl , metav1 .CreateOptions {}); err != nil {
370+ if _ , err := cli .DatabaseV1 ().ArangoDeployments (ns ).Create (context .Background (), & depl , meta .CreateOptions {}); err != nil {
371371 return errors .Wrap (err , "failed to create ArangoDeployment" )
372372 }
373373
0 commit comments