Skip to content

Commit

Permalink
Expand nodeFeatureDiscovery CRD
Browse files Browse the repository at this point in the history
This Patch expands the nodeFeatureDiscovery CRD to enable users to
define the Operand image provenance regirsty/image:version as well as
the imaePullPolicy, that by default has been set to "Always"

Also now the nodeFeatureDiscovery CRD holds the binaryData for the
NFD-Worker configuration file, allowing users to define the desired
nfd-worker.conf by editing the CR.

To achieve this we move the api from v1alpha1 to v1 and extend the CRD
and the controller to watch for the updated resources.

extra: go mod tidy removed 2 non needed deps from go.mod

simplify ImagePolicy function pkg/apis/nfd/v1/nodefeaturediscovery_types.go  : ImagePolicy simplification

Document new changes to CRD

Signed-off-by: Carlos Eduardo Arango Gutierrez <carangog@redhat.com>
Co-authored-by: Markus Lehtonen <markus.lehtonen@intel.com>
  • Loading branch information
ArangoGutierrez and marquiz committed Dec 4, 2020
1 parent 094b23e commit 97bc00e
Show file tree
Hide file tree
Showing 16 changed files with 511 additions and 136 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ Alternatively, instead of specifying variables on the command line, you can edit

## Manual deploy of the operator

