Skip to content

Commit

Permalink
Remove all Openshift deps
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Eduardo Arango Gutierrez <carangog@redhat.com>
  • Loading branch information
ArangoGutierrez committed Sep 30, 2021
1 parent d04b947 commit ac847c4
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 237 deletions.
4 changes: 2 additions & 2 deletions api/v1/nodefeaturediscovery_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package v1

import (
conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1"
"github.com/kubernetes-sigs/node-feature-discovery-operator/pkg/conditions"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -92,7 +92,7 @@ type ConfigMap struct {
type NodeFeatureDiscoveryStatus struct {
// Conditions represents the latest available observations of current state.
// +optional
Conditions []conditionsv1.Condition `json:"conditions,omitempty"`
Conditions []conditions.Condition `json:"conditions,omitempty"`
}

// +kubebuilder:object:root=true
Expand Down
5 changes: 3 additions & 2 deletions api/v1/zz_generated.deepcopy.go

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

91 changes: 34 additions & 57 deletions controllers/nodefeaturediscovery_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,107 +146,84 @@ func (r *NodeFeatureDiscoveryReconciler) Reconcile(ctx context.Context, req ctrl
}

// Check the status of the NFD Operator Worker SecurityContextConstraints
rstatus, err := r.getSecurityContextConstraintsConditions(ctx)
if rstatus.isDegraded {
return r.updateDegradedCondition(instance, err.Error(), err)

} else if err != nil {
if rstatus, err := r.getSecurityContextConstraintsConditions(ctx); err != nil {
return r.updateDegradedCondition(instance, conditionFailedGettingNFDScc, err)
} else if rstatus.isDegraded {
return r.updateDegradedCondition(instance, err.Error(), err)
}

// Check the status of the NFD Operator Worker ServiceAccount
rstatus, err = r.getWorkerServiceAccountConditions(ctx)
if rstatus.isDegraded {
return r.updateDegradedCondition(instance, err.Error(), err)

} else if err != nil {
if rstatus, err := r.getWorkerServiceAccountConditions(ctx); err != nil {
return r.updateDegradedCondition(instance, conditionFailedGettingNFDWorkerServiceAccount, err)
} else if rstatus.isDegraded {
return r.updateDegradedCondition(instance, err.Error(), err)
}

// Check the status of the NFD Operator Master ServiceAccount
rstatus, err = r.getMasterServiceAccountConditions(ctx)
if rstatus.isDegraded {
return r.updateDegradedCondition(instance, err.Error(), err)

} else if err != nil {
if rstatus, err := r.getMasterServiceAccountConditions(ctx); err != nil {
return r.updateDegradedCondition(instance, conditionFailedGettingNFDMasterServiceAccount, err)
} else if rstatus.isDegraded {
return r.updateDegradedCondition(instance, err.Error(), err)
}

// Check the status of the NFD Operator role
rstatus, err = r.getRoleConditions(ctx)
if rstatus.isDegraded {
return r.updateDegradedCondition(instance, err.Error(), err)

} else if err != nil {
if rstatus, err := r.getRoleConditions(ctx); err != nil {
return r.updateDegradedCondition(instance, conditionNFDRoleDegraded, err)
} else if rstatus.isDegraded {
return r.updateDegradedCondition(instance, err.Error(), err)
}

// Check the status of the NFD Operator cluster role
rstatus, err = r.getClusterRoleConditions(ctx)
if rstatus.isDegraded {
return r.updateDegradedCondition(instance, err.Error(), err)

} else if err != nil {
if rstatus, err := r.getClusterRoleConditions(ctx); err != nil {
return r.updateDegradedCondition(instance, conditionNFDClusterRoleDegraded, err)
} else if rstatus.isDegraded {
return r.updateDegradedCondition(instance, err.Error(), err)
}

// Check the status of the NFD Operator cluster role binding
rstatus, err = r.getClusterRoleBindingConditions(ctx)
if rstatus.isDegraded {
return r.updateDegradedCondition(instance, err.Error(), err)

} else if err != nil {
if rstatus, err := r.getClusterRoleBindingConditions(ctx); err != nil {
return r.updateDegradedCondition(instance, conditionNFDClusterRoleBindingDegraded, err)
} else if rstatus.isDegraded {
return r.updateDegradedCondition(instance, err.Error(), err)
}

// Check the status of the NFD Operator role binding
rstatus, err = r.getRoleBindingConditions(ctx)
if rstatus.isDegraded {
return r.updateDegradedCondition(instance, err.Error(), err)

} else if err != nil {
if rstatus, err := r.getRoleBindingConditions(ctx); err != nil {
return r.updateDegradedCondition(instance, conditionFailedGettingNFDRoleBinding, err)
} else if rstatus.isDegraded {
return r.updateDegradedCondition(instance, err.Error(), err)
}

// Check the status of the NFD Operator Service
rstatus, err = r.getServiceConditions(ctx)
if rstatus.isDegraded {
return r.updateDegradedCondition(instance, err.Error(), err)

} else if err != nil {
if rstatus, err := r.getServiceConditions(ctx); err != nil {
return r.updateDegradedCondition(instance, conditionFailedGettingNFDService, err)
} else if rstatus.isDegraded {
return r.updateDegradedCondition(instance, err.Error(), err)
}

// Check the status of the NFD Operator worker ConfigMap
rstatus, err = r.getWorkerConfigConditions(nfd)
if rstatus.isDegraded {
return r.updateDegradedCondition(instance, err.Error(), err)

} else if err != nil {
if rstatus, err := r.getWorkerConfigConditions(nfd); err != nil {
return r.updateDegradedCondition(instance, conditionFailedGettingNFDWorkerConfig, err)
} else if rstatus.isDegraded {
return r.updateDegradedCondition(instance, err.Error(), err)
}

// Check the status of the NFD Operator Worker DaemonSet
rstatus, err = r.getWorkerDaemonSetConditions(ctx)
if rstatus.isProgressing {
if rstatus, err := r.getWorkerDaemonSetConditions(ctx); err != nil {
return r.updateDegradedCondition(instance, conditionFailedGettingNFDWorkerDaemonSet, err)
} else if rstatus.isProgressing {
return r.updateProgressingCondition(instance, err.Error(), err)
} else if rstatus.isDegraded {
return r.updateDegradedCondition(instance, err.Error(), err)

} else if err != nil {
return r.updateDegradedCondition(instance, conditionFailedGettingNFDWorkerDaemonSet, err)
}

// Check the status of the NFD Operator Master DaemonSet
rstatus, err = r.getMasterDaemonSetConditions(ctx)
if rstatus.isProgressing {
if rstatus, err := r.getMasterDaemonSetConditions(ctx); err != nil {
return r.updateDegradedCondition(instance, conditionFailedGettingNFDMasterDaemonSet, err)
} else if rstatus.isProgressing {
return r.updateProgressingCondition(instance, err.Error(), err)

} else if rstatus.isDegraded {
return r.updateDegradedCondition(instance, err.Error(), err)

} else if err != nil {
return r.updateDegradedCondition(instance, conditionFailedGettingNFDMasterDaemonSet, err)
}

// Get available conditions
Expand All @@ -255,7 +232,7 @@ func (r *NodeFeatureDiscoveryReconciler) Reconcile(ctx context.Context, req ctrl
// Update the status of the resource on the CRD
if err := r.updateStatus(instance, conditions); err != nil {
if result != nil {
return *result, nil
return *result, err
}
return reconcile.Result{}, err
}
Expand Down
41 changes: 0 additions & 41 deletions controllers/nodefeaturediscovery_controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"strings"

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"
Expand Down Expand Up @@ -315,7 +314,6 @@ func DaemonSet(n NFD) (ResourceStatus, error) {
var args []string
port := defaultServicePort

// update ports
if n.ins.Spec.Operand.ServicePort != 0 {
port = n.ins.Spec.Operand.ServicePort
}
Expand Down Expand Up @@ -426,42 +424,3 @@ func Service(n NFD) (ResourceStatus, error) {

return Ready, nil
}

func SecurityContextConstraints(n NFD) (ResourceStatus, error) {

state := n.idx
obj := n.resources[state].SecurityContextConstraints

// Set the correct namespace for SCC when installed in non default namespace
obj.Users[0] = "system:serviceaccount:" + n.ins.GetNamespace() + ":" + obj.GetName()

found := &secv1.SecurityContextConstraints{}
logger := log.WithValues("SecurityContextConstraints", obj.Name, "Namespace", "default")

logger.Info("Looking for")

err := n.rec.Client.Get(context.TODO(), types.NamespacedName{Namespace: "", Name: obj.Name}, found)
if err != nil && errors.IsNotFound(err) {
logger.Info("Not found, creating")
err = n.rec.Client.Create(context.TODO(), &obj)
if err != nil {
logger.Info("Couldn't create", "Error", err)
return NotReady, err
}
return Ready, nil
} else if err != nil {
return NotReady, err
}

logger.Info("Found, updating")

required := obj.DeepCopy()
required.ResourceVersion = found.ResourceVersion

err = n.rec.Client.Update(context.TODO(), required)
if err != nil {
return NotReady, err
}

return Ready, nil
}
39 changes: 10 additions & 29 deletions controllers/nodefeaturediscovery_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ import (
"regexp"
"strings"

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/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer/json"
"k8s.io/kubectl/pkg/scheme"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -38,26 +36,16 @@ type assetsFromFile []byte

// Resources holds objects owned by NFD
type Resources struct {
Namespace corev1.Namespace
ServiceAccount corev1.ServiceAccount
Role rbacv1.Role
RoleBinding rbacv1.RoleBinding
ClusterRole rbacv1.ClusterRole
ClusterRoleBinding rbacv1.ClusterRoleBinding
ConfigMap corev1.ConfigMap
DaemonSet appsv1.DaemonSet
Pod corev1.Pod
Service corev1.Service
SecurityContextConstraints secv1.SecurityContextConstraints
}

// Add3dpartyResourcesToScheme Adds 3rd party resources To the operator
func Add3dpartyResourcesToScheme(scheme *runtime.Scheme) error {

if err := secv1.AddToScheme(scheme); err != nil {
return err
}
return nil
Namespace corev1.Namespace
ServiceAccount corev1.ServiceAccount
Role rbacv1.Role
RoleBinding rbacv1.RoleBinding
ClusterRole rbacv1.ClusterRole
ClusterRoleBinding rbacv1.ClusterRoleBinding
ConfigMap corev1.ConfigMap
DaemonSet appsv1.DaemonSet
Pod corev1.Pod
Service corev1.Service
}

func filePathWalkDir(root string) ([]string, error) {
Expand Down Expand Up @@ -209,10 +197,3 @@ func (r *NodeFeatureDiscoveryReconciler) getClusterRoleBinding(ctx context.Conte
err := r.Get(ctx, client.ObjectKey{Namespace: namespace, Name: name}, crb)
return crb, err
}

// getSecurityContextConstraints gets one of the NFD Operator's SecurityContextConstraints
func (r *NodeFeatureDiscoveryReconciler) getSecurityContextConstraints(ctx context.Context, namespace string, name string) (*secv1.SecurityContextConstraints, error) {
scc := &secv1.SecurityContextConstraints{}
err := r.Get(ctx, client.ObjectKey{Namespace: namespace, Name: name}, scc)
return scc, err
}
Loading

0 comments on commit ac847c4

Please sign in to comment.