Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SUBMARINE-1290. Add k8s labels to k8s resources in submarine-cloud-v3 #976

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
#
# 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.
#

Comment on lines -1 to -17
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @ianshen1104
The yaml file also needs to retain the Apache license description.
What is the reason for deletion?

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
Expand Down
17 changes: 0 additions & 17 deletions submarine-cloud-v3/config/rbac/role.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
#
# 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.
#
Comment on lines -1 to -16
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The yaml file also needs to retain the Apache license description.


---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand Down
1 change: 1 addition & 0 deletions submarine-cloud-v3/controllers/submarine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const (
observerRbacYamlPath = artifactPath + "submarine-observer-rbac.yaml"
storageRbacYamlPath = artifactPath + "submarine-storage-rbac.yaml"
virtualServiceYamlPath = artifactPath + "submarine-virtualservice.yaml"
appVersion = "0.8.0-SNAPSHOT"
)

// Name of deployments whose replica count and readiness need to be checked
Expand Down
32 changes: 32 additions & 0 deletions submarine-cloud-v3/controllers/submarine_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,22 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)

var databaseAdditionalLabels = map[string]string{"app.kubernetes.io/name": databaseName, "app.kubernetes.io/version": appVersion, "app.kubernetes.io/component": "database"}

func (r *SubmarineReconciler) newSubmarineDatabasePersistentVolumeClaim(ctx context.Context, submarine *submarineapacheorgv1alpha1.Submarine) *corev1.PersistentVolumeClaim {
pvc, err := ParsePersistentVolumeClaimYaml(databaseYamlPath)
if err != nil {
r.Log.Error(err, "ParsePersistentVolumeClaimYaml")
}
pvc.Namespace = submarine.Namespace
pvcLabels := pvc.GetLabels()
if pvcLabels == nil {
pvc.SetLabels(make(map[string]string))
pvcLabels = pvc.GetLabels()
}
for k, v := range databaseAdditionalLabels {
pvcLabels[k] = v
}
err = controllerutil.SetControllerReference(submarine, pvc, r.Scheme)
if err != nil {
r.Log.Error(err, "Set PVC ControllerReference")
Expand All @@ -52,6 +62,20 @@ func (r *SubmarineReconciler) newSubmarineDatabaseStatefulSet(ctx context.Contex
}

statefulset.Namespace = submarine.Namespace
statefulsetLabels := statefulset.GetLabels()
if statefulsetLabels == nil {
statefulset.SetLabels(make(map[string]string))
statefulsetLabels = statefulset.GetLabels()
}
podLabels := statefulset.Spec.Template.GetLabels()
if podLabels == nil {
statefulset.Spec.Template.SetLabels(make(map[string]string))
podLabels = statefulset.Spec.Template.GetLabels()
}
for k, v := range databaseAdditionalLabels {
statefulsetLabels[k] = v
podLabels[k] = v
}
err = controllerutil.SetControllerReference(submarine, statefulset, r.Scheme)
if err != nil {
r.Log.Error(err, "Set Stateful Set ControllerReference")
Expand All @@ -71,6 +95,14 @@ func (r *SubmarineReconciler) newSubmarineDatabaseService(ctx context.Context, s
r.Log.Error(err, "ParseServiceYaml")
}
service.Namespace = submarine.Namespace
serviceLabels := service.GetLabels()
if serviceLabels == nil {
service.SetLabels(make(map[string]string))
serviceLabels = service.GetLabels()
}
for k, v := range databaseAdditionalLabels {
serviceLabels[k] = v
}
err = controllerutil.SetControllerReference(submarine, service, r.Scheme)
if err != nil {
r.Log.Error(err, "Set Service ControllerReference")
Expand Down
32 changes: 32 additions & 0 deletions submarine-cloud-v3/controllers/submarine_minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,22 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)

var minioAdditionalLabels = map[string]string{"app.kubernetes.io/name": minioName, "app.kubernetes.io/version": appVersion, "app.kubernetes.io/component": "minio"}

func (r *SubmarineReconciler) newSubmarineMinioPersistentVolumeClaim(ctx context.Context, submarine *submarineapacheorgv1alpha1.Submarine) *corev1.PersistentVolumeClaim {
pvc, err := ParsePersistentVolumeClaimYaml(minioYamlPath)
if err != nil {
r.Log.Error(err, "ParsePersistentVolumeClaimYaml")
}
pvc.Namespace = submarine.Namespace
pvcLabels := pvc.GetLabels()
if pvcLabels == nil {
pvc.SetLabels(make(map[string]string))
pvcLabels = pvc.GetLabels()
}
for k, v := range minioAdditionalLabels {
pvcLabels[k] = v
}
err = controllerutil.SetControllerReference(submarine, pvc, r.Scheme)
if err != nil {
r.Log.Error(err, "Set PersistentVolumeClaim ControllerReference")
Expand All @@ -51,6 +61,20 @@ func (r *SubmarineReconciler) newSubmarineMinioDeployment(ctx context.Context, s
r.Log.Error(err, "ParseDeploymentYaml")
}
deployment.Namespace = submarine.Namespace
deploymentLabels := deployment.GetLabels()
if deploymentLabels == nil {
deployment.SetLabels(make(map[string]string))
deploymentLabels = deployment.GetLabels()
}
podLabels := deployment.Spec.Template.GetLabels()
if podLabels == nil {
deployment.Spec.Template.SetLabels(make(map[string]string))
podLabels = deployment.Spec.Template.GetLabels()
}
for k, v := range minioAdditionalLabels {
deploymentLabels[k] = v
podLabels[k] = v
}
err = controllerutil.SetControllerReference(submarine, deployment, r.Scheme)
if err != nil {
r.Log.Error(err, "Set Deployment ControllerReference")
Expand All @@ -64,6 +88,14 @@ func (r *SubmarineReconciler) newSubmarineMinioService(ctx context.Context, subm
r.Log.Error(err, "ParseServiceYaml")
}
service.Namespace = submarine.Namespace
serviceLabels := service.GetLabels()
if serviceLabels == nil {
service.SetLabels(make(map[string]string))
serviceLabels = service.GetLabels()
}
for k, v := range minioAdditionalLabels {
serviceLabels[k] = v
}
err = controllerutil.SetControllerReference(submarine, service, r.Scheme)
if err != nil {
r.Log.Error(err, "Set Service ControllerReference")
Expand Down
32 changes: 32 additions & 0 deletions submarine-cloud-v3/controllers/submarine_mlflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,22 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)

var mlflowAdditionalLabels = map[string]string{"app.kubernetes.io/name": mlflowName, "app.kubernetes.io/version": appVersion, "app.kubernetes.io/component": "mlflow"}

func (r *SubmarineReconciler) newSubmarineMlflowPersistentVolumeClaim(ctx context.Context, submarine *submarineapacheorgv1alpha1.Submarine) *corev1.PersistentVolumeClaim {
pvc, err := ParsePersistentVolumeClaimYaml(mlflowYamlPath)
if err != nil {
r.Log.Error(err, "ParsePersistentVolumeClaimYaml")
}
pvc.Namespace = submarine.Namespace
pvcLabels := pvc.GetLabels()
if pvcLabels == nil {
pvc.SetLabels(make(map[string]string))
pvcLabels = pvc.GetLabels()
}
for k, v := range mlflowAdditionalLabels {
pvcLabels[k] = v
}
err = controllerutil.SetControllerReference(submarine, pvc, r.Scheme)
if err != nil {
r.Log.Error(err, "Set PersistentVolumeClaim ControllerReference")
Expand All @@ -51,6 +61,20 @@ func (r *SubmarineReconciler) newSubmarineMlflowDeployment(ctx context.Context,
r.Log.Error(err, "ParseDeploymentYaml")
}
deployment.Namespace = submarine.Namespace
deploymentLabels := deployment.GetLabels()
if deploymentLabels == nil {
deployment.SetLabels(make(map[string]string))
deploymentLabels = deployment.GetLabels()
}
podLabels := deployment.Spec.Template.GetLabels()
if podLabels == nil {
deployment.Spec.Template.SetLabels(make(map[string]string))
podLabels = deployment.Spec.Template.GetLabels()
}
for k, v := range mlflowAdditionalLabels {
deploymentLabels[k] = v
podLabels[k] = v
}
err = controllerutil.SetControllerReference(submarine, deployment, r.Scheme)
if err != nil {
r.Log.Error(err, "Set Deployment ControllerReference")
Expand All @@ -64,6 +88,14 @@ func (r *SubmarineReconciler) newSubmarineMlflowService(ctx context.Context, sub
r.Log.Error(err, "ParseServiceYaml")
}
service.Namespace = submarine.Namespace
serviceLabels := service.GetLabels()
if serviceLabels == nil {
service.SetLabels(make(map[string]string))
serviceLabels = service.GetLabels()
}
for k, v := range mlflowAdditionalLabels {
serviceLabels[k] = v
}
err = controllerutil.SetControllerReference(submarine, service, r.Scheme)
if err != nil {
r.Log.Error(err, "Set Service ControllerReference")
Expand Down
18 changes: 18 additions & 0 deletions submarine-cloud-v3/controllers/submarine_observer_rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,22 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)

var observerAdditionalLabels = map[string]string{"app.kubernetes.io/name": observerName, "app.kubernetes.io/version": appVersion, "app.kubernetes.io/component": "observer"}

func (r *SubmarineReconciler) newSubmarineObserverRole(ctx context.Context, submarine *submarineapacheorgv1alpha1.Submarine) *rbacv1.Role {
role, err := ParseRoleYaml(observerRbacYamlPath)
if err != nil {
r.Log.Error(err, "ParseRoleYaml")
}
role.Namespace = submarine.Namespace
roleLabels := role.GetLabels()
if roleLabels == nil {
role.SetLabels(make(map[string]string))
roleLabels = role.GetLabels()
}
for k, v := range observerAdditionalLabels {
roleLabels[k] = v
}
err = controllerutil.SetControllerReference(submarine, role, r.Scheme)
if err != nil {
r.Log.Error(err, "Set Role ControllerReference")
Expand All @@ -51,6 +61,14 @@ func (r *SubmarineReconciler) newSubmarineObserverRoleBinding(ctx context.Contex
r.Log.Error(err, "Set RoleBinding ControllerReference")
}
roleBinding.Namespace = submarine.Namespace
roleBindingLabels := roleBinding.GetLabels()
if roleBindingLabels == nil {
roleBinding.SetLabels(make(map[string]string))
roleBindingLabels = roleBinding.GetLabels()
}
for k, v := range observerAdditionalLabels {
roleBindingLabels[k] = v
}
err = controllerutil.SetControllerReference(submarine, roleBinding, r.Scheme)
if err != nil {
r.Log.Error(err, "Set RoleBinding ControllerReference")
Expand Down
32 changes: 32 additions & 0 deletions submarine-cloud-v3/controllers/submarine_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,22 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)

var serverAdditionalLabels = map[string]string{"app.kubernetes.io/name": serverName, "app.kubernetes.io/version": appVersion, "app.kubernetes.io/component": "server"}

func (r *SubmarineReconciler) newSubmarineServerServiceAccount(ctx context.Context, submarine *submarineapacheorgv1alpha1.Submarine) *corev1.ServiceAccount {
serviceAccount, err := ParseServiceAccountYaml(serverYamlPath)
if err != nil {
r.Log.Error(err, "ParseServiceAccountYaml")
}
serviceAccount.Namespace = submarine.Namespace
serviceAccountLabels := serviceAccount.GetLabels()
if serviceAccountLabels == nil {
serviceAccount.SetLabels(make(map[string]string))
serviceAccountLabels = serviceAccount.GetLabels()
}
for k, v := range serverAdditionalLabels {
serviceAccountLabels[k] = v
}
err = controllerutil.SetControllerReference(submarine, serviceAccount, r.Scheme)
if err != nil {
r.Log.Error(err, "Set ServiceAccount ControllerReference")
Expand All @@ -51,6 +61,14 @@ func (r *SubmarineReconciler) newSubmarineServerService(ctx context.Context, sub
r.Log.Error(err, "ParseServiceYaml")
}
service.Namespace = submarine.Namespace
serviceLabels := service.GetLabels()
if serviceLabels == nil {
service.SetLabels(make(map[string]string))
serviceLabels = service.GetLabels()
}
for k, v := range serverAdditionalLabels {
serviceLabels[k] = v
}
err = controllerutil.SetControllerReference(submarine, service, r.Scheme)
if err != nil {
r.Log.Error(err, "Set Service ControllerReference")
Expand Down Expand Up @@ -92,6 +110,20 @@ func (r *SubmarineReconciler) newSubmarineServerDeployment(ctx context.Context,
r.Log.Error(err, "ParseDeploymentYaml")
}
deployment.Namespace = submarine.Namespace
deploymentLabels := deployment.GetLabels()
if deploymentLabels == nil {
deployment.SetLabels(make(map[string]string))
deploymentLabels = deployment.GetLabels()
}
podLabels := deployment.Spec.Template.GetLabels()
if podLabels == nil {
deployment.Spec.Template.SetLabels(make(map[string]string))
podLabels = deployment.Spec.Template.GetLabels()
}
for k, v := range serverAdditionalLabels {
deploymentLabels[k] = v
podLabels[k] = v
}
err = controllerutil.SetControllerReference(submarine, deployment, r.Scheme)
if err != nil {
r.Log.Error(err, "Set Deployment ControllerReference")
Expand Down
16 changes: 16 additions & 0 deletions submarine-cloud-v3/controllers/submarine_server_rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ func (r *SubmarineReconciler) newSubmarineServerRole(ctx context.Context, submar
r.Log.Error(err, "ParseRoleYaml")
}
role.Namespace = submarine.Namespace
roleLabels := role.GetLabels()
if roleLabels == nil {
role.SetLabels(make(map[string]string))
roleLabels = role.GetLabels()
}
for k, v := range serverAdditionalLabels {
roleLabels[k] = v
}
err = controllerutil.SetControllerReference(submarine, role, r.Scheme)
if err != nil {
r.Log.Error(err, "Set Role ControllerReference")
Expand All @@ -61,6 +69,14 @@ func (r *SubmarineReconciler) newSubmarineServerRoleBinding(ctx context.Context,
r.Log.Error(err, "Set RoleBinding ControllerReference")
}
roleBinding.Namespace = submarine.Namespace
roleBindingLabels := roleBinding.GetLabels()
if roleBindingLabels == nil {
roleBinding.SetLabels(make(map[string]string))
roleBindingLabels = roleBinding.GetLabels()
}
for k, v := range serverAdditionalLabels {
roleBindingLabels[k] = v
}
err = controllerutil.SetControllerReference(submarine, roleBinding, r.Scheme)
if err != nil {
r.Log.Error(err, "Set RoleBinding ControllerReference")
Expand Down
Loading