Skip to content

Commit

Permalink
NFDeployment CRD for Multi-vendor(https://github.com/nephio-project/n… (
Browse files Browse the repository at this point in the history
#45)

NFDeployment CRD for Multi-vendor Network functions
nephio-project/nephio#400
nephio-project/nephio#401
nephio-project/nephio#402
  • Loading branch information
vamshi-namilikonda authored Jan 4, 2024
1 parent db7c258 commit e657fdf
Show file tree
Hide file tree
Showing 38 changed files with 854 additions and 479 deletions.
404 changes: 404 additions & 0 deletions config/crd/bases/workload.nephio.org_nfdeployments.yaml

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
# since it depends on service name and namespace that are out of this kustomize package.
# It should be run by config/default
resources:
- bases/workload.nephio.org_amfdeployments.yaml
- bases/workload.nephio.org_smfdeployments.yaml
- bases/workload.nephio.org_upfdeployments.yaml
- bases/workload.nephio.org_nfdeployments.yaml
#+kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
Expand Down
56 changes: 2 additions & 54 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,6 @@ kind: ClusterRole
metadata:
name: free5gc-operator-role
rules:
- apiGroups:
- ""
resources:
- configmaps
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- ""
resources:
Expand Down Expand Up @@ -73,47 +61,7 @@ rules:
- apiGroups:
- workload.nephio.org
resources:
- amfdeployments
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- workload.nephio.org
resources:
- amfdeployments/status
verbs:
- get
- patch
- update
- apiGroups:
- workload.nephio.org
resources:
- smfdeployments
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- workload.nephio.org
resources:
- smfdeployments/status
verbs:
- get
- patch
- update
- apiGroups:
- workload.nephio.org
resources:
- upfdeployments
- nfdeployments
verbs:
- create
- delete
Expand All @@ -125,7 +73,7 @@ rules:
- apiGroups:
- workload.nephio.org
resources:
- upfdeployments/status
- nfdeployments/status
verbs:
- get
- patch
Expand Down
2 changes: 1 addition & 1 deletion config/samples/workload_v1alpha1_upfdeployment.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: workload.nephio.org/v1alpha1
kind: UPFDeployment
kind: NFDeployment
metadata:
labels:
app.kubernetes.io/name: upfdeployment
Expand Down
25 changes: 4 additions & 21 deletions controllers/amf/reconciler.go → controllers/nf/amf/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,6 @@ type AMFDeploymentReconciler struct {
Scheme *runtime.Scheme
}

// Sets up the controller with the Manager
func (r *AMFDeploymentReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(new(nephiov1alpha1.AMFDeployment)).
Owns(new(appsv1.Deployment)).
Owns(new(apiv1.ConfigMap)).
Complete(r)
}

// +kubebuilder:rbac:groups=workload.nephio.org,resources=amfdeployments,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=workload.nephio.org,resources=amfdeployments/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=apps,resources=deployments/status,verbs=get
// +kubebuilder:rbac:groups="",resources=pods,verbs=get;list;watch
// +kubebuilder:rbac:groups="",resources=configmaps;services,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups="",resources=events,verbs=create;patch
// +kubebuilder:rbac:groups="k8s.cni.cncf.io",resources=network-attachment-definitions,verbs=get;list;watch

// 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
Expand All @@ -70,7 +52,7 @@ func (r *AMFDeploymentReconciler) SetupWithManager(mgr ctrl.Manager) error {
func (r *AMFDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := log.FromContext(ctx).WithValues("AMFDeployment", req.NamespacedName)

amfDeployment := new(nephiov1alpha1.AMFDeployment)
amfDeployment := new(nephiov1alpha1.NFDeployment)
err := r.Client.Get(ctx, req.NamespacedName, amfDeployment)
if err != nil {
if k8serrors.IsNotFound(err) {
Expand Down Expand Up @@ -197,10 +179,11 @@ func (r *AMFDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Reques
return reconcile.Result{}, nil
}

func (r *AMFDeploymentReconciler) syncStatus(ctx context.Context, deployment *appsv1.Deployment, amfDeployment *nephiov1alpha1.AMFDeployment) error {
func (r *AMFDeploymentReconciler) syncStatus(ctx context.Context, deployment *appsv1.Deployment, amfDeployment *nephiov1alpha1.NFDeployment) error {
if nfDeploymentStatus, update := createNfDeploymentStatus(deployment, amfDeployment); update {
amfDeployment = amfDeployment.DeepCopy()
amfDeployment.Status.NFDeploymentStatus = nfDeploymentStatus
//amfDeployment.Status.NFDeploymentStatus = nfDeploymentStatus
amfDeployment.Status = nfDeploymentStatus
return r.Status().Update(ctx, amfDeployment)
} else {
return nil
Expand Down
36 changes: 18 additions & 18 deletions controllers/amf/resources.go → controllers/nf/amf/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
)

func createDeployment(log logr.Logger, configMapVersion string, amfDeployment *nephiov1alpha1.AMFDeployment) (*appsv1.Deployment, error) {
namespace := amfDeployment.Namespace
instanceName := amfDeployment.Name
spec := amfDeployment.Spec
func createDeployment(log logr.Logger, configMapVersion string, nfDeployment *nephiov1alpha1.NFDeployment) (*appsv1.Deployment, error) {
namespace := nfDeployment.Namespace
instanceName := nfDeployment.Name
spec := nfDeployment.Spec

replicas, resourceRequirements, err := createResourceRequirements(spec)
if err != nil {
return nil, err
}

networkAttachmentDefinitionNetworks, err := createNetworkAttachmentDefinitionNetworks(amfDeployment.Name, &spec)
networkAttachmentDefinitionNetworks, err := createNetworkAttachmentDefinitionNetworks(nfDeployment.Name, &spec)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -132,9 +132,9 @@ func createDeployment(log logr.Logger, configMapVersion string, amfDeployment *n
return deployment, nil
}

func createService(amfDeployment *nephiov1alpha1.AMFDeployment) *apiv1.Service {
namespace := amfDeployment.Namespace
instanceName := amfDeployment.Name
func createService(nfDeployment *nephiov1alpha1.NFDeployment) *apiv1.Service {
namespace := nfDeployment.Namespace
instanceName := nfDeployment.Name

labels := map[string]string{
"name": instanceName,
Expand All @@ -160,13 +160,13 @@ func createService(amfDeployment *nephiov1alpha1.AMFDeployment) *apiv1.Service {
return service
}

func createConfigMap(log logr.Logger, amfDeployment *nephiov1alpha1.AMFDeployment) (*apiv1.ConfigMap, error) {
namespace := amfDeployment.Namespace
instanceName := amfDeployment.Name
func createConfigMap(log logr.Logger, nfDeployment *nephiov1alpha1.NFDeployment) (*apiv1.ConfigMap, error) {
namespace := nfDeployment.Namespace
instanceName := nfDeployment.Name

n2ip, err := controllers.GetFirstInterfaceConfigIPv4(amfDeployment.Spec.Interfaces, "n2")
n2ip, err := controllers.GetFirstInterfaceConfigIPv4(nfDeployment.Spec.Interfaces, "n2")
if err != nil {
log.Error(err, "Interface N2 not found in AMFDeployment Spec")
log.Error(err, "Interface N2 not found in NFDeployment Spec")
return nil, err
}

Expand All @@ -177,7 +177,7 @@ func createConfigMap(log logr.Logger, amfDeployment *nephiov1alpha1.AMFDeploymen

configuration, err := renderConfigurationTemplate(templateValues)
if err != nil {
log.Error(err, "Could not render AMF configuration template.")
log.Error(err, "Could not render NF configuration template.")
return nil, err
}

Expand All @@ -199,7 +199,7 @@ func createConfigMap(log logr.Logger, amfDeployment *nephiov1alpha1.AMFDeploymen
return configMap, nil
}

func createResourceRequirements(amfDeploymentSpec nephiov1alpha1.AMFDeploymentSpec) (int32, *apiv1.ResourceRequirements, error) {
func createResourceRequirements(nfDeploymentSpec nephiov1alpha1.NFDeploymentSpec) (int32, *apiv1.ResourceRequirements, error) {
// TODO: Requirements should be calculated based on DL, UL
// TODO: increase number of recpicas based on NFDeployment.Capacity.MaxSessions

Expand All @@ -211,7 +211,7 @@ func createResourceRequirements(amfDeploymentSpec nephiov1alpha1.AMFDeploymentSp
var memoryLimit string
var memoryRequest string

if amfDeploymentSpec.Capacity.MaxSubscribers > 1000 {
if nfDeploymentSpec.Capacity.MaxSubscribers > 1000 {
cpuLimit = "300m"
memoryLimit = "256Mi"
cpuRequest = "300m"
Expand All @@ -237,8 +237,8 @@ func createResourceRequirements(amfDeploymentSpec nephiov1alpha1.AMFDeploymentSp
return replicas, &resources, nil
}

func createNetworkAttachmentDefinitionNetworks(templateName string, amfDeploymentSpec *nephiov1alpha1.AMFDeploymentSpec) (string, error) {
func createNetworkAttachmentDefinitionNetworks(templateName string, nfDeploymentSpec *nephiov1alpha1.NFDeploymentSpec) (string, error) {
return controllers.CreateNetworkAttachmentDefinitionNetworks(templateName, map[string][]nephiov1alpha1.InterfaceConfig{
"n2": controllers.GetInterfaceConfigs(amfDeploymentSpec.Interfaces, "n2"),
"n2": controllers.GetInterfaceConfigs(nfDeploymentSpec.Interfaces, "n2"),
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import (

func TestCreateDeployment(t *testing.T) {
log := log.FromContext(context.TODO())
amfDeployment := newAmfDeployment("test-amf-deployment")
got, err := createDeployment(log, "111111", amfDeployment)
nfDeployment := newAmfDeployment("test-amf-deployment")
got, err := createDeployment(log, "111111", nfDeployment)
if err != nil {
t.Errorf("createDeployment() returned unexpected error %s", err.Error())
}
Expand Down Expand Up @@ -142,19 +142,19 @@ func TestCreateDeployment(t *testing.T) {
},
}
if !reflect.DeepEqual(got, want) {
t.Errorf("createDeployment(%v) returned %v, want %v", amfDeployment, got, want)
t.Errorf("createDeployment(%v) returned %v, want %v", nfDeployment, got, want)
}
}

func TestCreateConfigMap(t *testing.T) {
log := log.FromContext(context.TODO())
amfDeployment := newAmfDeployment("test-amf-deployment")
got, err := createConfigMap(log, amfDeployment)
nfDeployment := newAmfDeployment("test-amf-deployment")
got, err := createConfigMap(log, nfDeployment)
if err != nil {
t.Errorf("createConfigMap() returned unexpected error %v", err)
}

n2ip, _ := controllers.GetFirstInterfaceConfigIPv4(amfDeployment.Spec.Interfaces, "n2")
n2ip, _ := controllers.GetFirstInterfaceConfigIPv4(nfDeployment.Spec.Interfaces, "n2")

templateValues := configurationTemplateValues{
SVC_NAME: "test-amf-deployment",
Expand All @@ -172,23 +172,23 @@ func TestCreateConfigMap(t *testing.T) {
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: amfDeployment.Name,
Namespace: amfDeployment.Namespace,
Name: nfDeployment.Name,
Namespace: nfDeployment.Namespace,
},
Data: map[string]string{
"amfcfg.yaml": configuration,
// "wrapper.sh": wrapper.String(),
},
}
if !reflect.DeepEqual(got, want) {
t.Errorf("createConfigMap(%v) returned %v, want %v", amfDeployment, got, want)
t.Errorf("createConfigMap(%v) returned %v, want %v", nfDeployment, got, want)
}
}

func TestCreateResourceRequirements(t *testing.T) {
amfDeployment := newAmfDeployment("test-amf-deployment")
nfDeployment := newAmfDeployment("test-amf-deployment")

replicas, got, err := createResourceRequirements(amfDeployment.Spec)
replicas, got, err := createResourceRequirements(nfDeployment.Spec)
if err != nil {
t.Errorf("createResourceRequirements() returned unexpected error %v", err)
}
Expand All @@ -206,7 +206,7 @@ func TestCreateResourceRequirements(t *testing.T) {
},
}
if !reflect.DeepEqual(got, want) {
t.Errorf("createResourceRequirements(%v) returned %v, want %v", amfDeployment.Spec, got, want)
t.Errorf("createResourceRequirements(%v) returned %v, want %v", nfDeployment.Spec, got, want)
}
}

Expand All @@ -225,8 +225,8 @@ func TestCreateNetworkAttachmentDefinitionName(t *testing.T) {
}

func TestCreateNetworkAttachmentDefinitionNetworks(t *testing.T) {
amfDeployment := newAmfDeployment("test-amf-deployment")
got, _ := createNetworkAttachmentDefinitionNetworks("test-amf-deployment", &amfDeployment.DeepCopy().Spec)
nfDeployment := newAmfDeployment("test-amf-deployment")
got, _ := createNetworkAttachmentDefinitionNetworks("test-amf-deployment", &nfDeployment.DeepCopy().Spec)

want := `[
{
Expand All @@ -238,33 +238,31 @@ func TestCreateNetworkAttachmentDefinitionNetworks(t *testing.T) {
]`

if got != want {
t.Errorf("createNetworkAttachmentDefinitionNetworks(%v) returned %v, want %v", amfDeployment.Spec, got, want)
t.Errorf("createNetworkAttachmentDefinitionNetworks(%v) returned %v, want %v", nfDeployment.Spec, got, want)
}
}

func newAmfDeployment(name string) *nephiov1alpha1.AMFDeployment {
func newAmfDeployment(name string) *nephiov1alpha1.NFDeployment {
interfaces := []nephiov1alpha1.InterfaceConfig{}
n2interface := newAmfNxInterface("n2")
interfaces = append(interfaces, n2interface)
//dnnName := "apn-test"

return &nephiov1alpha1.AMFDeployment{
return &nephiov1alpha1.NFDeployment{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: name + "-ns",
},
Spec: nephiov1alpha1.AMFDeploymentSpec{
NFDeploymentSpec: nephiov1alpha1.NFDeploymentSpec{
ConfigRefs: []apiv1.ObjectReference{},
Capacity: &nephioreqv1alpha1.CapacitySpec{
MaxUplinkThroughput: resource.MustParse("1G"),
MaxDownlinkThroughput: resource.MustParse("5G"),
MaxSessions: 1000,
MaxSubscribers: 1000,
MaxNFConnections: 2000,
},
Interfaces: interfaces,
Spec: nephiov1alpha1.NFDeploymentSpec{
ParametersRefs: []nephiov1alpha1.ObjectReference{},
Capacity: &nephioreqv1alpha1.CapacitySpec{
MaxUplinkThroughput: resource.MustParse("1G"),
MaxDownlinkThroughput: resource.MustParse("5G"),
MaxSessions: 1000,
MaxSubscribers: 1000,
MaxNFConnections: 2000,
},
Interfaces: interfaces,
},
}
}
Expand Down
Loading

0 comments on commit e657fdf

Please sign in to comment.