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

Signed-off-by: Carlos Eduardo Arango Gutierrez <carangog@redhat.com>
  • Loading branch information
ArangoGutierrez committed Nov 19, 2020
1 parent ad82d0f commit 6ef0a3b
Show file tree
Hide file tree
Showing 16 changed files with 444 additions and 109 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ require (
github.com/go-logr/logr v0.3.0
github.com/go-logr/zapr v0.3.0
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
Expand Down
227 changes: 227 additions & 0 deletions go.sum

Large diffs are not rendered by default.

91 changes: 63 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,65 @@ 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
- repository
- version
properties:
image:
pattern: '[a-zA-Z0-9\-]+'
type: string
repository:
pattern: '[a-zA-Z0-9\-]+'
type: string
version:
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
24 changes: 21 additions & 3 deletions manifests/0700_cr.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
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: node-feature-discovery
repository: k8s.gcr.io/nfd
version: v0.6.0
imagePullPolicy: Always
nfd-worker:
config: |
#sources:
# pci:
# deviceClassWhitelist:
# - "0200"
# - "03"
# - "12"
# deviceLabelFields:
# - "class"
# - "vendor"
# - "device"
# - "subsystem_vendor"
# - "subsystem_device"
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
95 changes: 95 additions & 0 deletions pkg/apis/nfd/v1/nodefeaturediscovery_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
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 {
Operand OperandSpec `json:"operand"`
Config ConfigSpec `json:"nfd-worker"`
}

// 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\.\-\/]+
Repository string `json:"repository,omitempty"`

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

// +kubebuilder:validation:Pattern=[a-zA-Z0-9\.-]+
Version string `json:"version,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
BinaryData string `json:"config"`
}

// NodeFeatureDiscoveryStatus defines the observed state of NodeFeatureDiscovery
// +k8s:openapi-gen=true
type NodeFeatureDiscoveryStatus struct{}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// NodeFeatureDiscovery is the Schema for the nodefeaturediscoveries API
// +k8s:openapi-gen=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:path=nodefeaturediscoveries,scope=Namespaced
type NodeFeatureDiscovery struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec NodeFeatureDiscoverySpec `json:"spec,omitempty"`
Status NodeFeatureDiscoveryStatus `json:"status,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// NodeFeatureDiscoveryList contains a list of NodeFeatureDiscovery
type NodeFeatureDiscoveryList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []NodeFeatureDiscovery `json:"items"`
}

func init() {
SchemeBuilder.Register(&NodeFeatureDiscovery{}, &NodeFeatureDiscoveryList{})
}

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

// ImagePolicy returns a valid corev1.PullPolicy from the string in the CR
func (o *OperandSpec) ImagePolicy(pullPolicy string) corev1.PullPolicy {
var imagePullPolicy corev1.PullPolicy
switch pullPolicy {
case "Always":
imagePullPolicy = corev1.PullAlways
case "Never":
imagePullPolicy = corev1.PullNever
case "IfNotPresent":
imagePullPolicy = corev1.PullIfNotPresent
default:
imagePullPolicy = corev1.PullIfNotPresent
}
return imagePullPolicy
}

// Data returns a valid ConfigMap name
func (c *ConfigSpec) Data() string {
return c.BinaryData
}
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.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// This file was autogenerated by openapi-gen. Do not edit it manually!

package v1alpha1
package v1

import (
spec "github.com/go-openapi/spec"
Expand All @@ -11,13 +11,13 @@ import (

func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition {
return map[string]common.OpenAPIDefinition{
"./pkg/apis/nfd/v1alpha1.NodeFeatureDiscovery": schema_pkg_apis_nfd_v1alpha1_NodeFeatureDiscovery(ref),
"./pkg/apis/nfd/v1alpha1.NodeFeatureDiscoverySpec": schema_pkg_apis_nfd_v1alpha1_NodeFeatureDiscoverySpec(ref),
"./pkg/apis/nfd/v1alpha1.NodeFeatureDiscoveryStatus": schema_pkg_apis_nfd_v1alpha1_NodeFeatureDiscoveryStatus(ref),
"./pkg/apis/nfd/v1.NodeFeatureDiscovery": schema_pkg_apis_nfd_v1_NodeFeatureDiscovery(ref),
"./pkg/apis/nfd/v1.NodeFeatureDiscoverySpec": schema_pkg_apis_nfd_v1_NodeFeatureDiscoverySpec(ref),
"./pkg/apis/nfd/v1.NodeFeatureDiscoveryStatus": schema_pkg_apis_nfd_v1_NodeFeatureDiscoveryStatus(ref),
}
}

func schema_pkg_apis_nfd_v1alpha1_NodeFeatureDiscovery(ref common.ReferenceCallback) common.OpenAPIDefinition {
func schema_pkg_apis_nfd_v1_NodeFeatureDiscovery(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Expand Down Expand Up @@ -45,23 +45,23 @@ func schema_pkg_apis_nfd_v1alpha1_NodeFeatureDiscovery(ref common.ReferenceCallb
},
"spec": {
SchemaProps: spec.SchemaProps{
Ref: ref("./pkg/apis/nfd/v1alpha1.NodeFeatureDiscoverySpec"),
Ref: ref("./pkg/apis/nfd/v1.NodeFeatureDiscoverySpec"),
},
},
"status": {
SchemaProps: spec.SchemaProps{
Ref: ref("./pkg/apis/nfd/v1alpha1.NodeFeatureDiscoveryStatus"),
Ref: ref("./pkg/apis/nfd/v1.NodeFeatureDiscoveryStatus"),
},
},
},
},
},
Dependencies: []string{
"./pkg/apis/nfd/v1alpha1.NodeFeatureDiscoverySpec", "./pkg/apis/nfd/v1alpha1.NodeFeatureDiscoveryStatus", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"},
"./pkg/apis/nfd/v1.NodeFeatureDiscoverySpec", "./pkg/apis/nfd/v1.NodeFeatureDiscoveryStatus", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"},
}
}

func schema_pkg_apis_nfd_v1alpha1_NodeFeatureDiscoverySpec(ref common.ReferenceCallback) common.OpenAPIDefinition {
func schema_pkg_apis_nfd_v1_NodeFeatureDiscoverySpec(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Expand All @@ -72,7 +72,7 @@ func schema_pkg_apis_nfd_v1alpha1_NodeFeatureDiscoverySpec(ref common.ReferenceC
}
}

func schema_pkg_apis_nfd_v1alpha1_NodeFeatureDiscoveryStatus(ref common.ReferenceCallback) common.OpenAPIDefinition {
func schema_pkg_apis_nfd_v1_NodeFeatureDiscoveryStatus(ref common.ReferenceCallback) common.OpenAPIDefinition {
return common.OpenAPIDefinition{
Schema: spec.Schema{
SchemaProps: spec.SchemaProps{
Expand Down
4 changes: 0 additions & 4 deletions pkg/apis/nfd/v1alpha1/doc.go

This file was deleted.

Loading

0 comments on commit 6ef0a3b

Please sign in to comment.