Skip to content

Commit

Permalink
Improve consistency
Browse files Browse the repository at this point in the history
- tweak log and error messages
- use versioned APIs
- `ClientSet()` each time, as otherwise it breaks testability with current
  implementation of `*FakeRawClient.ClientSet()`.
  • Loading branch information
errordeveloper committed Mar 14, 2019
1 parent 72c4a2d commit 750f6fd
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
4 changes: 2 additions & 2 deletions pkg/addons/default/aws_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ const (

// UpdateAWSNode will update the `aws-node` add-on
func UpdateAWSNode(rawClient kubernetes.RawClientInterface, region string) error {
_, err := rawClient.ClientSet().Apps().DaemonSets(metav1.NamespaceSystem).Get(AWSNode, metav1.GetOptions{})
_, err := rawClient.ClientSet().AppsV1().DaemonSets(metav1.NamespaceSystem).Get(AWSNode, metav1.GetOptions{})
if err != nil {
if apierrs.IsNotFound(err) {
logger.Warning("%q was not found", AWSNode)
return nil
}
return errors.Wrapf(err, "getting %s", AWSNode)
return errors.Wrapf(err, "getting %q", AWSNode)
}

// if DaemonSets is present, go through our list of assets
Expand Down
15 changes: 6 additions & 9 deletions pkg/addons/default/coredns.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ const (

// InstallCoreDNS will install the `coredns` add-on in place of `kube-dns`
func InstallCoreDNS(rawClient kubernetes.RawClientInterface, region string, waitTimeout *time.Duration) error {
coreClient := rawClient.ClientSet().CoreV1()
deploymentsClient := rawClient.ClientSet().AppsV1().Deployments(metav1.NamespaceSystem)

kubeDNSSevice, err := coreClient.Services(metav1.NamespaceSystem).Get(KubeDNS, metav1.GetOptions{})
kubeDNSSevice, err := rawClient.ClientSet().CoreV1().Services(metav1.NamespaceSystem).Get(KubeDNS, metav1.GetOptions{})
if err != nil {
if apierrs.IsNotFound(err) {
logger.Warning("%q service was not found", KubeDNS)
Expand All @@ -45,7 +42,7 @@ func InstallCoreDNS(rawClient kubernetes.RawClientInterface, region string, wait
return errors.Wrapf(err, "getting %q service", KubeDNS)
}

kubeDNSDeployment, err := deploymentsClient.Get(KubeDNS, metav1.GetOptions{})
kubeDNSDeployment, err := rawClient.ClientSet().AppsV1().Deployments(metav1.NamespaceSystem).Get(KubeDNS, metav1.GetOptions{})
if err != nil {
if apierrs.IsNotFound(err) {
logger.Warning("%q deployment was not found", KubeDNS)
Expand All @@ -57,7 +54,7 @@ func InstallCoreDNS(rawClient kubernetes.RawClientInterface, region string, wait
if v, ok := kubeDNSDeployment.Spec.Selector.MatchLabels[componentLabel]; !ok || v != KubeDNS {
logger.Debug("adding %q label to %q", componentLabel, KubeDNS)
kubeDNSDeployment.Spec.Selector.MatchLabels[componentLabel] = KubeDNS
if _, err := deploymentsClient.Update(kubeDNSDeployment); err != nil {
if _, err := rawClient.ClientSet().AppsV1().Deployments(metav1.NamespaceSystem).Update(kubeDNSDeployment); err != nil {
return errors.Wrapf(err, "patching %q", KubeDNS)
}
}
Expand Down Expand Up @@ -106,12 +103,12 @@ func InstallCoreDNS(rawClient kubernetes.RawClientInterface, region string, wait
timer := time.After(*waitTimeout)
timeout := false
readyPods := sets.NewString()
watcher, err := coreClient.Pods(metav1.NamespaceSystem).Watch(listPodsOptions)
watcher, err := rawClient.ClientSet().CoreV1().Pods(metav1.NamespaceSystem).Watch(listPodsOptions)
if err != nil {
return errors.Wrapf(err, "creating %q pod watcher", CoreDNS)
}

podList, err := coreClient.Pods(metav1.NamespaceSystem).List(listPodsOptions)
podList, err := rawClient.ClientSet().CoreV1().Pods(metav1.NamespaceSystem).List(listPodsOptions)
if err != nil {
return errors.Wrapf(err, "listing %q pods", CoreDNS)
}
Expand Down Expand Up @@ -147,7 +144,7 @@ func InstallCoreDNS(rawClient kubernetes.RawClientInterface, region string, wait
}
}

if err := deploymentsClient.Delete(KubeDNS, &metav1.DeleteOptions{}); err != nil {
if err := rawClient.ClientSet().AppsV1().Deployments(metav1.NamespaceSystem).Delete(KubeDNS, &metav1.DeleteOptions{}); err != nil {
return errors.Wrapf(err, "deleting %q", KubeDNS)
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/addons/default/kube_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ const (
func UpdateKubeProxyImageTag(clientSet kubernetes.Interface, controlPlaneVersion string, dryRun bool) error {
printer := printers.NewJSONPrinter()

d, err := clientSet.Apps().DaemonSets(metav1.NamespaceSystem).Get(KubeProxy, metav1.GetOptions{})
d, err := clientSet.AppsV1().DaemonSets(metav1.NamespaceSystem).Get(KubeProxy, metav1.GetOptions{})
if err != nil {
if apierrs.IsNotFound(err) {
logger.Warning("%q was not found", KubeProxy)
return nil
}
return errors.Wrapf(err, "getting %s", KubeProxy)
return errors.Wrapf(err, "getting %q", KubeProxy)
}
if numContainers := len(d.Spec.Template.Spec.Containers); !(numContainers >= 1) {
return fmt.Errorf("%s has %d containers, expected at least 1", KubeProxy, numContainers)
Expand Down Expand Up @@ -65,7 +65,7 @@ func UpdateKubeProxyImageTag(clientSet kubernetes.Interface, controlPlaneVersion
if err := printer.LogObj(logger.Debug, KubeProxy+" [updated] = \\\n%s\n", d); err != nil {
return err
}
if _, err := clientSet.Apps().DaemonSets(metav1.NamespaceSystem).Update(d); err != nil {
if _, err := clientSet.AppsV1().DaemonSets(metav1.NamespaceSystem).Update(d); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/ctl/utils/update_aws_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ func doUpdateAWSNode(p *api.ProviderConfig, cfg *api.ClusterConfig, nameArg stri
return err
}

return defaultaddons.UpdateAWSNode(rawClient, p.Region)
return defaultaddons.UpdateAWSNode(rawClient, meta.Region)
}

0 comments on commit 750f6fd

Please sign in to comment.