Skip to content

Commit

Permalink
Merge pull request #1876 from njhale/fix-ioob
Browse files Browse the repository at this point in the history
Bug 1899835: fix(catalog): be defensive about directly indexing catalog pods
  • Loading branch information
openshift-merge-robot committed Nov 26, 2020
2 parents 3cb2cfd + 926cae9 commit 62c86d3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
21 changes: 13 additions & 8 deletions pkg/controller/registry/reconciler/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import (
"hash/fnv"
"time"

controllerclient "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/controller-runtime/client"

"github.com/operator-framework/api/pkg/operators/v1alpha1"
hashutil "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/kubernetes/pkg/util/hash"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorlister"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/rand"

"github.com/operator-framework/api/pkg/operators/v1alpha1"
controllerclient "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/controller-runtime/client"
hashutil "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/kubernetes/pkg/util/hash"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorlister"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
)

const (
Expand Down Expand Up @@ -349,9 +349,14 @@ func imageChanged(updatePod *corev1.Pod, servingPods []*corev1.Pod) bool {
return false
}

// imageID returns the ImageID of the primary catalog source container.
// imageID returns the ImageID of the primary catalog source container or an empty string if the image ID isn't available yet.
// Note: the pod must be running and the container in a ready status to return a valid ImageID.
func imageID(pod *corev1.Pod) string {
if len(pod.Status.ContainerStatuses) < 1 {
logrus.WithField("CatalogSource", pod.GetName()).Warn("pod status unknown")
return ""
}

return pod.Status.ContainerStatuses[0].ImageID
}

Expand Down
13 changes: 13 additions & 0 deletions pkg/controller/registry/reconciler/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,19 @@ func TestGetPodImageID(t *testing.T) {
pod: &corev1.Pod{Status: corev1.PodStatus{ContainerStatuses: []corev1.ContainerStatus{{ImageID: "xyz123"}}}},
result: "xyz123",
},
{
description: "pod has two containers: return first",
pod: &corev1.Pod{Status: corev1.PodStatus{ContainerStatuses: []corev1.ContainerStatus{
{ImageID: "xyz123"},
{ImageID: "abc456"},
}}},
result: "xyz123",
},
{
description: "pod has no status",
pod: &corev1.Pod{Status: corev1.PodStatus{}},
result: "",
},
}

for i, tt := range table {
Expand Down

0 comments on commit 62c86d3

Please sign in to comment.