The default CR will create the operand (NFD) in the `node-feature-discovery-operator` namespace,
the CR can be edited to choose another namespace and image. See the `manifests/0700_cr.yaml` for the default values.
The default `NodeFeatureDiscovery` CR will create the operand (NFD) in the `node-feature-discovery-operator` namespace,
also an empty [nfd-worker-conf](https://kubernetes-sigs.github.io/node-feature-discovery/v0.6/get-started/deployment-and-usage.html#configuration),
the CR can be edited to choose another namespace, image, imagePullPolicy and nfd-worker-conf. See the `manifests/0700_cr.yaml` for the default values.

```bash
IMAGE_REGISTRY=<my registry>
Expand Down
10 changes: 3 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@ module github.com/kubernetes-sigs/node-feature-discovery-operator
go 1.15

require (
github.com/go-logr/logr v0.3.0
github.com/go-logr/zapr v0.3.0
github.com/go-logr/logr v0.3.0 // indirect
github.com/go-logr/zapr v0.3.0 // indirect
github.com/go-openapi/spec v0.19.3
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef // indirect
github.com/googleapis/gnostic v0.4.1
github.com/imdario/mergo v0.3.7 // indirect
github.com/openshift/api v0.0.0-20200116145750-0e2ff1e215dd
github.com/operator-framework/operator-sdk v0.4.1-0.20190129222657-43d37ce85826
golang.org/x/text v0.3.3 // indirect
// Kubernetes 1.19
k8s.io/api v0.19.0
k8s.io/apiextensions-apiserver v0.19.0 // indirect
k8s.io/apimachinery v0.19.0
k8s.io/client-go v0.19.0
k8s.io/klog/v2 v2.4.0
k8s.io/klog/v2 v2.4.0 // indirect
k8s.io/kube-openapi v0.0.0-20200805222855-6aeccd4b50c6 // kube-openapi release-1.9 branch
sigs.k8s.io/controller-runtime v0.6.3
)
Expand Down
335 changes: 275 additions & 60 deletions go.sum

Large diffs are not rendered by default.

83 changes: 55 additions & 28 deletions manifests/0500_crd.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
apiVersion: apiextensions.k8s.io/v1beta1
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations: #https://github.com/kubernetes/enhancements/pull/1111
"api-approved.kubernetes.io": "unapproved, experimental-only"
name: nodefeaturediscoveries.nfd.kubernetes.io
spec:
group: nfd.kubernetes.io
Expand All @@ -10,32 +12,57 @@ spec:
plural: nodefeaturediscoveries
singular: nodefeaturediscovery
scope: Namespaced
subresources:
status: {}
preserveUnknownFields: false
validation:
openAPIV3Schema:
description: 'The Node Feature Discovery operator manages detection of hardware features and configuration in a Kubernetes cluster. The operator orchestrates all resources needed to run the NFD DaemonSet (Upstream: https://github.com/kubernetes-sigs/node-feature-discovery)'
type: object
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
type: object
status:
type: object
version: v1alpha1
versions:
- name: v1alpha1
versions:
- name: v1
served: true
storage: true
storage: true
schema:
openAPIV3Schema:
description: 'The Node Feature Discovery operator manages detection of hardware features and configuration in a Kubernetes cluster. The operator orchestrates all resources needed to run the NFD DaemonSet (Upstream: https://github.com/kubernetes-sigs/node-feature-discovery)'
type: object
properties:
apiVersion:
type: string
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
kind:
type: string
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
metadata:
type: object
spec:
description: NodeFeatureDiscoverySpec defines the desired state of NodeFeatureDiscovery
type: object
required:
- operand
properties:
operand:
type: object
description: OperandSpec describes configuration options for the NFD operand
required:
- image
properties:
image:
pattern: '[a-zA-Z0-9\-]+'
type: string
imagePullPolicy:
description: Image pull policy
type: string
namespace:
pattern: '[a-zA-Z0-9\.\-\/]+'
type: string
nfd-worker:
description: NFD configuration files
type: object
required:
- config
properties:
config:
description: NFD Worker configuration file
type: string
status:
type: object
96 changes: 93 additions & 3 deletions manifests/0700_cr.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,98 @@
apiVersion: nfd.kubernetes.io/v1alpha1
apiVersion: nfd.kubernetes.io/v1
kind: NodeFeatureDiscovery
metadata:
name: nfd-master-server
namespace: REPLACE_NAMESPACE
spec:
namespace: node-feature-discovery-operator
image: k8s.gcr.io/nfd/node-feature-discovery:v0.6.0
operand:
namespace: node-feature-discovery-operator
image: k8s.gcr.io/nfdnode-feature-discovery:v0.6.0
imagePullPolicy: Always
workerConfig:
configData: |
#sources:
# cpu:
# cpuid:
## NOTE: whitelist has priority over blacklist
# attributeBlacklist:
# - "BMI1"
# - "BMI2"
# - "CLMUL"
# - "CMOV"
# - "CX16"
# - "ERMS"
# - "F16C"
# - "HTT"
# - "LZCNT"
# - "MMX"
# - "MMXEXT"
# - "NX"
# - "POPCNT"
# - "RDRAND"
# - "RDSEED"
# - "RDTSCP"
# - "SGX"
# - "SSE"
# - "SSE2"
# - "SSE3"
# - "SSE4.1"
# - "SSE4.2"
# - "SSSE3"
# attributeWhitelist:
# kernel:
# kconfigFile: "/path/to/kconfig"
# configOpts:
# - "NO_HZ"
# - "X86"
# - "DMI"
# pci:
# deviceClassWhitelist:
# - "0200"
# - "03"
# - "12"
# deviceLabelFields:
# - "class"
# - "vendor"
# - "device"
# - "subsystem_vendor"
# - "subsystem_device"
# usb:
# deviceClassWhitelist:
# - "0e"
# - "ef"
# - "fe"
# - "ff"
# deviceLabelFields:
# - "class"
# - "vendor"
# - "device"
# custom:
# - name: "my.kernel.feature"
# matchOn:
# - loadedKMod: ["example_kmod1", "example_kmod2"]
# - name: "my.pci.feature"
# matchOn:
# - pciId:
# class: ["0200"]
# vendor: ["15b3"]
# device: ["1014", "1017"]
# - pciId :
# vendor: ["8086"]
# device: ["1000", "1100"]
# - name: "my.usb.feature"
# matchOn:
# - usbId:
# class: ["ff"]
# vendor: ["03e7"]
# device: ["2485"]
# - usbId:
# class: ["fe"]
# vendor: ["1a6e"]
# device: ["089a"]
# - name: "my.combined.feature"
# matchOn:
# - pciId:
# vendor: ["15b3"]
# device: ["1014", "1017"]
# loadedKMod : ["vendor_kmod1", "vendor_kmod2"]

4 changes: 2 additions & 2 deletions pkg/apis/addtoscheme_nfd_v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ limitations under the License.
package apis

import (
"github.com/kubernetes-sigs/node-feature-discovery-operator/pkg/apis/nfd/v1alpha1"
v1 "github.com/kubernetes-sigs/node-feature-discovery-operator/pkg/apis/nfd/v1"
)

func init() {
// Register the types with the Scheme so the components can map objects to GroupVersionKinds and back
AddToSchemes = append(AddToSchemes, v1alpha1.SchemeBuilder.AddToScheme)
AddToSchemes = append(AddToSchemes, v1.SchemeBuilder.AddToScheme)
}
4 changes: 4 additions & 0 deletions pkg/apis/nfd/v1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Package v1 contains API Schema definitions for the nfd v1 API group
// +k8s:deepcopy-gen=package,register
// +groupName=nfd.kubernetes.io
package v1
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
package v1alpha1
package v1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// NodeFeatureDiscoverySpec defines the desired state of NodeFeatureDiscovery
// +k8s:openapi-gen=true
type NodeFeatureDiscoverySpec struct {
OperandNamespace string `json:"operandNamespace"`
OperandImage string `json:"operandImage"`
Operand OperandSpec `json:"operand"`
WorkerConfig ConfigSpec `json:"workerConfig"`
}

// OperandSpec describes configuration options for the operand
type OperandSpec struct {
// +kubebuilder:validation:Pattern=[a-zA-Z0-9\.\-\/]+
Namespace string `json:"namespace,omitempty"`

// +kubebuilder:validation:Pattern=[a-zA-Z0-9\-]+
Image string `json:"image,omitempty"`

// Image pull policy
// +kubebuilder:validation:Optional
ImagePullPolicy string `json:"imagePullPolicy,omitempty"`
}

// ConfigSpec describes configuration options for the NFD worker
type ConfigSpec struct {
// BinaryData holds the NFD configuration file
ConfigData string `json:"configData"`
}

// NodeFeatureDiscoveryStatus defines the observed state of NodeFeatureDiscovery
Expand Down Expand Up @@ -41,3 +61,24 @@ type NodeFeatureDiscoveryList struct {
func init() {
SchemeBuilder.Register(&NodeFeatureDiscovery{}, &NodeFeatureDiscoveryList{})
}

// ImagePath returns a compiled full valid image string
func (o *OperandSpec) ImagePath() string {
return o.Image
}

// ImagePolicy returns a valid corev1.PullPolicy from the string in the CR
func (o *OperandSpec) ImagePolicy(pullPolicy string) corev1.PullPolicy {
switch corev1.PullPolicy(pullPolicy) {
case corev1.PullAlways:
return corev1.PullAlways
case corev1.PullNever:
return corev1.PullNever
}
return corev1.PullIfNotPresent
}

// Data returns a valid ConfigMap name
func (c *ConfigSpec) Data() string {
return c.ConfigData
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// NOTE: Boilerplate only. Ignore this file.

// Package v1alpha1 contains API Schema definitions for the nfd v1alpha1 API group
// Package v1 contains API Schema definitions for the nfd v1 API group
// +k8s:deepcopy-gen=package,register
// +groupName=nfd.kubernetes.io
package v1alpha1
package v1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
Expand All @@ -12,7 +12,7 @@ import (

var (
// SchemeGroupVersion is group version used to register these objects
SchemeGroupVersion = schema.GroupVersion{Group: "nfd.kubernetes.io", Version: "v1alpha1"}
SchemeGroupVersion = schema.GroupVersion{Group: "nfd.kubernetes.io", Version: "v1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
Expand Down

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

Loading

0 comments on commit 97bc00e

Please sign in to comment.