Skip to content

Commit

Permalink
🧹 do not error out when running operator outside of the cluster
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev committed Apr 30, 2024
1 parent 37dd716 commit 4efd59a
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions pkg/utils/mondoo/container_image_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,18 @@ func (c *containerImageResolver) MondooOperatorImage(ctx context.Context, userIm
// If we have no user image or tag, we read the image from the operator pod
if userImage == "" || userTag == "" {
operatorPod := &corev1.Pod{}
if err := c.kubeClient.Get(ctx, client.ObjectKey{Namespace: c.operatorPodNamespace, Name: c.operatorPodName}, operatorPod); err != nil {
return "", err
}

for _, container := range operatorPod.Spec.Containers {
if container.Name == "manager" {
image = container.Image
break
if err := c.kubeClient.Get(ctx, client.ObjectKey{Namespace: c.operatorPodNamespace, Name: c.operatorPodName}, operatorPod); err == nil {
for _, container := range operatorPod.Spec.Containers {
if container.Name == "manager" {
image = container.Image
break
}
}
}

// If at this point we don't have an image, then something went wrong
if image == "" {
return "", fmt.Errorf("failed to get mondoo-operator image from operator pod")
// If at this point we don't have an image, then something went wrong
if image == "" {
return "", fmt.Errorf("failed to get mondoo-operator image from operator pod")
}
}
}

Expand Down

0 comments on commit 4efd59a

Please sign in to comment.