Skip to content

Commit 275d62e

Browse files
authored
OCPBUGS-31438: Correctly detect catalog image ID for extractContent catalog pods (#3194)
Signed-off-by: Joe Lanford <[email protected]>
1 parent e1db71e commit 275d62e

File tree

2 files changed

+38
-16
lines changed

2 files changed

+38
-16
lines changed

pkg/controller/registry/reconciler/grpc.go

+20-11
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@ import (
88

99
"github.com/google/go-cmp/cmp"
1010
"github.com/operator-framework/api/pkg/operators/v1alpha1"
11-
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
12-
controllerclient "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/controller-runtime/client"
13-
hashutil "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/kubernetes/pkg/util/hash"
14-
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
15-
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorlister"
16-
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
1711
"github.com/pkg/errors"
1812
"github.com/sirupsen/logrus"
1913
corev1 "k8s.io/api/core/v1"
2014
apierrors "k8s.io/apimachinery/pkg/api/errors"
2115
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2216
"k8s.io/apimachinery/pkg/labels"
2317
"k8s.io/apimachinery/pkg/util/intstr"
18+
19+
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
20+
controllerclient "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/controller-runtime/client"
21+
hashutil "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/kubernetes/pkg/util/hash"
22+
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
23+
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorlister"
24+
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
2425
)
2526

2627
const (
@@ -525,12 +526,20 @@ func imageChanged(logger *logrus.Entry, updatePod *corev1.Pod, servingPods []*co
525526
// imageID returns the ImageID of the primary catalog source container or an empty string if the image ID isn't available yet.
526527
// Note: the pod must be running and the container in a ready status to return a valid ImageID.
527528
func imageID(pod *corev1.Pod) string {
528-
if len(pod.Status.ContainerStatuses) < 1 {
529-
logrus.WithField("CatalogSource", pod.GetName()).Warn("pod status unknown")
530-
return ""
529+
if len(pod.Status.InitContainerStatuses) == 2 && len(pod.Status.ContainerStatuses) == 1 {
530+
// spec.grpcPodConfig.extractContent mode was used for this pod
531+
return pod.Status.InitContainerStatuses[1].ImageID
531532
}
532-
533-
return pod.Status.ContainerStatuses[0].ImageID
533+
if len(pod.Status.InitContainerStatuses) == 0 && len(pod.Status.ContainerStatuses) == 1 {
534+
// spec.grpcPodConfig.extractContent mode was NOT used for this pod (i.e. we're just running the catalog image directly)
535+
return pod.Status.ContainerStatuses[0].ImageID
536+
}
537+
if len(pod.Status.InitContainerStatuses) == 0 && len(pod.Status.ContainerStatuses) == 0 {
538+
logrus.WithField("CatalogSource", pod.GetName()).Warn("pod status unknown; pod has not yet populated initContainer and container status")
539+
} else {
540+
logrus.WithField("CatalogSource", pod.GetName()).Warn("pod status unknown; pod contains unexpected initContainer and container configuration")
541+
}
542+
return ""
534543
}
535544

536545
func (c *GrpcRegistryReconciler) removePods(pods []*corev1.Pod, namespace string) error {

pkg/controller/registry/reconciler/grpc_test.go

+18-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"time"
88

99
"github.com/google/go-cmp/cmp"
10-
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
10+
"github.com/operator-framework/api/pkg/operators/v1alpha1"
1111
"github.com/sirupsen/logrus"
1212
"github.com/stretchr/testify/require"
1313
corev1 "k8s.io/api/core/v1"
@@ -17,7 +17,7 @@ import (
1717
"k8s.io/apimachinery/pkg/runtime"
1818
"k8s.io/apimachinery/pkg/types"
1919

20-
"github.com/operator-framework/api/pkg/operators/v1alpha1"
20+
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
2121
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/clientfake"
2222
)
2323

@@ -640,17 +640,30 @@ func TestGetPodImageID(t *testing.T) {
640640
result string
641641
}{
642642
{
643-
description: "pod has status: return status",
643+
description: "default pod has status: return status",
644644
pod: &corev1.Pod{Status: corev1.PodStatus{ContainerStatuses: []corev1.ContainerStatus{{ImageID: "xyz123"}}}},
645645
result: "xyz123",
646646
},
647647
{
648-
description: "pod has two containers: return first",
648+
description: "extractConfig pod has status: return status",
649+
pod: &corev1.Pod{Status: corev1.PodStatus{
650+
InitContainerStatuses: []corev1.ContainerStatus{
651+
{ImageID: "xyz123"},
652+
{ImageID: "abc456"},
653+
},
654+
ContainerStatuses: []corev1.ContainerStatus{
655+
{ImageID: "xyz123"},
656+
},
657+
}},
658+
result: "abc456",
659+
},
660+
{
661+
description: "pod has unexpected container config",
649662
pod: &corev1.Pod{Status: corev1.PodStatus{ContainerStatuses: []corev1.ContainerStatus{
650663
{ImageID: "xyz123"},
651664
{ImageID: "abc456"},
652665
}}},
653-
result: "xyz123",
666+
result: "",
654667
},
655668
{
656669
description: "pod has no status",

0 commit comments

Comments
 (0)