Skip to content

Commit

Permalink
add openshift namespace to the controller-runtime cache
Browse files Browse the repository at this point in the history
Signed-off-by: Tariq Ibrahim <[email protected]>
  • Loading branch information
tariq1890 committed Aug 2, 2024
1 parent f3b69bf commit 8f285ab
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions cmd/gpu-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (
nvidiav1alpha1 "github.com/NVIDIA/gpu-operator/api/nvidia/v1alpha1"
"github.com/NVIDIA/gpu-operator/controllers"
"github.com/NVIDIA/gpu-operator/controllers/clusterinfo"
"github.com/NVIDIA/gpu-operator/internal/consts"
"github.com/NVIDIA/gpu-operator/internal/info"
// +kubebuilder:scaffold:imports
)
Expand Down Expand Up @@ -106,9 +107,12 @@ func main() {
})

operatorNamespace := os.Getenv("OPERATOR_NAMESPACE")
openshiftNamespace := consts.OpenshiftNamespace
cacheOptions := cache.Options{
DefaultNamespaces: map[string]cache.Config{
operatorNamespace: {},
// Also cache resources in the openshift namespace to retrieve ImageStreams when on an openshift cluster
openshiftNamespace: {},
},
}

Expand Down
2 changes: 1 addition & 1 deletion controllers/clusterinfo/clusterinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func getOpenshiftDTKImages(ctx context.Context, c *rest.Config) map[string]strin
logger := log.FromContext(ctx)

name := "driver-toolkit"
namespace := "openshift"
namespace := consts.OpenshiftNamespace

ocpImageClient, err := imagesv1.NewForConfig(c)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion controllers/object_controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import (
"sigs.k8s.io/yaml"

gpuv1 "github.com/NVIDIA/gpu-operator/api/nvidia/v1"
"github.com/NVIDIA/gpu-operator/internal/consts"
"github.com/NVIDIA/gpu-operator/internal/utils"
)

Expand Down Expand Up @@ -3705,7 +3706,7 @@ func ocpHasDriverToolkitImageStream(n *ClusterPolicyController) (bool, error) {
ctx := n.ctx
found := &apiimagev1.ImageStream{}
name := "driver-toolkit"
namespace := "openshift"
namespace := consts.OpenshiftNamespace
err := n.client.Get(ctx, types.NamespacedName{Namespace: namespace, Name: name}, found)
if err != nil {
if apierrors.IsNotFound(err) {
Expand Down
3 changes: 3 additions & 0 deletions internal/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ const (
// Containerd runtime
Containerd = "containerd"

// OpenshiftNamespace indicates the main namespace of an Openshift cluster
OpenshiftNamespace = "openshift"

OcpDriverToolkitVersionLabel = "openshift.driver-toolkit.rhcos"
OcpDriverToolkitIdentificationLabel = "openshift.driver-toolkit"
NfdOSTreeVersionLabelKey = "feature.node.kubernetes.io/system-os_release.OSTREE_VERSION"
Expand Down

0 comments on commit 8f285ab

Please sign in to comment.