Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion cmd/gpuop-cfg/validate/clusterpolicy/clusterpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ import (
"io"
"os"

"log/slog"

"github.com/regclient/regclient"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v3"
"sigs.k8s.io/yaml"

v1 "github.com/NVIDIA/gpu-operator/api/nvidia/v1"
"github.com/NVIDIA/gpu-operator/cmd/gpuop-cfg/validate/registry"
)

type command struct {
Expand Down Expand Up @@ -83,7 +87,13 @@ func (m command) run(ctx context.Context, opts *options) error {
return fmt.Errorf("failed to load clusterpolicy spec: %v", err)
}

err = validateImages(ctx, &cp.Spec)
var rcOpts []regclient.Opt
if m.logger.GetLevel() >= logrus.DebugLevel {
rcOpts = append(rcOpts, regclient.WithSlog(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelDebug}))))
}
client := registry.NewClient(rcOpts...)

err = validateImages(ctx, &cp.Spec, client)
if err != nil {
return fmt.Errorf("failed to validate images: %v", err)
}
Expand Down
27 changes: 13 additions & 14 deletions cmd/gpuop-cfg/validate/clusterpolicy/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
v1 "github.com/NVIDIA/gpu-operator/api/nvidia/v1"
)

func validateImages(ctx context.Context, spec *v1.ClusterPolicySpec) error {
func validateImages(ctx context.Context, spec *v1.ClusterPolicySpec, client *regclient.RegClient) error {
// Driver
path, err := v1.ImagePath(&spec.Driver)
if err != nil {
Expand All @@ -35,7 +35,7 @@ func validateImages(ctx context.Context, spec *v1.ClusterPolicySpec) error {
// For driver, we must append the os-tag
path += "-ubuntu22.04"

err = validateImage(ctx, path)
err = validateImage(ctx, client, path)
if err != nil {
return fmt.Errorf("failed to validate image %s: %v", path, err)
}
Expand All @@ -46,7 +46,7 @@ func validateImages(ctx context.Context, spec *v1.ClusterPolicySpec) error {
return fmt.Errorf("failed to construct the image path: %v", err)
}

err = validateImage(ctx, path)
err = validateImage(ctx, client, path)
if err != nil {
return fmt.Errorf("failed to validate image %s: %v", path, err)
}
Expand All @@ -57,7 +57,7 @@ func validateImages(ctx context.Context, spec *v1.ClusterPolicySpec) error {
return fmt.Errorf("failed to construct the image path: %v", err)
}

err = validateImage(ctx, path)
err = validateImage(ctx, client, path)
if err != nil {
return fmt.Errorf("failed to validate image %s: %v", path, err)
}
Expand All @@ -68,7 +68,7 @@ func validateImages(ctx context.Context, spec *v1.ClusterPolicySpec) error {
return fmt.Errorf("failed to construct the image path: %v", err)
}

err = validateImage(ctx, path)
err = validateImage(ctx, client, path)
if err != nil {
return fmt.Errorf("failed to validate image %s: %v", path, err)
}
Expand All @@ -79,7 +79,7 @@ func validateImages(ctx context.Context, spec *v1.ClusterPolicySpec) error {
return fmt.Errorf("failed to construct the image path: %v", err)
}

err = validateImage(ctx, path)
err = validateImage(ctx, client, path)
if err != nil {
return fmt.Errorf("failed to validate image %s: %v", path, err)
}
Expand All @@ -90,7 +90,7 @@ func validateImages(ctx context.Context, spec *v1.ClusterPolicySpec) error {
return fmt.Errorf("failed to construct the image path: %v", err)
}

err = validateImage(ctx, path)
err = validateImage(ctx, client, path)
if err != nil {
return fmt.Errorf("failed to validate image %s: %v", path, err)
}
Expand All @@ -101,7 +101,7 @@ func validateImages(ctx context.Context, spec *v1.ClusterPolicySpec) error {
return fmt.Errorf("failed to construct the image path: %v", err)
}

err = validateImage(ctx, path)
err = validateImage(ctx, client, path)
if err != nil {
return fmt.Errorf("failed to validate image %s: %v", path, err)
}
Expand All @@ -114,7 +114,7 @@ func validateImages(ctx context.Context, spec *v1.ClusterPolicySpec) error {
// For GDS driver, we must append the os-tag
path += "-ubuntu22.04"

err = validateImage(ctx, path)
err = validateImage(ctx, client, path)
if err != nil {
return fmt.Errorf("failed to validate image %s: %v", path, err)
}
Expand All @@ -125,7 +125,7 @@ func validateImages(ctx context.Context, spec *v1.ClusterPolicySpec) error {
return fmt.Errorf("failed to construct the image path: %v", err)
}

err = validateImage(ctx, path)
err = validateImage(ctx, client, path)
if err != nil {
return fmt.Errorf("failed to validate image %s: %v", path, err)
}
Expand All @@ -136,7 +136,7 @@ func validateImages(ctx context.Context, spec *v1.ClusterPolicySpec) error {
return fmt.Errorf("failed to construct the image path: %v", err)
}

err = validateImage(ctx, path)
err = validateImage(ctx, client, path)
if err != nil {
return fmt.Errorf("failed to validate image %s: %v", path, err)
}
Expand All @@ -147,16 +147,15 @@ func validateImages(ctx context.Context, spec *v1.ClusterPolicySpec) error {
return fmt.Errorf("failed to construct the image path: %v", err)
}

err = validateImage(ctx, path)
err = validateImage(ctx, client, path)
if err != nil {
return fmt.Errorf("failed to validate image %s: %v", path, err)
}

return nil
}

func validateImage(ctx context.Context, path string) error {
var client = regclient.New()
func validateImage(ctx context.Context, client *regclient.RegClient, path string) error {
ref, err := ref.New(path)
if err != nil {
return fmt.Errorf("failed to construct an image reference: %v", err)
Expand Down
12 changes: 11 additions & 1 deletion cmd/gpuop-cfg/validate/csv/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ import (
"context"
"fmt"
"io"
"log/slog"
"os"

"github.com/operator-framework/api/pkg/operators/v1alpha1"
"github.com/regclient/regclient"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v3"
"sigs.k8s.io/yaml"

"github.com/NVIDIA/gpu-operator/cmd/gpuop-cfg/validate/registry"
)

type command struct {
Expand Down Expand Up @@ -82,7 +86,13 @@ func (m command) run(ctx context.Context, opts *options) error {
return fmt.Errorf("failed to load csv yaml: %v", err)
}

err = validateImages(ctx, csv)
var rcOpts []regclient.Opt
if m.logger.GetLevel() >= logrus.DebugLevel {
rcOpts = append(rcOpts, regclient.WithSlog(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelDebug}))))
}
client := registry.NewClient(rcOpts...)

err = validateImages(ctx, csv, client)
if err != nil {
return fmt.Errorf("failed to validate images: %v", err)
}
Expand Down
11 changes: 5 additions & 6 deletions cmd/gpuop-cfg/validate/csv/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import (
"github.com/regclient/regclient/types/ref"
)

func validateImages(ctx context.Context, csv *v1alpha1.ClusterServiceVersion) error {
func validateImages(ctx context.Context, csv *v1alpha1.ClusterServiceVersion, client *regclient.RegClient) error {
// validate all 'relatedImages'
images := csv.Spec.RelatedImages
for _, image := range images {
err := validateImage(ctx, image.Image)
err := validateImage(ctx, client, image.Image)
if err != nil {
return fmt.Errorf("failed to validate image %s: %v", image.Name, err)
}
Expand All @@ -41,7 +41,7 @@ func validateImages(ctx context.Context, csv *v1alpha1.ClusterServiceVersion) er
ctr := deployment.Spec.Template.Spec.Containers[0]

// validate the gpu-operator image
err := validateImage(ctx, ctr.Image)
err := validateImage(ctx, client, ctr.Image)
if err != nil {
return fmt.Errorf("failed to validate image %s: %v", ctr.Image, err)
}
Expand All @@ -51,7 +51,7 @@ func validateImages(ctx context.Context, csv *v1alpha1.ClusterServiceVersion) er
if !strings.HasSuffix(env.Name, "_IMAGE") {
continue
}
err = validateImage(ctx, env.Value)
err = validateImage(ctx, client, env.Value)
if err != nil {
return fmt.Errorf("failed to validate image %s: %v", env.Name, err)
}
Expand All @@ -60,8 +60,7 @@ func validateImages(ctx context.Context, csv *v1alpha1.ClusterServiceVersion) er
return nil
}

func validateImage(ctx context.Context, path string) error {
var client = regclient.New()
func validateImage(ctx context.Context, client *regclient.RegClient, path string) error {
ref, err := ref.New(path)
if err != nil {
return fmt.Errorf("failed to construct an image reference: %v", err)
Expand Down
26 changes: 26 additions & 0 deletions cmd/gpuop-cfg/validate/registry/registry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
# Copyright (c), NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
**/

package registry

import (
"github.com/regclient/regclient"
)

// NewClient creates a regclient client with the provided options.
func NewClient(opts ...regclient.Opt) *regclient.RegClient {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this method at all?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could just call regclient.New(opts...) directly at the call site.

return regclient.New(opts...)
}
Loading