Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add serviceport var to CRD #63

Merged
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
13 changes: 12 additions & 1 deletion api/v1/nodefeaturediscovery_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,26 @@ type NodeFeatureDiscoverySpec struct {

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

// Image defines the image to pull for the
// NFD operand
// [defaults to k8s.gcr.io/nfd/node-feature-discovery]
// +kubebuilder:validation:Pattern=[a-zA-Z0-9\-]+
Image string `json:"image,omitempty"`

// Image pull policy
// ImagePullPolicy defines Image pull policy for the
// NFD operand image [defaults to Always]
// +kubebuilder:validation:Optional
ImagePullPolicy string `json:"imagePullPolicy,omitempty"`

// ServicePort specifies the TCP port that nfd-master
// listens for incoming requests.
// +kubebuilder:validation:Optional
ServicePort int `json:"servicePort"`
}

// ConfigMap describes configuration options for the NFD worker
Expand Down
2 changes: 1 addition & 1 deletion build/assets/master/0400_master_daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
fieldPath: spec.nodeName
image: $(NODE_FEATURE_DISCOVERY_IMAGE)
name: nfd-master
command: ["nfd-master", "--port=12000"]
command: ["nfd-master"]
securityContext:
readOnlyRootFilesystem: true
allowPrivilegeEscalation: false
Expand Down
11 changes: 10 additions & 1 deletion config/crd/bases/nfd.kubernetes.io_nodefeaturediscoveries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,23 @@ spec:
description: OperandSpec describes configuration options for the operand
properties:
image:
description: Image defines the image to pull for the NFD operand
[defaults to k8s.gcr.io/nfd/node-feature-discovery]
pattern: '[a-zA-Z0-9\-]+'
type: string
imagePullPolicy:
description: Image pull policy
description: ImagePullPolicy defines Image pull policy for the
NFD operand image [defaults to Always]
type: string
namespace:
description: Namespace defines the namespace to deploy nfd-master
and nfd-worker pods
pattern: '[a-zA-Z0-9\.\-\/]+'
type: string
servicePort:
description: ServicePort specifies the TCP port that nfd-master
listens for incoming requests.
type: integer
type: object
workerConfig:
description: ConfigMap describes configuration options for the NFD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ spec:
namespace: node-feature-discovery-operator
image: gcr.io/k8s-staging-nfd/node-feature-discovery:master
imagePullPolicy: Always
servicePort: 12000
workerConfig:
configData: |
#core:
Expand Down
23 changes: 23 additions & 0 deletions controllers/nodefeaturediscovery_controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ package controllers

import (
"context"
"fmt"

secv1 "github.com/openshift/api/security/v1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)

Expand All @@ -35,6 +37,8 @@ type ResourceStatus int
const (
Ready ResourceStatus = iota
NotReady

defaultServicePort int = 12000
)

func (s ResourceStatus) String() string {
Expand Down Expand Up @@ -305,6 +309,16 @@ func DaemonSet(n NFD) (ResourceStatus, error) {
obj.Spec.Template.Spec.Containers[0].ImagePullPolicy = n.ins.Spec.Operand.ImagePolicy(n.ins.Spec.Operand.ImagePullPolicy)
}

// update nfd-master service port
if obj.ObjectMeta.Name == "nfd-master" {
port := defaultServicePort
if n.ins.Spec.Operand.ServicePort != 0 {
port = n.ins.Spec.Operand.ServicePort
}
portFlag := fmt.Sprintf("--port=%d", port)
obj.Spec.Template.Spec.Containers[0].Args = []string{portFlag}
}

obj.SetNamespace(n.ins.GetNamespace())

found := &appsv1.DaemonSet{}
Expand Down Expand Up @@ -343,6 +357,15 @@ func Service(n NFD) (ResourceStatus, error) {
state := n.idx
obj := n.resources[state].Service

// update ports
if n.ins.Spec.Operand.ServicePort != 0 {
obj.Spec.Ports[0].Port = int32(n.ins.Spec.Operand.ServicePort)
obj.Spec.Ports[0].TargetPort = intstr.FromInt(n.ins.Spec.Operand.ServicePort)
} else {
obj.Spec.Ports[0].Port = int32(defaultServicePort)
obj.Spec.Ports[0].TargetPort = intstr.FromInt(defaultServicePort)
}

obj.SetNamespace(n.ins.GetNamespace())

found := &corev1.Service{}
Expand Down