Skip to content

Commit

Permalink
Merge branch 'controller-gen-code' into 'main'
Browse files Browse the repository at this point in the history
Generate boilerplate code using controller-gen

See merge request nvidia/cloud-native/k8s-kata-manager!17
  • Loading branch information
cdesiniotis committed Jun 20, 2023
2 parents d0b6efa + 36378c8 commit 08b57fe
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 6 deletions.
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ CMDS := $(patsubst ./cmd/%/,%,$(sort $(dir $(wildcard ./cmd/*/))))
CMD_TARGETS := $(patsubst %,cmd-%, $(CMDS))

CHECK_TARGETS := assert-fmt vet lint ineffassign misspell
MAKE_TARGETS := cmds build install fmt test coverage $(CHECK_TARGETS)
MAKE_TARGETS := cmds build install fmt test coverage generate $(CHECK_TARGETS)

TARGETS := $(MAKE_TARGETS)
DOCKER_TARGETS := $(pathsubst %, docker-%, $(TARGETS))
Expand Down Expand Up @@ -121,6 +121,16 @@ coverage: test
cat $(COVERAGE_FILE) | grep -v "_mock.go" > $(COVERAGE_FILE).no-mocks
$(GO_CMD) tool cover -func=$(COVERAGE_FILE).no-mocks

# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object object:headerFile="hack/boilerplate.go.txt" paths="./api/..."

# Download controller-gen locally if necessary
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
CONTROLLER_GEN = $(PROJECT_DIR)/bin/controller-gen
controller-gen:
@GOBIN=$(PROJECT_DIR)/bin GO111MODULE=on $(GO_CMD) install sigs.k8s.io/controller-tools/cmd/[email protected]

##### Devel image build and push targets #####
.PHONY: .build-image .pull-build-image .push-build-image
BUILDIMAGE ?= k8s-kata-manager-devel
Expand Down
39 changes: 34 additions & 5 deletions api/v1alpha1/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,51 @@

package config

import "k8s.io/klog/v2"
import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/klog/v2"
)

// Config defines the configuration for the kata-manager
// +kubebuilder:object:root=true
// +kubebuilder:object:generate=true
type Config struct {
ArtifactsDir string `json:"artifactsDir,omitempty" yaml:"artifactsDir,omitempty"`
// ArtifactsDir is the directory where kata artifacts (e.g. kernel / guest images, configuration, etc.)
// are placed on the local filesystem.
// +kubebuilder:default=/opt/nvidia-gpu-operator/artifacts/runtimeclasses
ArtifactsDir string `json:"artifactsDir,omitempty" yaml:"artifactsDir,omitempty"`

// RuntimeClasses is a list of kata runtime classes to configure.
// +optional
RuntimeClasses []RuntimeClass `json:"runtimeClasses,omitempty" yaml:"runtimeClasses,omitempty"`
}

// RuntimeClass defines the configuration for a kata RuntimeClass
// +kubebuilder:object:generate=true
type RuntimeClass struct {
Name string `json:"name" yaml:"name"`
// Name is the name of the kata runtime class.
Name string `json:"name" yaml:"name"`

// NodeSelector specifies the nodeSelector for the RuntimeClass object.
// This ensures pods running with the RuntimeClass only get scheduled
// onto nodes which support it.
// +optional
NodeSelector map[string]string `json:"nodeSelector,omitempty" yaml:"nodeSelector,omitempty"`
Artifacts Artifacts `json:"artifacts" yaml:"artifacts"`

// Artifacts are the kata artifacts associated with the runtime class.
Artifacts Artifacts `json:"artifacts" yaml:"artifacts"`
}

// Artifacts defines the path to an OCI artifact (payload) containing all artifacts
// associated with a kata RuntimeClass (e.g. kernel, guest image, initrd, kata configuration)
// +kubebuilder:object:generate=true
type Artifacts struct {
URL string `json:"url" yaml:"url"`
// URL is the path to the OCI artifact (payload) containing all artifacts
// associated with a kata runtime class.
URL string `json:"url" yaml:"url"`

// PullSecret is the secret used to pull the OCI artifact.
// +optional
PullSecret string `json:"pullSecret,omitempty" yaml:"pullSecret,omitempty"`
}

Expand All @@ -45,6 +71,9 @@ func NewDefaultConfig() *Config {
}
}

// GetObjectKind
func (c *Config) GetObjectKind() schema.ObjectKind { return nil }

// SanitizeConfig sanitizes the config struct and removes any invalid runtime class entries
func SanitizeConfig(c *Config) {
i := 0
Expand Down
94 changes: 94 additions & 0 deletions api/v1alpha1/config/zz_generated.deepcopy.go

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

15 changes: 15 additions & 0 deletions hack/boilerplate.go.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
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.
*/

0 comments on commit 08b57fe

Please sign in to comment.