Skip to content
Merged
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
130 changes: 130 additions & 0 deletions cmd/manage-crds/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
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 main

import (
"context"
"fmt"
"os"

"github.com/NVIDIA/k8s-operator-libs/pkg/crdutil"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"

"github.com/NVIDIA/gpu-operator/internal/info"
)

var logger = log.New()

type config struct {
Debug bool
crdsPaths *cli.StringSlice
}

func main() {
config := config{
crdsPaths: cli.NewStringSlice(),
}

// Create the top-level CLI
c := cli.NewApp()
c.Name = "manage-crds"
c.Usage = "Tools for managing Custom Resource Definitions (CRDs) for NVIDIA GPU Operator"
c.Version = info.GetVersionString()

// Setup the flags for this command
c.Flags = []cli.Flag{
&cli.BoolFlag{
Name: "debug",
Aliases: []string{"d"},
Usage: "Enable debug-level logging",
Destination: &config.Debug,
EnvVars: []string{"DEBUG"},
},
}

// Set log-level for all subcommands
c.Before = func(c *cli.Context) error {
logLevel := log.InfoLevel
if config.Debug {
logLevel = log.DebugLevel
}
logger.SetLevel(logLevel)
return nil
}

// Common flags for both apply and delete subcommands
commonFlags := []cli.Flag{
&cli.StringSliceFlag{
Name: "filepath",
Aliases: []string{"f"},
Usage: "Path to CRD manifest file or directory (can be specified multiple times, directories are searched recursively)",
Required: true,
Destination: config.crdsPaths,
},
}

// Define the subcommands
c.Commands = []*cli.Command{
{
Name: "apply",
Usage: "Apply CRDs from the specified path",
Flags: commonFlags,
Action: func(c *cli.Context) error {
return runApply(c.Context, config)
},
},
{
Name: "delete",
Usage: "Delete CRDs from the specified path",
Flags: commonFlags,
Action: func(c *cli.Context) error {
return runDelete(c.Context, config)
},
},
}

err := c.Run(os.Args)
if err != nil {
log.Errorf("%v", err)
log.Exit(1)
}
}

func runApply(ctx context.Context, cfg config) error {
paths := cfg.crdsPaths.Value()
logger.Infof("Applying CRDs from %d path(s): %v", len(paths), paths)

if err := crdutil.ProcessCRDs(ctx, crdutil.CRDOperationApply, paths...); err != nil {
return fmt.Errorf("failed to apply CRDs: %w", err)
}

logger.Info("Successfully applied CRDs")
return nil
}

func runDelete(ctx context.Context, cfg config) error {
paths := cfg.crdsPaths.Value()
logger.Infof("Deleting CRDs from %d path(s): %v", len(paths), paths)

if err := crdutil.ProcessCRDs(ctx, crdutil.CRDOperationDelete, paths...); err != nil {
return fmt.Errorf("failed to delete CRDs: %w", err)
}

logger.Info("Successfully deleted CRDs")
return nil
}
19 changes: 8 additions & 11 deletions deployments/gpu-operator/templates/cleanup_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,13 @@ spec:
image: {{ include "gpu-operator.fullimage" . }}
imagePullPolicy: {{ .Values.operator.imagePullPolicy }}
command:
- sh
- -c
- >
kubectl delete clusterpolicy cluster-policy;
kubectl delete crd clusterpolicies.nvidia.com;
kubectl delete crd nvidiadrivers.nvidia.com --ignore-not-found=true;
{{- if .Values.nfd.enabled -}}
kubectl delete crd nodefeatures.nfd.k8s-sigs.io --ignore-not-found=true;
kubectl delete crd nodefeaturegroups.nfd.k8s-sigs.io --ignore-not-found=true;
kubectl delete crd nodefeaturerules.nfd.k8s-sigs.io --ignore-not-found=true;
{{- end }}
- /usr/bin/manage-crds
args:
- delete
- --filepath=/opt/gpu-operator/nvidia.com_clusterpolicies.yaml
- --filepath=/opt/gpu-operator/nvidia.com_nvidiadrivers.yaml
{{- if .Values.nfd.enabled }}
- --filepath=/opt/gpu-operator/nfd-api-crds.yaml;
{{- end }}
restartPolicy: OnFailure
{{- end }}
12 changes: 6 additions & 6 deletions deployments/gpu-operator/templates/upgrade_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ spec:
image: {{ include "gpu-operator.fullimage" . }}
imagePullPolicy: {{ .Values.operator.imagePullPolicy }}
command:
- sh
- -c
- >
kubectl apply -f /opt/gpu-operator/nvidia.com_clusterpolicies.yaml;
kubectl apply -f /opt/gpu-operator/nvidia.com_nvidiadrivers.yaml;
- /usr/bin/manage-crds
args:
- apply
- --filepath=/opt/gpu-operator/nvidia.com_clusterpolicies.yaml
- --filepath=/opt/gpu-operator/nvidia.com_nvidiadrivers.yaml
{{- if .Values.nfd.enabled }}
kubectl apply -f /opt/gpu-operator/nfd-api-crds.yaml;
- --filepath=/opt/gpu-operator/nfd-api-crds.yaml
{{- end }}
restartPolicy: OnFailure
{{- end }}
8 changes: 1 addition & 7 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ RUN dnf install -y --allowerasing \

