Skip to content

Commit

Permalink
resource should be nil if not found (#6756)
Browse files Browse the repository at this point in the history
  • Loading branch information
wind0r authored Jul 4, 2023
1 parent 38d294b commit 43f77ec
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions pkg/addons/default/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ func supportsMultiArch(podSec corev1.PodSpec) bool {
return false
}

func makeGetError(err error, resourceName string) error {
func makeGetError[T any](resource *T, err error, resourceName string) (*T, error) {
if err != nil {
if apierrors.IsNotFound(err) {
logger.Warning("%q was not found", resourceName)
return nil
return nil, nil
}
return fmt.Errorf("getting %q: %w", resourceName, err)
return nil, fmt.Errorf("getting %q: %w", resourceName, err)
}
return nil
return resource, nil
}

// LoadAsset return embedded manifest as a runtime.Object
Expand Down
2 changes: 1 addition & 1 deletion pkg/addons/default/aws_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,5 @@ func UpdateAWSNode(ctx context.Context, input AddonInput, plan bool) (bool, erro

func getAWSNode(ctx context.Context, clientSet kubernetes.Interface) (*appsv1.DaemonSet, error) {
d, err := clientSet.AppsV1().DaemonSets(metav1.NamespaceSystem).Get(ctx, AWSNode, metav1.GetOptions{})
return d, makeGetError(err, AWSNode)
return makeGetError(d, err, AWSNode)
}
2 changes: 1 addition & 1 deletion pkg/addons/default/coredns.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func UpdateCoreDNS(ctx context.Context, input AddonInput, plan bool) (bool, erro

func getCoreDNS(ctx context.Context, clientSet kubernetes.Interface) (*appsv1.Deployment, error) {
d, err := clientSet.AppsV1().Deployments(metav1.NamespaceSystem).Get(ctx, CoreDNS, metav1.GetOptions{})
return d, makeGetError(err, CoreDNS)
return makeGetError(d, err, CoreDNS)
}

func loadAssetCoreDNS(controlPlaneVersion string) (*metav1.List, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/addons/default/kube_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func UpdateKubeProxy(ctx context.Context, input AddonInput, plan bool) (bool, er

func getKubeProxy(ctx context.Context, clientSet kubernetes.Interface) (*v1.DaemonSet, error) {
d, err := clientSet.AppsV1().DaemonSets(metav1.NamespaceSystem).Get(ctx, KubeProxy, metav1.GetOptions{})
return d, makeGetError(err, KubeProxy)
return makeGetError(d, err, KubeProxy)
}

func addArm64NodeSelector(daemonSet *v1.DaemonSet) error {
Expand Down

0 comments on commit 43f77ec

Please sign in to comment.