@@ -17,6 +17,7 @@ limitations under the License.
17
17
package dns
18
18
19
19
import (
20
+ "context"
20
21
"encoding/json"
21
22
"fmt"
22
23
"net"
@@ -58,7 +59,7 @@ const (
58
59
// DeployedDNSAddon returns the type of DNS addon currently deployed
59
60
func DeployedDNSAddon (client clientset.Interface ) (kubeadmapi.DNSAddOnType , string , error ) {
60
61
deploymentsClient := client .AppsV1 ().Deployments (metav1 .NamespaceSystem )
61
- deployments , err := deploymentsClient .List (metav1.ListOptions {LabelSelector : "k8s-app=kube-dns" })
62
+ deployments , err := deploymentsClient .List (context . TODO (), metav1.ListOptions {LabelSelector : "k8s-app=kube-dns" })
62
63
if err != nil {
63
64
return "" , "" , errors .Wrap (err , "couldn't retrieve DNS addon deployments" )
64
65
}
@@ -84,7 +85,7 @@ func DeployedDNSAddon(client clientset.Interface) (kubeadmapi.DNSAddOnType, stri
84
85
// deployedDNSReplicas returns the replica count for the current DNS deployment
85
86
func deployedDNSReplicas (client clientset.Interface , replicas int32 ) (* int32 , error ) {
86
87
deploymentsClient := client .AppsV1 ().Deployments (metav1 .NamespaceSystem )
87
- deployments , err := deploymentsClient .List (metav1.ListOptions {LabelSelector : "k8s-app=kube-dns" })
88
+ deployments , err := deploymentsClient .List (context . TODO (), metav1.ListOptions {LabelSelector : "k8s-app=kube-dns" })
88
89
if err != nil {
89
90
return & replicas , errors .Wrap (err , "couldn't retrieve DNS addon deployments" )
90
91
}
@@ -209,7 +210,7 @@ func coreDNSAddon(cfg *kubeadmapi.ClusterConfiguration, client clientset.Interfa
209
210
}
210
211
211
212
// Get the kube-dns ConfigMap for translation to equivalent CoreDNS Config.
212
- kubeDNSConfigMap , err := client .CoreV1 ().ConfigMaps (metav1 .NamespaceSystem ).Get (kubeadmconstants .KubeDNSConfigMap , metav1.GetOptions {})
213
+ kubeDNSConfigMap , err := client .CoreV1 ().ConfigMaps (metav1 .NamespaceSystem ).Get (context . TODO (), kubeadmconstants .KubeDNSConfigMap , metav1.GetOptions {})
213
214
if err != nil && ! apierrors .IsNotFound (err ) {
214
215
return err
215
216
}
@@ -346,15 +347,15 @@ func createDNSService(dnsService *v1.Service, serviceBytes []byte, client client
346
347
}
347
348
348
349
// Can't use a generic apiclient helper func here as we have to tolerate more than AlreadyExists.
349
- if _ , err := client .CoreV1 ().Services (metav1 .NamespaceSystem ).Create (dnsService ); err != nil {
350
+ if _ , err := client .CoreV1 ().Services (metav1 .NamespaceSystem ).Create (context . TODO (), dnsService ); err != nil {
350
351
// Ignore if the Service is invalid with this error message:
351
352
// Service "kube-dns" is invalid: spec.clusterIP: Invalid value: "10.96.0.10": provided IP is already allocated
352
353
353
354
if ! apierrors .IsAlreadyExists (err ) && ! apierrors .IsInvalid (err ) {
354
355
return errors .Wrap (err , "unable to create a new DNS service" )
355
356
}
356
357
357
- if _ , err := client .CoreV1 ().Services (metav1 .NamespaceSystem ).Update (dnsService ); err != nil {
358
+ if _ , err := client .CoreV1 ().Services (metav1 .NamespaceSystem ).Update (context . TODO (), dnsService ); err != nil {
358
359
return errors .Wrap (err , "unable to create/update the DNS service" )
359
360
}
360
361
}
@@ -373,7 +374,7 @@ func migrateCoreDNSCorefile(client clientset.Interface, cm *v1.ConfigMap, corefi
373
374
// Take a copy of the Corefile data as `Corefile-backup` and update the ConfigMap
374
375
// Also point the CoreDNS deployment to the `Corefile-backup` data.
375
376
376
- if _ , err := client .CoreV1 ().ConfigMaps (cm .ObjectMeta .Namespace ).Update (& v1.ConfigMap {
377
+ if _ , err := client .CoreV1 ().ConfigMaps (cm .ObjectMeta .Namespace ).Update (context . TODO (), & v1.ConfigMap {
377
378
ObjectMeta : metav1.ObjectMeta {
378
379
Name : kubeadmconstants .CoreDNSConfigMap ,
379
380
Namespace : metav1 .NamespaceSystem ,
@@ -395,7 +396,7 @@ func migrateCoreDNSCorefile(client clientset.Interface, cm *v1.ConfigMap, corefi
395
396
return errors .Wrap (err , "unable to migrate CoreDNS ConfigMap" )
396
397
}
397
398
398
- if _ , err := client .CoreV1 ().ConfigMaps (cm .ObjectMeta .Namespace ).Update (& v1.ConfigMap {
399
+ if _ , err := client .CoreV1 ().ConfigMaps (cm .ObjectMeta .Namespace ).Update (context . TODO (), & v1.ConfigMap {
399
400
ObjectMeta : metav1.ObjectMeta {
400
401
Name : kubeadmconstants .CoreDNSConfigMap ,
401
402
Namespace : metav1 .NamespaceSystem ,
@@ -424,7 +425,7 @@ func migrateCoreDNSCorefile(client clientset.Interface, cm *v1.ConfigMap, corefi
424
425
425
426
// GetCoreDNSInfo gets the current CoreDNS installed and the current Corefile Configuration of CoreDNS.
426
427
func GetCoreDNSInfo (client clientset.Interface ) (* v1.ConfigMap , string , string , error ) {
427
- coreDNSConfigMap , err := client .CoreV1 ().ConfigMaps (metav1 .NamespaceSystem ).Get (kubeadmconstants .CoreDNSConfigMap , metav1.GetOptions {})
428
+ coreDNSConfigMap , err := client .CoreV1 ().ConfigMaps (metav1 .NamespaceSystem ).Get (context . TODO (), kubeadmconstants .CoreDNSConfigMap , metav1.GetOptions {})
428
429
if err != nil && ! apierrors .IsNotFound (err ) {
429
430
return nil , "" , "" , err
430
431
}
@@ -445,13 +446,13 @@ func GetCoreDNSInfo(client clientset.Interface) (*v1.ConfigMap, string, string,
445
446
}
446
447
447
448
func patchCoreDNSDeployment (client clientset.Interface , coreDNSCorefileName string ) error {
448
- dnsDeployment , err := client .AppsV1 ().Deployments (metav1 .NamespaceSystem ).Get (kubeadmconstants .CoreDNSDeploymentName , metav1.GetOptions {})
449
+ dnsDeployment , err := client .AppsV1 ().Deployments (metav1 .NamespaceSystem ).Get (context . TODO (), kubeadmconstants .CoreDNSDeploymentName , metav1.GetOptions {})
449
450
if err != nil {
450
451
return err
451
452
}
452
453
patch := fmt .Sprintf (`{"spec":{"template":{"spec":{"volumes":[{"name": "config-volume", "configMap":{"name": "coredns", "items":[{"key": "%s", "path": "%s"}]}}]}}}}` , coreDNSCorefileName , coreDNSCorefileName )
453
454
454
- if _ , err := client .AppsV1 ().Deployments (dnsDeployment .ObjectMeta .Namespace ).Patch (dnsDeployment .Name , types .StrategicMergePatchType , []byte (patch )); err != nil {
455
+ if _ , err := client .AppsV1 ().Deployments (dnsDeployment .ObjectMeta .Namespace ).Patch (context . TODO (), dnsDeployment .Name , types .StrategicMergePatchType , []byte (patch )); err != nil {
455
456
return errors .Wrap (err , "unable to patch the CoreDNS deployment" )
456
457
}
457
458
return nil
0 commit comments