diff --git a/api/v1/sriovnetworkpoolconfig_types.go b/api/v1/sriovnetworkpoolconfig_types.go new file mode 100644 index 000000000..c79473333 --- /dev/null +++ b/api/v1/sriovnetworkpoolconfig_types.go @@ -0,0 +1,49 @@ +package v1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// SriovNetworkPoolConfigSpec defines the desired state of SriovNetworkPoolConfig +type SriovNetworkPoolConfigSpec struct { + // OvsHardwareOffloadConfig describes the OVS HWOL configuration for selected Nodes + OvsHardwareOffloadConfig OvsHardwareOffloadConfig `json:"ovsHardwareOffloadConfig,omitempty"` +} + +type OvsHardwareOffloadConfig struct { + // Name is mandatory and must be unique. + // On Kubernetes: + // Name is the name of OvsHardwareOffloadConfig + // On OpenShift: + // Name is the name of MachineConfigPool to be enabled with OVS hardware offload + Name string `json:"name,omitempty"` +} + +// SriovNetworkPoolConfigStatus defines the observed state of SriovNetworkPoolConfig +type SriovNetworkPoolConfigStatus struct { +} + +//+kubebuilder:object:root=true +//+kubebuilder:subresource:status + +// SriovNetworkPoolConfig is the Schema for the sriovnetworkpoolconfigs API +type SriovNetworkPoolConfig struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec SriovNetworkPoolConfigSpec `json:"spec,omitempty"` + Status SriovNetworkPoolConfigStatus `json:"status,omitempty"` +} + +//+kubebuilder:object:root=true + +// SriovNetworkPoolConfigList contains a list of SriovNetworkPoolConfig +type SriovNetworkPoolConfigList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []SriovNetworkPoolConfig `json:"items"` +} + +func init() { + SchemeBuilder.Register(&SriovNetworkPoolConfig{}, &SriovNetworkPoolConfigList{}) +} diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index 0cac719ca..99b80021a 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -127,6 +127,21 @@ func (in Interfaces) DeepCopy() Interfaces { return *out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *OvsHardwareOffloadConfig) DeepCopyInto(out *OvsHardwareOffloadConfig) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OvsHardwareOffloadConfig. +func (in *OvsHardwareOffloadConfig) DeepCopy() *OvsHardwareOffloadConfig { + if in == nil { + return nil + } + out := new(OvsHardwareOffloadConfig) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SriovIBNetwork) DeepCopyInto(out *SriovIBNetwork) { *out = *in @@ -500,6 +515,96 @@ func (in *SriovNetworkNodeStateStatus) DeepCopy() *SriovNetworkNodeStateStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SriovNetworkPoolConfig) DeepCopyInto(out *SriovNetworkPoolConfig) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec + out.Status = in.Status +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SriovNetworkPoolConfig. +func (in *SriovNetworkPoolConfig) DeepCopy() *SriovNetworkPoolConfig { + if in == nil { + return nil + } + out := new(SriovNetworkPoolConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *SriovNetworkPoolConfig) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SriovNetworkPoolConfigList) DeepCopyInto(out *SriovNetworkPoolConfigList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]SriovNetworkPoolConfig, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SriovNetworkPoolConfigList. +func (in *SriovNetworkPoolConfigList) DeepCopy() *SriovNetworkPoolConfigList { + if in == nil { + return nil + } + out := new(SriovNetworkPoolConfigList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *SriovNetworkPoolConfigList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SriovNetworkPoolConfigSpec) DeepCopyInto(out *SriovNetworkPoolConfigSpec) { + *out = *in + out.OvsHardwareOffloadConfig = in.OvsHardwareOffloadConfig +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SriovNetworkPoolConfigSpec. +func (in *SriovNetworkPoolConfigSpec) DeepCopy() *SriovNetworkPoolConfigSpec { + if in == nil { + return nil + } + out := new(SriovNetworkPoolConfigSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SriovNetworkPoolConfigStatus) DeepCopyInto(out *SriovNetworkPoolConfigStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SriovNetworkPoolConfigStatus. +func (in *SriovNetworkPoolConfigStatus) DeepCopy() *SriovNetworkPoolConfigStatus { + if in == nil { + return nil + } + out := new(SriovNetworkPoolConfigStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SriovNetworkSpec) DeepCopyInto(out *SriovNetworkSpec) { *out = *in diff --git a/config/crd/bases/sriovnetwork.openshift.io_sriovnetworkpoolconfigs.yaml b/config/crd/bases/sriovnetwork.openshift.io_sriovnetworkpoolconfigs.yaml new file mode 100644 index 000000000..eba8c8804 --- /dev/null +++ b/config/crd/bases/sriovnetwork.openshift.io_sriovnetworkpoolconfigs.yaml @@ -0,0 +1,66 @@ + +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.3.0 + creationTimestamp: null + name: sriovnetworkpoolconfigs.sriovnetwork.openshift.io +spec: + group: sriovnetwork.openshift.io + names: + kind: SriovNetworkPoolConfig + listKind: SriovNetworkPoolConfigList + plural: sriovnetworkpoolconfigs + singular: sriovnetworkpoolconfig + scope: Namespaced + versions: + - name: v1 + schema: + openAPIV3Schema: + description: SriovNetworkPoolConfig is the Schema for the sriovnetworkpoolconfigs + API + 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/sig-architecture/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/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: SriovNetworkPoolConfigSpec defines the desired state of SriovNetworkPoolConfig + properties: + ovsHardwareOffloadConfig: + description: OvsHardwareOffloadConfig describes the OVS HWOL configuration + for selected Nodes + properties: + name: + description: 'Name is mandatory and must be unique. On Kubernetes: + Name is the name of OvsHardwareOffloadConfig On OpenShift: Name + is the name of MachineConfigPool to be enabled with OVS hardware + offload' + type: string + type: object + type: object + status: + description: SriovNetworkPoolConfigStatus defines the observed state of + SriovNetworkPoolConfig + type: object + type: object + served: true + storage: true + subresources: + status: {} +status: + acceptedNames: + kind: "" + plural: "" + conditions: [] + storedVersions: [] diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml index f0be96873..6e4c3d59a 100644 --- a/config/crd/kustomization.yaml +++ b/config/crd/kustomization.yaml @@ -7,7 +7,8 @@ resources: - bases/sriovnetwork.openshift.io_sriovibnetworks.yaml - bases/sriovnetwork.openshift.io_sriovnetworknodepolicies.yaml - bases/sriovnetwork.openshift.io_sriovoperatorconfigs.yaml -#+kubebuilder:scaffold:crdkustomizeresource +- bases/sriovnetwork.openshift.io_sriovnetworkpoolconfigs.yaml +# +kubebuilder:scaffold:crdkustomizeresource patchesStrategicMerge: # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix. @@ -17,7 +18,8 @@ patchesStrategicMerge: #- patches/webhook_in_sriovibnetworks.yaml #- patches/webhook_in_sriovnetworknodepolicies.yaml #- patches/webhook_in_sriovoperatorconfigs.yaml -#+kubebuilder:scaffold:crdkustomizewebhookpatch +#- patches/webhook_in_sriovnetworkpoolconfigs.yaml +# +kubebuilder:scaffold:crdkustomizewebhookpatch # [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix. # patches here are for enabling the CA injection for each CRD @@ -26,7 +28,8 @@ patchesStrategicMerge: #- patches/cainjection_in_sriovibnetworks.yaml #- patches/cainjection_in_sriovnetworknodepolicies.yaml #- patches/cainjection_in_sriovoperatorconfigs.yaml -#+kubebuilder:scaffold:crdkustomizecainjectionpatch +#- patches/cainjection_in_sriovnetworkpoolconfigs.yaml +# +kubebuilder:scaffold:crdkustomizecainjectionpatch # the following config is for teaching kustomize how to do kustomization for CRDs. configurations: diff --git a/config/crd/patches/cainjection_in_sriovnetworkpoolconfigs.yaml b/config/crd/patches/cainjection_in_sriovnetworkpoolconfigs.yaml new file mode 100644 index 000000000..8410ee441 --- /dev/null +++ b/config/crd/patches/cainjection_in_sriovnetworkpoolconfigs.yaml @@ -0,0 +1,8 @@ +# The following patch adds a directive for certmanager to inject CA into the CRD +# CRD conversion requires k8s 1.13 or later. +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + annotations: + cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) + name: sriovnetworkpoolconfigs.sriovnetwork.openshift.io diff --git a/config/crd/patches/webhook_in_sriovnetworkpoolconfigs.yaml b/config/crd/patches/webhook_in_sriovnetworkpoolconfigs.yaml new file mode 100644 index 000000000..4dd610c65 --- /dev/null +++ b/config/crd/patches/webhook_in_sriovnetworkpoolconfigs.yaml @@ -0,0 +1,17 @@ +# The following patch enables conversion webhook for CRD +# CRD conversion requires k8s 1.13 or later. +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: sriovnetworkpoolconfigs.sriovnetwork.openshift.io +spec: + conversion: + strategy: Webhook + webhookClientConfig: + # this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank, + # but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager) + caBundle: Cg== + service: + namespace: system + name: webhook-service + path: /convert diff --git a/config/rbac/sriovnetworkpoolconfig_editor_role.yaml b/config/rbac/sriovnetworkpoolconfig_editor_role.yaml new file mode 100644 index 000000000..342506ecf --- /dev/null +++ b/config/rbac/sriovnetworkpoolconfig_editor_role.yaml @@ -0,0 +1,24 @@ +# permissions for end users to edit sriovnetworkpoolconfigs. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: sriovnetworkpoolconfig-editor-role +rules: +- apiGroups: + - sriovnetwork.openshift.io + resources: + - sriovnetworkpoolconfigs + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - sriovnetwork.openshift.io + resources: + - sriovnetworkpoolconfigs/status + verbs: + - get diff --git a/config/rbac/sriovnetworkpoolconfig_viewer_role.yaml b/config/rbac/sriovnetworkpoolconfig_viewer_role.yaml new file mode 100644 index 000000000..d669d324e --- /dev/null +++ b/config/rbac/sriovnetworkpoolconfig_viewer_role.yaml @@ -0,0 +1,20 @@ +# permissions for end users to view sriovnetworkpoolconfigs. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: sriovnetworkpoolconfig-viewer-role +rules: +- apiGroups: + - sriovnetwork.openshift.io + resources: + - sriovnetworkpoolconfigs + verbs: + - get + - list + - watch +- apiGroups: + - sriovnetwork.openshift.io + resources: + - sriovnetworkpoolconfigs/status + verbs: + - get diff --git a/config/samples/sriovnetwork_v1_sriovnetworkpoolconfig.yaml b/config/samples/sriovnetwork_v1_sriovnetworkpoolconfig.yaml new file mode 100644 index 000000000..c02325e9a --- /dev/null +++ b/config/samples/sriovnetwork_v1_sriovnetworkpoolconfig.yaml @@ -0,0 +1,7 @@ +apiVersion: sriovnetwork.openshift.io/v1 +kind: SriovNetworkPoolConfig +metadata: + name: sriovnetworkpoolconfig-sample +spec: + # Add fields here + foo: bar diff --git a/controllers/sriovnetworknodeconfig_controller.go b/controllers/sriovnetworknodeconfig_controller.go new file mode 100644 index 000000000..b51665e3f --- /dev/null +++ b/controllers/sriovnetworknodeconfig_controller.go @@ -0,0 +1,47 @@ +package controllers + +import ( + "context" + + "github.com/go-logr/logr" + "k8s.io/apimachinery/pkg/runtime" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + + sriovnetworkv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1" +) + +// SriovNetworkNodeConfigReconciler reconciles a SriovNetworkNodeConfig object +type SriovNetworkNodeConfigReconciler struct { + client.Client + Log logr.Logger + Scheme *runtime.Scheme +} + +//+kubebuilder:rbac:groups=sriovnetwork.openshift.io,resources=sriovnetworknodeconfigs,verbs=get;list;watch;create;update;patch;delete +//+kubebuilder:rbac:groups=sriovnetwork.openshift.io,resources=sriovnetworknodeconfigs/status,verbs=get;update;patch + +// Reconcile is part of the main kubernetes reconciliation loop which aims to +// move the current state of the cluster closer to the desired state. +// TODO(user): Modify the Reconcile function to compare the state specified by +// the SriovNetworkNodeConfig object against the actual cluster state, and then +// perform operations to make the cluster state reflect the state specified by +// the user. +// +// For more details, check Reconcile and its Result here: +// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.6.4/pkg/reconcile +func (r *SriovNetworkNodeConfigReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { + _ = context.Background() + _ = r.Log.WithValues("sriovnetworknodeconfig", req.NamespacedName) + + // your logic here + + return ctrl.Result{}, nil +} + +// SetupWithManager sets up the controller with the Manager. +func (r *SriovNetworkNodeConfigReconciler) SetupWithManager(mgr ctrl.Manager) error { + return ctrl.NewControllerManagedBy(mgr). + For(&sriovnetworkv1.SriovNetworkNodeConfig{}). + Complete(r) +} diff --git a/main.go b/main.go index cdb4fbf66..184fe37e5 100644 --- a/main.go +++ b/main.go @@ -25,6 +25,7 @@ import ( netattdefv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1" mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" "k8s.io/apimachinery/pkg/api/errors" + // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.) // to ensure that exec-entrypoint and run can make use of them. _ "k8s.io/client-go/plugin/pkg/client/auth" @@ -126,7 +127,16 @@ func main() { setupLog.Error(err, "unable to create controller", "controller", "SriovOperatorConfig") os.Exit(1) } - //+kubebuilder:scaffold:builder + if err = (&controllers.SriovNetworkPoolConfigReconciler{ + Client: mgr.GetClient(), + Log: ctrl.Log.WithName("controllers").WithName("SriovNetworkPoolConfig"), + Scheme: mgr.GetScheme(), + }).SetupWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create controller", "controller", "SriovNetworkPoolConfig") + os.Exit(1) + } + // +kubebuilder:scaffold:builder + // Create a default SriovNetworkNodePolicy err = createDefaultPolicy(ctrl.GetConfigOrDie()) if err != nil {