From de560b96388dea7f79efbf994f82a9dc98fca2bf Mon Sep 17 00:00:00 2001 From: "Velayutham, Arunkumar" Date: Tue, 30 Sep 2025 14:28:37 -0400 Subject: [PATCH] Move vsp-p4 yaml into dpu-operator. 1) Move vsp-p4 plugin yaml to dpu-operator. 2) Implement finalizer to sync vsp and vsp-p4 delete sequence. Signed-off-by: Velayutham, Arunkumar --- .../bindata/vsp-p4-pvc/05.vsp_p4_pv.yaml | 24 ------- .../bindata/vsp-p4-pvc/06.vsp_p4_pvc.yaml | 13 ---- .../infrapod/bindata/vsp-p4/01.vsp_p4_sa.yaml | 5 -- .../bindata/vsp-p4/02.vsp_p4_role.yaml | 25 ------- .../vsp-p4/03.vsp_p4_role_binding.yaml | 13 ---- .../bindata/vsp-p4/04.vsp_p4_service.yaml | 12 ---- .../infrapod/bindata/vsp-p4/99.vsp_p4.yaml | 67 ------------------- ipu-plugin/pkg/infrapod/infrapod.go | 67 ------------------- ipu-plugin/pkg/ipuplugin/ipuplugin.go | 16 ----- ipu-plugin/pkg/types/types.go | 3 - 10 files changed, 245 deletions(-) delete mode 100644 ipu-plugin/pkg/infrapod/bindata/vsp-p4-pvc/05.vsp_p4_pv.yaml delete mode 100644 ipu-plugin/pkg/infrapod/bindata/vsp-p4-pvc/06.vsp_p4_pvc.yaml delete mode 100644 ipu-plugin/pkg/infrapod/bindata/vsp-p4/01.vsp_p4_sa.yaml delete mode 100644 ipu-plugin/pkg/infrapod/bindata/vsp-p4/02.vsp_p4_role.yaml delete mode 100644 ipu-plugin/pkg/infrapod/bindata/vsp-p4/03.vsp_p4_role_binding.yaml delete mode 100644 ipu-plugin/pkg/infrapod/bindata/vsp-p4/04.vsp_p4_service.yaml delete mode 100644 ipu-plugin/pkg/infrapod/bindata/vsp-p4/99.vsp_p4.yaml diff --git a/ipu-plugin/pkg/infrapod/bindata/vsp-p4-pvc/05.vsp_p4_pv.yaml b/ipu-plugin/pkg/infrapod/bindata/vsp-p4-pvc/05.vsp_p4_pv.yaml deleted file mode 100644 index 3dad774f..00000000 --- a/ipu-plugin/pkg/infrapod/bindata/vsp-p4-pvc/05.vsp_p4_pv.yaml +++ /dev/null @@ -1,24 +0,0 @@ -apiVersion: v1 -kind: PersistentVolume -metadata: - name: vsp-p4-pv - namespace: {{.Namespace}} -spec: - selector: - app: vsp-p4 - capacity: - storage: 3Gi - accessModes: - - ReadWriteMany - persistentVolumeReclaimPolicy: Retain - local: - path: /opt/p4/ - storageClassName: local-storage - nodeAffinity: - required: - nodeSelectorTerms: - - matchExpressions: - - key: kubernetes.io/hostname - operator: In - values: - - {{.HostName}} diff --git a/ipu-plugin/pkg/infrapod/bindata/vsp-p4-pvc/06.vsp_p4_pvc.yaml b/ipu-plugin/pkg/infrapod/bindata/vsp-p4-pvc/06.vsp_p4_pvc.yaml deleted file mode 100644 index b9ff1d3c..00000000 --- a/ipu-plugin/pkg/infrapod/bindata/vsp-p4-pvc/06.vsp_p4_pvc.yaml +++ /dev/null @@ -1,13 +0,0 @@ -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: vsp-p4-pvc - namespace: {{.Namespace}} -spec: - accessModes: - - ReadWriteMany - provisioner: kubernetes.io/no-provisioner - resources: - requests: - storage: 3Gi - storageClassName: local-storage diff --git a/ipu-plugin/pkg/infrapod/bindata/vsp-p4/01.vsp_p4_sa.yaml b/ipu-plugin/pkg/infrapod/bindata/vsp-p4/01.vsp_p4_sa.yaml deleted file mode 100644 index dd0a15c2..00000000 --- a/ipu-plugin/pkg/infrapod/bindata/vsp-p4/01.vsp_p4_sa.yaml +++ /dev/null @@ -1,5 +0,0 @@ -apiVersion: v1 -kind: ServiceAccount -metadata: - name: vsp-p4-sa - namespace: {{.Namespace}} diff --git a/ipu-plugin/pkg/infrapod/bindata/vsp-p4/02.vsp_p4_role.yaml b/ipu-plugin/pkg/infrapod/bindata/vsp-p4/02.vsp_p4_role.yaml deleted file mode 100644 index e1909ce1..00000000 --- a/ipu-plugin/pkg/infrapod/bindata/vsp-p4/02.vsp_p4_role.yaml +++ /dev/null @@ -1,25 +0,0 @@ -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: vsp-p4-role - namespace: {{.Namespace}} -rules: -- apiGroups: - - security.openshift.io - resourceNames: - - privileged - resources: - - securitycontextconstraints - verbs: - - use -- apiGroups: - - apps - resources: - - daemonsets - verbs: - - get - - list - - watch - - create - - update - - delete diff --git a/ipu-plugin/pkg/infrapod/bindata/vsp-p4/03.vsp_p4_role_binding.yaml b/ipu-plugin/pkg/infrapod/bindata/vsp-p4/03.vsp_p4_role_binding.yaml deleted file mode 100644 index 0540653d..00000000 --- a/ipu-plugin/pkg/infrapod/bindata/vsp-p4/03.vsp_p4_role_binding.yaml +++ /dev/null @@ -1,13 +0,0 @@ -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: vsp-p4-role-binding - namespace: {{.Namespace}} -subjects: -- kind: ServiceAccount - name: vsp-p4-sa -roleRef: - kind: Role - name: vsp-p4-role - apiGroup: rbac.authorization.k8s.io - diff --git a/ipu-plugin/pkg/infrapod/bindata/vsp-p4/04.vsp_p4_service.yaml b/ipu-plugin/pkg/infrapod/bindata/vsp-p4/04.vsp_p4_service.yaml deleted file mode 100644 index 045f0ad4..00000000 --- a/ipu-plugin/pkg/infrapod/bindata/vsp-p4/04.vsp_p4_service.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: vsp-p4-service - namespace: {{.Namespace}} -spec: - selector: - app: vsp-p4 - ports: - - protocol: TCP - port: 9559 - targetPort: 9559 diff --git a/ipu-plugin/pkg/infrapod/bindata/vsp-p4/99.vsp_p4.yaml b/ipu-plugin/pkg/infrapod/bindata/vsp-p4/99.vsp_p4.yaml deleted file mode 100644 index fe38fd6e..00000000 --- a/ipu-plugin/pkg/infrapod/bindata/vsp-p4/99.vsp_p4.yaml +++ /dev/null @@ -1,67 +0,0 @@ -apiVersion: apps/v1 -kind: DaemonSet -metadata: - name: vsp-p4 - namespace: {{.Namespace}} -spec: - selector: - matchLabels: - app: vsp-p4 - template: - metadata: - labels: - app: vsp-p4 - spec: - nodeSelector: - dpu: "true" - serviceAccountName: vsp-p4-sa - containers: - - name: p4-container - image: {{.ImageName}} - securityContext: - privileged: true - ports: - - containerPort: 9559 - hostPort: 9559 - resources: - requests: - cpu: 500m - memory: 4Gi - hugepages-2Mi: 256Mi - limits: - cpu: 1 - memory: 4Gi - hugepages-2Mi: 256Mi - volumeMounts: - - name: lib-modules - mountPath: /lib/modules/ - - name: var-run - mountPath: /opt/p4/p4-cp-nws/var/run - - name: sys - mountPath: /sys - - name: dev - mountPath: /dev - - name: hugepages - mountPath: /dev/hugepages - - name: opt-p4 - mountPath: /opt/p4 - dnsPolicy: ClusterFirstWithHostNet - volumes: - - name: lib-modules - hostPath: - path: /lib/modules/ - - name: var-run - hostPath: - path: /opt/p4/p4-cp-nws/var/run - - name: sys - hostPath: - path: /sys - - name: dev - hostPath: - path: /dev - - name: hugepages - hostPath: - path: /dev/hugepages - - name: opt-p4 - persistentVolumeClaim: - claimName: vsp-p4-pvc diff --git a/ipu-plugin/pkg/infrapod/infrapod.go b/ipu-plugin/pkg/infrapod/infrapod.go index 8fbdba1c..1b64e705 100644 --- a/ipu-plugin/pkg/infrapod/infrapod.go +++ b/ipu-plugin/pkg/infrapod/infrapod.go @@ -2,7 +2,6 @@ package infrapod import ( "context" - "embed" "fmt" "os" "strconv" @@ -10,7 +9,6 @@ import ( "github.com/bombsimon/logrusr/v4" "github.com/go-logr/logr" - "github.com/intel/ipu-opi-plugins/ipu-plugin/pkg/k8s/render" "github.com/intel/ipu-opi-plugins/ipu-plugin/pkg/types" logrus "github.com/sirupsen/logrus" appsv1 "k8s.io/api/apps/v1" @@ -29,8 +27,6 @@ import ( "k8s.io/client-go/rest" ) -//go:embed bindata/* -var binData embed.FS var ( scheme = runtime.NewScheme() ) @@ -164,69 +160,6 @@ func (infrapodMgr *InfrapodMgrOcImpl) getPvCrs() (error, bool) { return err, false } -/* -Create p4 pvc This will create -> -persistentvolumes -persistentvolumeclaims -*/ -func (infrapodMgr *InfrapodMgrOcImpl) CreatePvCrs() error { - err, isPresent := infrapodMgr.getPvCrs() - if err != nil { - infrapodMgr.log.Error(err, "failed to start PV") - return fmt.Errorf("failed to get PV due to: %v", err) - } - if isPresent { - infrapodMgr.log.Error(err, "PV already present") - return nil - } - err = render.OperateAllFromBinData(infrapodMgr.log, "vsp-p4-pvc", - infrapodMgr.vspP4Template.ToMap(), binData, infrapodMgr.mgr.GetClient(), - nil, infrapodMgr.mgr.GetScheme(), false) - if err != nil { - infrapodMgr.log.Error(err, "failed to start PV") - return fmt.Errorf("failed to start PV due to: %v", err) - } - return nil -} - -/* -Create p4 pod This will create -> -ServiceAccount -role -rolebindings -service for p4runtime -P4 pod -*/ -func (infrapodMgr *InfrapodMgrOcImpl) CreateCrs() error { - err := render.OperateAllFromBinData(infrapodMgr.log, "vsp-p4", - infrapodMgr.vspP4Template.ToMap(), binData, infrapodMgr.mgr.GetClient(), - nil, infrapodMgr.mgr.GetScheme(), false) - if err != nil { - infrapodMgr.log.Error(err, "failed to start vsp-p4") - return fmt.Errorf("failed to start vsp-p4 (p4Image:%s) due to: %v", infrapodMgr.vspP4Template.ImageName, err) - } - return nil -} - -/* -Delete p4 pod This will delete -> -ServiceAccount -role -rolebindings -service for p4runtime -P4 pod -*/ -func (infrapodMgr *InfrapodMgrOcImpl) DeleteCrs() error { - err := render.OperateAllFromBinData(infrapodMgr.log, "vsp-p4", - infrapodMgr.vspP4Template.ToMap(), binData, infrapodMgr.mgr.GetClient(), - nil, infrapodMgr.mgr.GetScheme(), true) - if err != nil { - infrapodMgr.log.Error(err, "failed to delete vsp-p4") - return fmt.Errorf("failed to delete vsp-p4 (p4Image:%s) due to: %v", infrapodMgr.vspP4Template.ImageName, err) - } - return nil -} - func (infrapodMgr *InfrapodMgrOcImpl) WaitForPodDelete(timeout time.Duration) error { /* This waits for P4 pod status to be ready. diff --git a/ipu-plugin/pkg/ipuplugin/ipuplugin.go b/ipu-plugin/pkg/ipuplugin/ipuplugin.go index aa0e867c..9026be6d 100644 --- a/ipu-plugin/pkg/ipuplugin/ipuplugin.go +++ b/ipu-plugin/pkg/ipuplugin/ipuplugin.go @@ -175,22 +175,10 @@ func (s *server) Run() error { syscall.Kill(syscall.Getpid(), syscall.SIGTERM) } }() - if err = s.infrapodMgr.DeleteCrs(); err != nil { - log.Error(err, "unable to Delete Crs : %v", err) - return err - } if err = s.infrapodMgr.WaitForPodDelete(60 * time.Second); err != nil { log.Error(err, "unable to Wait for pod deletion : %v", err) return err } - if err = s.infrapodMgr.CreatePvCrs(); err != nil { - log.Error(err, "unable to Create PV Crs : %v", err) - return err - } - if err = s.infrapodMgr.CreateCrs(); err != nil { - log.Error(err, "unable to Create Crs : %v", err) - return err - } if err = s.infrapodMgr.WaitForPodReady(60 * time.Second); err != nil { log.Error(err, "unable to Wait for pod creation : %v", err) return err @@ -264,10 +252,6 @@ func (s *server) Stop() { s.bridgeCtlr.DeleteBridges() // Delete P4 rules on exit cleanUpRulesOnExit(s.p4rtClient) - if err := s.infrapodMgr.DeleteCrs(); err != nil { - log.Error(err, "unable to Delete Crs : %v", err) - // Do not return since we continue on error - } //Restore Red Hat primary network path via opcodes - This is required after the primiary network P4 rules are deleted. utils.RestoreRHPrimaryNetwork() } diff --git a/ipu-plugin/pkg/types/types.go b/ipu-plugin/pkg/types/types.go index 6408fe04..3cb5a4b3 100644 --- a/ipu-plugin/pkg/types/types.go +++ b/ipu-plugin/pkg/types/types.go @@ -82,9 +82,6 @@ type P4RTClient interface { type InfrapodMgr interface { StartMgr() error - CreateCrs() error - CreatePvCrs() error - DeleteCrs() error WaitForPodDelete(timeout time.Duration) error WaitForPodReady(timeout time.Duration) error }