This is an automated email from the ASF dual-hosted git repository. pingsutw pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/submarine.git
The following commit(s) were added to refs/heads/master by this push: new bf52f6e SUBMARINE-975. Create storageClass for database, minio, tensorboard to control persistentVolume bf52f6e is described below commit bf52f6e6374cf833917ee7b795249b18f00a254c Author: Kenchu123 <k889...@gmail.com> AuthorDate: Fri Aug 13 14:56:10 2021 +0800 SUBMARINE-975. Create storageClass for database, minio, tensorboard to control persistentVolume ### What is this PR for? <!-- A few sentences describing the overall goals of the pull request's commits. First time? Check out the contributing guide - https://submarine.apache.org/contribution/contributions.html --> To create persistent volumes, submarine-operator creates persistent volumes with different names depending on the namespace (eg. `submarine-database-pvādefault`) However, we can use storage class to create persistent volumes dynamically and delete them easily. This will be implemented only on the submarine operator. Besides, only minikube support the current storage class provisioner, and volumes can only be in the host (nfs not supported). ### What type of PR is it? [Improvement] ### Todos - [x] Add storage class - [x] Modify operator to create persistent volume claim with storage class name - [x] Remove persistent volume creation in operator ### What is the Jira issue? <!-- * Open an issue on Jira https://issues.apache.org/jira/browse/SUBMARINE/ * Put link here, and add [SUBMARINE-*Jira number*] in PR title, eg. `SUBMARINE-23. PR title` --> https://issues.apache.org/jira/browse/SUBMARINE-975 ### How should this be tested? <!-- * First time? Setup Travis CI as described on https://submarine.apache.org/contribution/contributions.html#continuous-integration * Strongly recommended: add automated unit tests for any new or changed behavior * Outline any manual steps to test the PR here. --> Follow submarine-operator instructions. ### Screenshots (if appropriate) https://user-images.githubusercontent.com/17617373/129319157-5923ebcf-cdf4-45ae-b18c-e3cc0eb45b16.mov ### Questions: * Do the license files need updating? No * Are there breaking changes for older versions? No * Does this need new documentation? No Author: Kenchu123 <k889...@gmail.com> Signed-off-by: Kevin <pings...@apache.org> Closes #707 from Kenchu123/SUBMARINE-975 and squashes the following commits: 663e26c4 [Kenchu123] SUBMARINE-975. Change submarine_database pvc accessmode 25b1a2c6 [Kenchu123] SUBMARINE-975. Add storage class and remove persistentVolume creation manually --- .../submarine-operator/templates/rbac.yaml | 5 +- .../submarine-operator/templates/storageclass.yaml | 45 +++++++++++++ submarine-cloud-v2/main.go | 1 - submarine-cloud-v2/pkg/controller/controller.go | 34 +++------- .../pkg/controller/submarine_database.go | 71 ++------------------ .../pkg/controller/submarine_minio.go | 76 ++-------------------- .../pkg/controller/submarine_mlflow.go | 75 ++------------------- .../pkg/controller/submarine_tensorboard.go | 76 ++-------------------- 8 files changed, 75 insertions(+), 308 deletions(-) diff --git a/submarine-cloud-v2/helm-charts/submarine-operator/templates/rbac.yaml b/submarine-cloud-v2/helm-charts/submarine-operator/templates/rbac.yaml index 399b5f6..df95280 100644 --- a/submarine-cloud-v2/helm-charts/submarine-operator/templates/rbac.yaml +++ b/submarine-cloud-v2/helm-charts/submarine-operator/templates/rbac.yaml @@ -56,7 +56,6 @@ rules: - namespaces - jobs - serviceaccounts - - persistentvolumes - persistentvolumeclaims - pods/portforward - events @@ -78,8 +77,8 @@ rules: - apiGroups: - "rbac.authorization.k8s.io" resources: - - clusterroles - - clusterrolebindings + - roles + - rolebindings verbs: - "*" - apiGroups: diff --git a/submarine-cloud-v2/helm-charts/submarine-operator/templates/storageclass.yaml b/submarine-cloud-v2/helm-charts/submarine-operator/templates/storageclass.yaml new file mode 100644 index 0000000..6e29357 --- /dev/null +++ b/submarine-cloud-v2/helm-charts/submarine-operator/templates/storageclass.yaml @@ -0,0 +1,45 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: submarine-database-sc +provisioner: k8s.io/minikube-hostpath +reclaimPolicy: Delete +--- +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: submarine-tensorboard-sc +provisioner: k8s.io/minikube-hostpath +reclaimPolicy: Delete +--- +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: submarine-mlflow-sc +provisioner: k8s.io/minikube-hostpath +reclaimPolicy: Delete +--- +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: submarine-minio-sc +provisioner: k8s.io/minikube-hostpath +reclaimPolicy: Delete + diff --git a/submarine-cloud-v2/main.go b/submarine-cloud-v2/main.go index 9db241c..bfdba48 100644 --- a/submarine-cloud-v2/main.go +++ b/submarine-cloud-v2/main.go @@ -91,7 +91,6 @@ func main() { kubeInformerFactory.Apps().V1().Deployments(), kubeInformerFactory.Core().V1().Services(), kubeInformerFactory.Core().V1().ServiceAccounts(), - kubeInformerFactory.Core().V1().PersistentVolumes(), kubeInformerFactory.Core().V1().PersistentVolumeClaims(), kubeInformerFactory.Extensions().V1beta1().Ingresses(), traefikInformerFactory.Traefik().V1alpha1().IngressRoutes(), diff --git a/submarine-cloud-v2/pkg/controller/controller.go b/submarine-cloud-v2/pkg/controller/controller.go index d4af685..e0bd49e 100644 --- a/submarine-cloud-v2/pkg/controller/controller.go +++ b/submarine-cloud-v2/pkg/controller/controller.go @@ -68,28 +68,22 @@ const ( mlflowName = "submarine-mlflow" minioName = "submarine-minio" ingressName = serverName + "-ingress" - databasePvNamePrefix = databaseName + "-pv" + databaseScName = databaseName + "-sc" databasePvcName = databaseName + "-pvc" - tensorboardPvNamePrefix = tensorboardName + "-pv" + tensorboardScName = tensorboardName + "-sc" tensorboardPvcName = tensorboardName + "-pvc" tensorboardServiceName = tensorboardName + "-service" tensorboardIngressRouteName = tensorboardName + "-ingressroute" - mlflowPvNamePrefix = mlflowName + "-pv" + mlflowScName = mlflowName + "-sc" mlflowPvcName = mlflowName + "-pvc" mlflowServiceName = mlflowName + "-service" mlflowIngressRouteName = mlflowName + "-ingressroute" - minioPvNamePrefix = minioName + "-pv" + minioScName = minioName + "-sc" minioPvcName = minioName + "-pvc" minioServiceName = minioName + "-service" minioIngressRouteName = minioName + "-ingressroute" ) -// PersistentVolumes are not namespaced resources, so we add the namespace as a -// suffix to distinguish them -func pvName(pvPrefix string, namespace string) string { - return pvPrefix + "--" + namespace -} - const ( // SuccessSynced is used as part of the Event 'reason' when a Submarine is synced SuccessSynced = "Synced" @@ -120,7 +114,6 @@ type Controller struct { deploymentLister appslisters.DeploymentLister serviceaccountLister corelisters.ServiceAccountLister serviceLister corelisters.ServiceLister - persistentvolumeLister corelisters.PersistentVolumeLister persistentvolumeclaimLister corelisters.PersistentVolumeClaimLister ingressLister extlisters.IngressLister ingressrouteLister traefiklisters.IngressRouteLister @@ -149,7 +142,6 @@ func NewController( deploymentInformer appsinformers.DeploymentInformer, serviceInformer coreinformers.ServiceInformer, serviceaccountInformer coreinformers.ServiceAccountInformer, - persistentvolumeInformer coreinformers.PersistentVolumeInformer, persistentvolumeclaimInformer coreinformers.PersistentVolumeClaimInformer, ingressInformer extinformers.IngressInformer, ingressrouteInformer traefikinformers.IngressRouteInformer, @@ -177,7 +169,6 @@ func NewController( deploymentLister: deploymentInformer.Lister(), serviceLister: serviceInformer.Lister(), serviceaccountLister: serviceaccountInformer.Lister(), - persistentvolumeLister: persistentvolumeInformer.Lister(), persistentvolumeclaimLister: persistentvolumeclaimInformer.Lister(), ingressLister: ingressInformer.Lister(), ingressrouteLister: ingressrouteInformer.Lister(), @@ -246,18 +237,6 @@ func NewController( }, DeleteFunc: controller.handleObject, }) - persistentvolumeInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ - AddFunc: controller.handleObject, - UpdateFunc: func(old, new interface{}) { - newPV := new.(*corev1.PersistentVolume) - oldPV := old.(*corev1.PersistentVolume) - if newPV.ResourceVersion == oldPV.ResourceVersion { - return - } - controller.handleObject(new) - }, - DeleteFunc: controller.handleObject, - }) persistentvolumeclaimInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: controller.handleObject, UpdateFunc: func(old, new interface{}) { @@ -422,6 +401,11 @@ func (c *Controller) syncHandler(key string) error { return err } + // Submarine is in the terminating process + if !submarine.DeletionTimestamp.IsZero() { + return nil + } + // Print out the spec of the Submarine resource b, err := json.MarshalIndent(submarine.Spec, "", " ") fmt.Println(string(b)) diff --git a/submarine-cloud-v2/pkg/controller/submarine_database.go b/submarine-cloud-v2/pkg/controller/submarine_database.go index 3ff5199..d92a804 100644 --- a/submarine-cloud-v2/pkg/controller/submarine_database.go +++ b/submarine-cloud-v2/pkg/controller/submarine_database.go @@ -32,47 +32,8 @@ import ( "k8s.io/klog/v2" ) -func newSubmarineDatabasePersistentVolume(submarine *v1alpha1.Submarine) *corev1.PersistentVolume { - var persistentVolumeSource corev1.PersistentVolumeSource - switch submarine.Spec.Storage.StorageType { - case "nfs": - persistentVolumeSource = corev1.PersistentVolumeSource{ - NFS: &corev1.NFSVolumeSource{ - Server: submarine.Spec.Storage.NfsIP, - Path: submarine.Spec.Storage.NfsPath, - }, - } - case "host": - hostPathType := corev1.HostPathDirectoryOrCreate - persistentVolumeSource = corev1.PersistentVolumeSource{ - HostPath: &corev1.HostPathVolumeSource{ - Path: submarine.Spec.Storage.HostPath, - Type: &hostPathType, - }, - } - } - - return &corev1.PersistentVolume{ - ObjectMeta: metav1.ObjectMeta{ - Name: pvName(databasePvNamePrefix, submarine.Namespace), - OwnerReferences: []metav1.OwnerReference{ - *metav1.NewControllerRef(submarine, v1alpha1.SchemeGroupVersion.WithKind("Submarine")), - }, - }, - Spec: corev1.PersistentVolumeSpec{ - AccessModes: []corev1.PersistentVolumeAccessMode{ - corev1.ReadWriteMany, - }, - Capacity: corev1.ResourceList{ - corev1.ResourceStorage: resource.MustParse(submarine.Spec.Database.StorageSize), - }, - PersistentVolumeSource: persistentVolumeSource, - }, - } -} - func newSubmarineDatabasePersistentVolumeClaim(submarine *v1alpha1.Submarine) *corev1.PersistentVolumeClaim { - storageClassName := "" + storageClassName := databaseScName return &corev1.PersistentVolumeClaim{ ObjectMeta: metav1.ObjectMeta{ Name: databasePvcName, @@ -89,7 +50,6 @@ func newSubmarineDatabasePersistentVolumeClaim(submarine *v1alpha1.Submarine) *c corev1.ResourceStorage: resource.MustParse(submarine.Spec.Database.StorageSize), }, }, - VolumeName: pvName(databasePvNamePrefix, submarine.Namespace), StorageClassName: &storageClassName, }, } @@ -191,30 +151,7 @@ func newSubmarineDatabaseService(submarine *v1alpha1.Submarine) *corev1.Service func (c *Controller) createSubmarineDatabase(submarine *v1alpha1.Submarine) (*appsv1.Deployment, error) { klog.Info("[createSubmarineDatabase]") - // Step1: Create PersistentVolume - pv, err := c.persistentvolumeLister.Get(pvName(databasePvNamePrefix, submarine.Namespace)) - // If the resource doesn't exist, we'll create it - if errors.IsNotFound(err) { - pv, err = c.kubeclientset.CoreV1().PersistentVolumes().Create(context.TODO(), newSubmarineDatabasePersistentVolume(submarine), metav1.CreateOptions{}) - if err != nil { - klog.Info(err) - } - klog.Info(" Create PersistentVolume: ", pv.Name) - } - // If an error occurs during Get/Create, we'll requeue the item so we can - // attempt processing again later. This could have been caused by a - // temporary network failure, or any other transient reason. - if err != nil { - return nil, err - } - - if !metav1.IsControlledBy(pv, submarine) { - msg := fmt.Sprintf(MessageResourceExists, pv.Name) - c.recorder.Event(submarine, corev1.EventTypeWarning, ErrResourceExists, msg) - return nil, fmt.Errorf(msg) - } - - // Step2: Create PersistentVolumeClaim + // Step 1: Create PersistentVolumeClaim pvc, err := c.persistentvolumeclaimLister.PersistentVolumeClaims(submarine.Namespace).Get(databasePvcName) // If the resource doesn't exist, we'll create it if errors.IsNotFound(err) { @@ -237,7 +174,7 @@ func (c *Controller) createSubmarineDatabase(submarine *v1alpha1.Submarine) (*ap return nil, fmt.Errorf(msg) } - // Step3: Create Deployment + // Step 2: Create Deployment deployment, err := c.deploymentLister.Deployments(submarine.Namespace).Get(databaseName) // If the resource doesn't exist, we'll create it if errors.IsNotFound(err) { @@ -270,7 +207,7 @@ func (c *Controller) createSubmarineDatabase(submarine *v1alpha1.Submarine) (*ap return nil, err } - // Step4: Create Service + // Step 3: Create Service service, err := c.serviceLister.Services(submarine.Namespace).Get(databaseName) // If the resource doesn't exist, we'll create it if errors.IsNotFound(err) { diff --git a/submarine-cloud-v2/pkg/controller/submarine_minio.go b/submarine-cloud-v2/pkg/controller/submarine_minio.go index 031104c..7c0873c 100644 --- a/submarine-cloud-v2/pkg/controller/submarine_minio.go +++ b/submarine-cloud-v2/pkg/controller/submarine_minio.go @@ -34,46 +34,8 @@ import ( traefikv1alpha1 "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefik/v1alpha1" ) -func newSubmarineMinioPersistentVolume(submarine *v1alpha1.Submarine) *corev1.PersistentVolume { - var persistentVolumeSource corev1.PersistentVolumeSource - switch submarine.Spec.Storage.StorageType { - case "nfs": - persistentVolumeSource = corev1.PersistentVolumeSource{ - NFS: &corev1.NFSVolumeSource{ - Server: submarine.Spec.Storage.NfsIP, - Path: submarine.Spec.Storage.NfsPath, - }, - } - case "host": - hostPathType := corev1.HostPathDirectoryOrCreate - persistentVolumeSource = corev1.PersistentVolumeSource{ - HostPath: &corev1.HostPathVolumeSource{ - Path: submarine.Spec.Storage.HostPath, - Type: &hostPathType, - }, - } - } - return &corev1.PersistentVolume{ - ObjectMeta: metav1.ObjectMeta{ - Name: pvName(minioPvNamePrefix, submarine.Namespace), - OwnerReferences: []metav1.OwnerReference{ - *metav1.NewControllerRef(submarine, v1alpha1.SchemeGroupVersion.WithKind("Submarine")), - }, - }, - Spec: corev1.PersistentVolumeSpec{ - AccessModes: []corev1.PersistentVolumeAccessMode{ - corev1.ReadWriteMany, - }, - Capacity: corev1.ResourceList{ - corev1.ResourceStorage: resource.MustParse(submarine.Spec.Minio.StorageSize), - }, - PersistentVolumeSource: persistentVolumeSource, - }, - } -} - func newSubmarineMinioPersistentVolumeClaim(submarine *v1alpha1.Submarine) *corev1.PersistentVolumeClaim { - storageClassName := "" + storageClassName := minioScName return &corev1.PersistentVolumeClaim{ ObjectMeta: metav1.ObjectMeta{ Name: minioPvcName, @@ -90,7 +52,6 @@ func newSubmarineMinioPersistentVolumeClaim(submarine *v1alpha1.Submarine) *core corev1.ResourceStorage: resource.MustParse(submarine.Spec.Minio.StorageSize), }, }, - VolumeName: pvName(minioPvNamePrefix, submarine.Namespace), StorageClassName: &storageClassName, }, } @@ -227,34 +188,7 @@ func newSubmarineMinioIngressRoute(submarine *v1alpha1.Submarine) *traefikv1alph func (c *Controller) createSubmarineMinio(submarine *v1alpha1.Submarine) error { klog.Info("[createSubmarineMinio]") - // Step 1: Create PersistentVolume - // PersistentVolumes are not namespaced resources, so we add the namespace - // as a suffix to distinguish them - pv, err := c.persistentvolumeLister.Get(pvName(minioPvNamePrefix, submarine.Namespace)) - - // If the resource doesn't exist, we'll create it - if errors.IsNotFound(err) { - pv, err = c.kubeclientset.CoreV1().PersistentVolumes().Create(context.TODO(), newSubmarineMinioPersistentVolume(submarine), metav1.CreateOptions{}) - if err != nil { - klog.Info(err) - } - klog.Info(" Create PersistentVolume: ", pv.Name) - } - - // If an error occurs during Get/Create, we'll requeue the item so we can - // attempt processing again later. This could have been caused by a - // temporary network failure, or any other transient reason. - if err != nil { - return err - } - - if !metav1.IsControlledBy(pv, submarine) { - msg := fmt.Sprintf(MessageResourceExists, pv.Name) - c.recorder.Event(submarine, corev1.EventTypeWarning, ErrResourceExists, msg) - return fmt.Errorf(msg) - } - - // Step 2: Create PersistentVolumeClaim + // Step 1: Create PersistentVolumeClaim pvc, err := c.persistentvolumeclaimLister.PersistentVolumeClaims(submarine.Namespace).Get(minioPvcName) // If the resource doesn't exist, we'll create it if errors.IsNotFound(err) { @@ -279,7 +213,7 @@ func (c *Controller) createSubmarineMinio(submarine *v1alpha1.Submarine) error { return fmt.Errorf(msg) } - // Step 3: Create Deployment + // Step 2: Create Deployment deployment, err := c.deploymentLister.Deployments(submarine.Namespace).Get(minioName) if errors.IsNotFound(err) { deployment, err = c.kubeclientset.AppsV1().Deployments(submarine.Namespace).Create(context.TODO(), newSubmarineMinioDeployment(submarine), metav1.CreateOptions{}) @@ -301,7 +235,7 @@ func (c *Controller) createSubmarineMinio(submarine *v1alpha1.Submarine) error { return fmt.Errorf(msg) } - // Step 4: Create Service + // Step 3: Create Service service, err := c.serviceLister.Services(submarine.Namespace).Get(minioServiceName) // If the resource doesn't exist, we'll create it if errors.IsNotFound(err) { @@ -324,7 +258,7 @@ func (c *Controller) createSubmarineMinio(submarine *v1alpha1.Submarine) error { return fmt.Errorf(msg) } - // Step 5: Create IngressRoute + // Step 4: Create IngressRoute ingressroute, err := c.ingressrouteLister.IngressRoutes(submarine.Namespace).Get(minioIngressRouteName) // If the resource doesn't exist, we'll create it if errors.IsNotFound(err) { diff --git a/submarine-cloud-v2/pkg/controller/submarine_mlflow.go b/submarine-cloud-v2/pkg/controller/submarine_mlflow.go index 3f431e9..1e5e8d5 100644 --- a/submarine-cloud-v2/pkg/controller/submarine_mlflow.go +++ b/submarine-cloud-v2/pkg/controller/submarine_mlflow.go @@ -32,46 +32,8 @@ import ( "k8s.io/klog/v2" ) -func newSubmarineMlflowPersistentVolume(submarine *v1alpha1.Submarine) *corev1.PersistentVolume { - var persistentVolumeSource corev1.PersistentVolumeSource - switch submarine.Spec.Storage.StorageType { - case "nfs": - persistentVolumeSource = corev1.PersistentVolumeSource{ - NFS: &corev1.NFSVolumeSource{ - Server: submarine.Spec.Storage.NfsIP, - Path: submarine.Spec.Storage.NfsPath, - }, - } - case "host": - hostPathType := corev1.HostPathDirectoryOrCreate - persistentVolumeSource = corev1.PersistentVolumeSource{ - HostPath: &corev1.HostPathVolumeSource{ - Path: submarine.Spec.Storage.HostPath, - Type: &hostPathType, - }, - } - } - return &corev1.PersistentVolume{ - ObjectMeta: metav1.ObjectMeta{ - Name: pvName(mlflowPvNamePrefix, submarine.Namespace), - OwnerReferences: []metav1.OwnerReference{ - *metav1.NewControllerRef(submarine, v1alpha1.SchemeGroupVersion.WithKind("Submarine")), - }, - }, - Spec: corev1.PersistentVolumeSpec{ - AccessModes: []corev1.PersistentVolumeAccessMode{ - corev1.ReadWriteMany, - }, - Capacity: corev1.ResourceList{ - corev1.ResourceStorage: resource.MustParse(submarine.Spec.Mlflow.StorageSize), - }, - PersistentVolumeSource: persistentVolumeSource, - }, - } -} - func newSubmarineMlflowPersistentVolumeClaim(submarine *v1alpha1.Submarine) *corev1.PersistentVolumeClaim { - storageClassName := "" + storageClassName := mlflowScName return &corev1.PersistentVolumeClaim{ ObjectMeta: metav1.ObjectMeta{ Name: mlflowPvcName, @@ -88,7 +50,6 @@ func newSubmarineMlflowPersistentVolumeClaim(submarine *v1alpha1.Submarine) *cor corev1.ResourceStorage: resource.MustParse(submarine.Spec.Mlflow.StorageSize), }, }, - VolumeName: pvName(mlflowPvNamePrefix, submarine.Namespace), StorageClassName: &storageClassName, }, } @@ -219,33 +180,7 @@ func newSubmarineMlflowIngressRoute(submarine *v1alpha1.Submarine) *traefikv1alp func (c *Controller) createSubmarineMlflow(submarine *v1alpha1.Submarine) error { klog.Info("[createSubmarineMlflow]") - // Step 1: Create PersistentVolume - // PersistentVolumes are not namespaced resources, so we add the namespace - // as a suffix to distinguish them - pv, err := c.persistentvolumeLister.Get(pvName(mlflowPvNamePrefix, submarine.Namespace)) - - // If the resource doesn't exist, we'll create it - if errors.IsNotFound(err) { - pv, err = c.kubeclientset.CoreV1().PersistentVolumes().Create(context.TODO(), newSubmarineMlflowPersistentVolume(submarine), metav1.CreateOptions{}) - if err != nil { - klog.Info(err) - } - klog.Info(" Create PersistentVolume: ", pv.Name) - } - // If an error occurs during Get/Create, we'll requeue the item so we can - // attempt processing again later. This could have been caused by a - // temporary network failure, or any other transient reason. - if err != nil { - return err - } - - if !metav1.IsControlledBy(pv, submarine) { - msg := fmt.Sprintf(MessageResourceExists, pv.Name) - c.recorder.Event(submarine, corev1.EventTypeWarning, ErrResourceExists, msg) - return fmt.Errorf(msg) - } - - // Step 2: Create PersistentVolumeClaim + // Step 1: Create PersistentVolumeClaim pvc, err := c.persistentvolumeclaimLister.PersistentVolumeClaims(submarine.Namespace).Get(mlflowPvcName) // If the resource doesn't exist, we'll create it if errors.IsNotFound(err) { @@ -270,7 +205,7 @@ func (c *Controller) createSubmarineMlflow(submarine *v1alpha1.Submarine) error return fmt.Errorf(msg) } - // Step 3: Create Deployment + // Step 2: Create Deployment deployment, err := c.deploymentLister.Deployments(submarine.Namespace).Get(mlflowName) if errors.IsNotFound(err) { deployment, err = c.kubeclientset.AppsV1().Deployments(submarine.Namespace).Create(context.TODO(), newSubmarineMlflowDeployment(submarine), metav1.CreateOptions{}) @@ -292,7 +227,7 @@ func (c *Controller) createSubmarineMlflow(submarine *v1alpha1.Submarine) error return fmt.Errorf(msg) } - // Step 4: Create Service + // Step 3: Create Service service, err := c.serviceLister.Services(submarine.Namespace).Get(mlflowServiceName) // If the resource doesn't exist, we'll create it if errors.IsNotFound(err) { @@ -315,7 +250,7 @@ func (c *Controller) createSubmarineMlflow(submarine *v1alpha1.Submarine) error return fmt.Errorf(msg) } - // Step 5: Create IngressRoute + // Step 4: Create IngressRoute ingressroute, err := c.ingressrouteLister.IngressRoutes(submarine.Namespace).Get(mlflowIngressRouteName) // If the resource doesn't exist, we'll create it if errors.IsNotFound(err) { diff --git a/submarine-cloud-v2/pkg/controller/submarine_tensorboard.go b/submarine-cloud-v2/pkg/controller/submarine_tensorboard.go index 9c487ad..cc71b25 100644 --- a/submarine-cloud-v2/pkg/controller/submarine_tensorboard.go +++ b/submarine-cloud-v2/pkg/controller/submarine_tensorboard.go @@ -34,46 +34,8 @@ import ( traefikv1alpha1 "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefik/v1alpha1" ) -func newSubmarineTensorboardPersistentVolume(submarine *v1alpha1.Submarine) *corev1.PersistentVolume { - var persistentVolumeSource corev1.PersistentVolumeSource - switch submarine.Spec.Storage.StorageType { - case "nfs": - persistentVolumeSource = corev1.PersistentVolumeSource{ - NFS: &corev1.NFSVolumeSource{ - Server: submarine.Spec.Storage.NfsIP, - Path: submarine.Spec.Storage.NfsPath, - }, - } - case "host": - hostPathType := corev1.HostPathDirectoryOrCreate - persistentVolumeSource = corev1.PersistentVolumeSource{ - HostPath: &corev1.HostPathVolumeSource{ - Path: submarine.Spec.Storage.HostPath, - Type: &hostPathType, - }, - } - } - return &corev1.PersistentVolume{ - ObjectMeta: metav1.ObjectMeta{ - Name: pvName(tensorboardPvNamePrefix, submarine.Namespace), - OwnerReferences: []metav1.OwnerReference{ - *metav1.NewControllerRef(submarine, v1alpha1.SchemeGroupVersion.WithKind("Submarine")), - }, - }, - Spec: corev1.PersistentVolumeSpec{ - AccessModes: []corev1.PersistentVolumeAccessMode{ - corev1.ReadWriteMany, - }, - Capacity: corev1.ResourceList{ - corev1.ResourceStorage: resource.MustParse(submarine.Spec.Tensorboard.StorageSize), - }, - PersistentVolumeSource: persistentVolumeSource, - }, - } -} - func newSubmarineTensorboardPersistentVolumeClaim(submarine *v1alpha1.Submarine) *corev1.PersistentVolumeClaim { - storageClassName := "" + storageClassName := tensorboardScName return &corev1.PersistentVolumeClaim{ ObjectMeta: metav1.ObjectMeta{ Name: tensorboardPvcName, @@ -90,7 +52,6 @@ func newSubmarineTensorboardPersistentVolumeClaim(submarine *v1alpha1.Submarine) corev1.ResourceStorage: resource.MustParse(submarine.Spec.Tensorboard.StorageSize), }, }, - VolumeName: pvName(tensorboardPvNamePrefix, submarine.Namespace), StorageClassName: &storageClassName, }, } @@ -224,34 +185,7 @@ func newSubmarineTensorboardIngressRoute(submarine *v1alpha1.Submarine) *traefik func (c *Controller) createSubmarineTensorboard(submarine *v1alpha1.Submarine) error { klog.Info("[createSubmarineTensorboard]") - // Step 1: Create PersistentVolume - // PersistentVolumes are not namespaced resources, so we add the namespace - // as a suffix to distinguish them - pv, err := c.persistentvolumeLister.Get(pvName(tensorboardPvNamePrefix, submarine.Namespace)) - - // If the resource doesn't exist, we'll create it - if errors.IsNotFound(err) { - pv, err = c.kubeclientset.CoreV1().PersistentVolumes().Create(context.TODO(), newSubmarineTensorboardPersistentVolume(submarine), metav1.CreateOptions{}) - if err != nil { - klog.Info(err) - } - klog.Info(" Create PersistentVolume: ", pv.Name) - } - - // If an error occurs during Get/Create, we'll requeue the item so we can - // attempt processing again later. This could have been caused by a - // temporary network failure, or any other transient reason. - if err != nil { - return err - } - - if !metav1.IsControlledBy(pv, submarine) { - msg := fmt.Sprintf(MessageResourceExists, pv.Name) - c.recorder.Event(submarine, corev1.EventTypeWarning, ErrResourceExists, msg) - return fmt.Errorf(msg) - } - - // Step 2: Create PersistentVolumeClaim + // Step 1: Create PersistentVolumeClaim pvc, err := c.persistentvolumeclaimLister.PersistentVolumeClaims(submarine.Namespace).Get(tensorboardPvcName) // If the resource doesn't exist, we'll create it if errors.IsNotFound(err) { @@ -276,7 +210,7 @@ func (c *Controller) createSubmarineTensorboard(submarine *v1alpha1.Submarine) e return fmt.Errorf(msg) } - // Step 3: Create Deployment + // Step 2: Create Deployment deployment, err := c.deploymentLister.Deployments(submarine.Namespace).Get(tensorboardName) if errors.IsNotFound(err) { deployment, err = c.kubeclientset.AppsV1().Deployments(submarine.Namespace).Create(context.TODO(), newSubmarineTensorboardDeployment(submarine), metav1.CreateOptions{}) @@ -298,7 +232,7 @@ func (c *Controller) createSubmarineTensorboard(submarine *v1alpha1.Submarine) e return fmt.Errorf(msg) } - // Step 4: Create Service + // Step 3: Create Service service, err := c.serviceLister.Services(submarine.Namespace).Get(tensorboardServiceName) // If the resource doesn't exist, we'll create it if errors.IsNotFound(err) { @@ -321,7 +255,7 @@ func (c *Controller) createSubmarineTensorboard(submarine *v1alpha1.Submarine) e return fmt.Errorf(msg) } - // Step 5: Create IngressRoute + // Step 4: Create IngressRoute ingressroute, err := c.ingressrouteLister.IngressRoutes(submarine.Namespace).Get(tensorboardIngressRouteName) // If the resource doesn't exist, we'll create it if errors.IsNotFound(err) { --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@submarine.apache.org For additional commands, e-mail: dev-h...@submarine.apache.org