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

Drop operand.namespace #115

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
5 changes: 0 additions & 5 deletions api/v1/nodefeaturediscovery_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ 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]
Expand Down
62 changes: 50 additions & 12 deletions config/crd/bases/nfd.kubernetes.io_nodefeaturediscoveries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ spec:
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.
Expand Down Expand Up @@ -105,26 +100,69 @@ spec:
description: Conditions represents the latest available observations
of current state.
items:
description: Condition represents the state of the operator's reconciliation
functionality.
description: "Condition contains details for one aspect of the current
state of this API Resource. --- This struct is intended for direct
use as an array at the field path .status.conditions. For example,
type FooStatus struct{ // Represents the observations of a
foo's current state. // Known .status.conditions.type are:
\"Available\", \"Progressing\", and \"Degraded\" // +patchMergeKey=type
\ // +patchStrategy=merge // +listType=map // +listMapKey=type
\ Conditions []metav1.Condition `json:\"conditions,omitempty\"
patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`
\n // other fields }"
properties:
lastHeartbeatTime:
format: date-time
type: string
lastTransitionTime:
description: lastTransitionTime is the last time the condition
transitioned from one status to another. This should be when
the underlying condition changed. If that is not known, then
using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: message is a human readable message indicating
details about the transition. This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
description: observedGeneration represents the .metadata.generation
that the condition was set based upon. For instance, if .metadata.generation
is currently 12, but the .status.conditions[x].observedGeneration
is 9, the condition is out of date with respect to the current
state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: reason contains a programmatic identifier indicating
the reason for the condition's last transition. Producers
of specific condition types may define expected values and
meanings for this field, and whether the values are considered
a guaranteed API. The value should be a CamelCase string.
This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: status of the condition, one of True, False, Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: ConditionType is the state of the operator's reconciliation
functionality.
description: type of condition in CamelCase or in foo.example.com/CamelCase.
--- Many .condition.type values are consistent across resources
like Available, but because arbitrary conditions can be useful
(see .node.status.conditions), the ability to deconflict is
important. The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ spec:
#resourceLabels:
# - "example.com/resource"
operand:
namespace: node-feature-discovery-operator
image: gcr.io/k8s-staging-nfd/node-feature-discovery:master
imagePullPolicy: Always
servicePort: 12000
Expand Down
18 changes: 9 additions & 9 deletions controllers/nodefeaturediscovery_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,49 +157,49 @@ func (r *NodeFeatureDiscoveryReconciler) Reconcile(ctx context.Context, req ctrl
}

// Check the status of the NFD Operator Worker ServiceAccount
if rstatus, err := r.getWorkerServiceAccountConditions(ctx); err != nil {
if rstatus, err := r.getWorkerServiceAccountConditions(ctx, instance); err != nil {
ArangoGutierrez marked this conversation as resolved.
Show resolved Hide resolved
return r.updateDegradedCondition(instance, conditionFailedGettingNFDWorkerServiceAccount, err.Error())
} else if rstatus.isDegraded {
return r.updateDegradedCondition(instance, conditionNFDWorkerServiceAccountDegraded, "nfd-worker service account has been degraded")
}

// Check the status of the NFD Operator Master ServiceAccount
if rstatus, err := r.getMasterServiceAccountConditions(ctx); err != nil {
if rstatus, err := r.getMasterServiceAccountConditions(ctx, instance); err != nil {
return r.updateDegradedCondition(instance, conditionFailedGettingNFDMasterServiceAccount, err.Error())
} else if rstatus.isDegraded {
return r.updateDegradedCondition(instance, conditionNFDMasterServiceAccountDegraded, "nfd-master service account has been degraded")
}

// Check the status of the NFD Operator role
if rstatus, err := r.getRoleConditions(ctx); err != nil {
if rstatus, err := r.getRoleConditions(ctx, instance); err != nil {
return r.updateDegradedCondition(instance, conditionNFDRoleDegraded, err.Error())
} else if rstatus.isDegraded {
return r.updateDegradedCondition(instance, conditionNFDRoleDegraded, "nfd-worker role has been degraded")
}

// Check the status of the NFD Operator cluster role
if rstatus, err := r.getClusterRoleConditions(ctx); err != nil {
if rstatus, err := r.getClusterRoleConditions(ctx, instance); err != nil {
return r.updateDegradedCondition(instance, conditionNFDClusterRoleDegraded, err.Error())
} else if rstatus.isDegraded {
return r.updateDegradedCondition(instance, conditionNFDClusterRoleDegraded, "nfd ClusterRole has been degraded")
}

// Check the status of the NFD Operator cluster role binding
if rstatus, err := r.getClusterRoleBindingConditions(ctx); err != nil {
if rstatus, err := r.getClusterRoleBindingConditions(ctx, instance); err != nil {
return r.updateDegradedCondition(instance, conditionFailedGettingNFDClusterRoleBinding, err.Error())
} else if rstatus.isDegraded {
return r.updateDegradedCondition(instance, conditionNFDClusterRoleBindingDegraded, "nfd ClusterRoleBinding has been degraded")
}

// Check the status of the NFD Operator role binding
if rstatus, err := r.getRoleBindingConditions(ctx); err != nil {
if rstatus, err := r.getRoleBindingConditions(ctx, instance); err != nil {
return r.updateDegradedCondition(instance, conditionFailedGettingNFDRoleBinding, err.Error())
} else if rstatus.isDegraded {
return r.updateDegradedCondition(instance, conditionNFDRoleBindingDegraded, "nfd RoleBinding has been degraded")
}

// Check the status of the NFD Operator Service
if rstatus, err := r.getServiceConditions(ctx); err != nil {
if rstatus, err := r.getServiceConditions(ctx, instance); err != nil {
return r.updateDegradedCondition(instance, conditionFailedGettingNFDService, err.Error())
} else if rstatus.isDegraded {
return r.updateDegradedCondition(instance, conditionNFDServiceDegraded, "nfd Service has been degraded")
Expand All @@ -213,7 +213,7 @@ func (r *NodeFeatureDiscoveryReconciler) Reconcile(ctx context.Context, req ctrl
}

// Check the status of the NFD Operator Worker DaemonSet
if rstatus, err := r.getWorkerDaemonSetConditions(ctx); err != nil {
if rstatus, err := r.getWorkerDaemonSetConditions(ctx, instance); err != nil {
return r.updateDegradedCondition(instance, conditionFailedGettingNFDWorkerDaemonSet, err.Error())
} else if rstatus.isProgressing {
return r.updateProgressingCondition(instance, err.Error(), "nfd-worker Daemonset is progressing")
Expand All @@ -222,7 +222,7 @@ func (r *NodeFeatureDiscoveryReconciler) Reconcile(ctx context.Context, req ctrl
}

// Check the status of the NFD Operator Master DaemonSet
if rstatus, err := r.getMasterDaemonSetConditions(ctx); err != nil {
if rstatus, err := r.getMasterDaemonSetConditions(ctx, instance); err != nil {
return r.updateDegradedCondition(instance, conditionFailedGettingNFDMasterDaemonSet, err.Error())
} else if rstatus.isProgressing {
return r.updateProgressingCondition(instance, err.Error(), "nfd-master Daemonset is progressing")
Expand Down
36 changes: 0 additions & 36 deletions controllers/nodefeaturediscovery_controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,42 +57,6 @@ func (s ResourceStatus) String() string {
return names[s]
}

// Namespace checks if the Namespace for NFD exists and creates it
// if it doesn't exist
func Namespace(n NFD) (ResourceStatus, error) {

// state represents the resource's 'control' function index
state := n.idx

// It is assumed that the index has already been verified to be a
// Namespace object, so let's get the resource's Namespace object
obj := n.resources[state].Namespace

// found states if the Namespace was found
found := &corev1.Namespace{}

// Look for the Namespace to see if it exists, and if so, check if
// it's Ready/NotReady. If the Namespace does not exist, then
// attempt to create it
klog.Info("Looking for Namespace %q", obj.Name)
err := n.rec.Client.Get(context.TODO(), types.NamespacedName{Namespace: obj.Namespace, Name: obj.Name}, found)
if err != nil && errors.IsNotFound(err) {
klog.Info("Namespace %q Not found, creating", obj.Name)
err = n.rec.Client.Create(context.TODO(), &obj)
if err != nil {
klog.Info("Couldn't create Namespace %q", obj.Name)
return NotReady, err
}
return Ready, nil
} else if err != nil {
return NotReady, err
}

klog.Info("Found Namespace %q, skipping update", obj.Name)

return Ready, nil
}

// ServiceAccount checks the readiness of the NFD ServiceAccount and creates it if it doesn't exist
func ServiceAccount(n NFD) (ResourceStatus, error) {

Expand Down
5 changes: 0 additions & 5 deletions controllers/nodefeaturediscovery_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ func addResourcesControls(path string) (Resources, controlFunc) {
kind = strings.TrimSpace(slce[1])

switch kind {
case "Namespace":
_, _, err := s.Decode(m, nil, &res.Namespace)
panicIfError(err)
ctrl = append(ctrl, Namespace)
case "ServiceAccount":
_, _, err := s.Decode(m, nil, &res.ServiceAccount)
panicIfError(err)
Expand Down Expand Up @@ -153,7 +149,6 @@ func addResourcesControls(path string) (Resources, controlFunc) {
default:
klog.Info("Unknown Resource: ", "Kind", kind)
}

}

return res, ctrl
Expand Down
Loading