WORKDIR /workspace

# Install must-gather dependency: `kubectl`
ARG TARGETARCH
RUN OS_ARCH=${TARGETARCH/x86_64/amd64} && OS_ARCH=${OS_ARCH/aarch64/arm64} && \
curl -LO https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/${OS_ARCH}/kubectl && \
chmod +x ./kubectl

FROM nvcr.io/nvidia/cuda:12.9.1-base-ubi9 AS sample-builder

RUN dnf install -y --allowerasing \
Expand Down Expand Up @@ -96,7 +90,7 @@ LABEL vsc-ref=${GIT_COMMIT}

WORKDIR /
COPY --from=builder /workspace/gpu-operator /usr/bin/
COPY --from=cuda-base /workspace/kubectl /usr/bin/
COPY --from=builder /workspace/manage-crds /usr/bin/
COPY --from=builder /workspace/nvidia-validator /usr/bin/
COPY --from=sample-builder /build/vectorAdd /usr/bin/vectorAdd
# TODO: Copy the compat libs from the 'sample-builder' image instead.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/Masterminds/sprig/v3 v3.3.0
github.com/NVIDIA/go-nvlib v0.8.1
github.com/NVIDIA/k8s-kata-manager v0.2.3
github.com/NVIDIA/k8s-operator-libs v0.0.0-20250709180754-c80af13d73e3
github.com/NVIDIA/k8s-operator-libs v0.0.0-20251027171627-45ccd0c3dd32
github.com/NVIDIA/nvidia-container-toolkit v1.18.0
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/go-logr/logr v1.4.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ github.com/NVIDIA/go-nvlib v0.8.1 h1:OPEHVvn3zcV5OXB68A7WRpeCnYMRSPl7LdeJH/d3gZI
github.com/NVIDIA/go-nvlib v0.8.1/go.mod h1:7mzx9FSdO9fXWP9NKuZmWkCwhkEcSWQFe2tmFwtLb9c=
github.com/NVIDIA/k8s-kata-manager v0.2.3 h1:d5+gRFqU5el/fKMXhHUaPY7haj+dbHL4nDsO/q05LBo=
github.com/NVIDIA/k8s-kata-manager v0.2.3/go.mod h1:xx5OUiMsHyKbyX0JjKHqAftvqS8vx00LFn/5EaMdtB4=
github.com/NVIDIA/k8s-operator-libs v0.0.0-20250709180754-c80af13d73e3 h1:vGT+oyUY7kOGLd71Cz0NfRVEep23jdd4fi+PYsZEj88=
github.com/NVIDIA/k8s-operator-libs v0.0.0-20250709180754-c80af13d73e3/go.mod h1:0GPZJRwr6nY1IVhGUyzG9YfKhNFQq8UlhYe4u7jVF0U=
github.com/NVIDIA/k8s-operator-libs v0.0.0-20251027171627-45ccd0c3dd32 h1:TWudaaTt7QwN/cQwPOm1wgesGLOc8hoik9GubKgnph0=
github.com/NVIDIA/k8s-operator-libs v0.0.0-20251027171627-45ccd0c3dd32/go.mod h1:WbVhWGKqRcwjRKj8MYsYJas73G1YdU3oLW5ggDvTWXs=
github.com/NVIDIA/nvidia-container-toolkit v1.18.0 h1:bXoKq9C1WHU5fF6VqXvX3RkMzpp4ihTUgBPrh66vTf0=
github.com/NVIDIA/nvidia-container-toolkit v1.18.0/go.mod h1:ZxWSG7fnFo2Z7xSGtMyZVF7WnTbj1lgx4dMrBLUq90g=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading