Skip to content

Commit

Permalink
Merge pull request #296 from peng9808/main
Browse files Browse the repository at this point in the history
Fix the bug of reinstallation
  • Loading branch information
peng9808 authored Jul 31, 2024
2 parents 7e54ab7 + 0e39b92 commit 9a302ea
Show file tree
Hide file tree
Showing 22 changed files with 80 additions and 48 deletions.
7 changes: 4 additions & 3 deletions controllers/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,13 @@ func (r *ClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
// status.installedCRDs true bool value will cause hwameistor crds not updated when upgrade,
// so we turn status.installedCRDS to false bool value here once spec generation changed.
// That will ensure hwameistor crds updating not missed when upgrading.
if r.ClusterSpecGeneration != newInstance.Generation && newInstance.Status.InstalledCRDS{
// Upgrade crd when operator restarts
if r.ClusterSpecGeneration == 0 && newInstance.Status.InstalledCRDS {
log.Infof("cached cluster spec generation:%v, gotten cluster generation: %v", r.ClusterSpecGeneration, newInstance.Generation)
log.Infof("going to set status.installedCRDS to false bool value")
newInstance.Status.InstalledCRDS = false
if err := r.Client.Status().Update(ctx, newInstance); err != nil {
log.Errorf("Update status err: %v", err)
log.Errorf("Update InstalledCRDS=false status err: %v", err)
return ctrl.Result{}, err
}
r.ClusterSpecGeneration = newInstance.Generation
Expand All @@ -134,7 +135,7 @@ func (r *ClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
}
newInstance.Status.InstalledCRDS = true
if err := r.Client.Status().Update(ctx, newInstance); err != nil {
log.Errorf("Update status err: %v", err)
log.Errorf("Update InstalledCRDS=true status err: %v", err)
return ctrl.Result{}, err
}
return ctrl.Result{}, nil
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"
"path"
"runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"strings"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
Expand Down Expand Up @@ -76,6 +77,7 @@ func main() {
kubeconfig.Set(ctrl.GetConfigOrDie())

mgr, err := ctrl.NewManager(kubeconfig.Get(), ctrl.Options{
ClientDisableCacheFor: []client.Object{&hwameistoroperatorv1alpha1.Cluster{}},
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
Expand Down
31 changes: 18 additions & 13 deletions pkg/install/admissioncontroller/admission_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package admissioncontroller
import (
"context"
"errors"
"k8s.io/apimachinery/pkg/runtime/schema"
"reflect"
"time"

Expand Down Expand Up @@ -115,17 +116,19 @@ var admissionController = appsv1.Deployment{
},
}

func SetAdmissionController(clusterInstance *hwameistoriov1alpha1.Cluster) {
admissionController.Namespace = clusterInstance.Spec.TargetNamespace
admissionController.OwnerReferences = append(admissionController.OwnerReferences, *metav1.NewControllerRef(clusterInstance, clusterInstance.GroupVersionKind()))
func SetAdmissionController(clusterInstance *hwameistoriov1alpha1.Cluster) *appsv1.Deployment {

resourceCreate := admissionController.DeepCopy()
resourceCreate.Namespace = clusterInstance.Spec.TargetNamespace
resourceCreate.OwnerReferences = append(resourceCreate.OwnerReferences, *metav1.NewControllerRef(clusterInstance, schema.FromAPIVersionAndKind("hwameistor.io/v1alpha1", "Cluster")))
replicas := getAdmissionControllerReplicasFromClusterInstance(clusterInstance)
admissionController.Spec.Replicas = &replicas
admissionController.Spec.Template.Spec.ServiceAccountName = clusterInstance.Spec.RBAC.ServiceAccountName
setAdmissionControllerContainers(clusterInstance)
resourceCreate.Spec.Replicas = &replicas
resourceCreate.Spec.Template.Spec.ServiceAccountName = clusterInstance.Spec.RBAC.ServiceAccountName
return setAdmissionControllerContainers(clusterInstance, resourceCreate)
}

func setAdmissionControllerContainers(clusterInstance *hwameistoriov1alpha1.Cluster) {
for i, container := range admissionController.Spec.Template.Spec.Containers {
func setAdmissionControllerContainers(clusterInstance *hwameistoriov1alpha1.Cluster, resourceCreate *appsv1.Deployment) *appsv1.Deployment {
for i, container := range resourceCreate.Spec.Template.Spec.Containers {
if container.Name == admissionControllerContainerName {
// container.Resources = *clusterInstance.Spec.AdmissionController.Controller.Resources
if resources := clusterInstance.Spec.AdmissionController.Controller.Resources; resources != nil {
Expand All @@ -152,8 +155,10 @@ func setAdmissionControllerContainers(clusterInstance *hwameistoriov1alpha1.Clus
},
}...)
}
admissionController.Spec.Template.Spec.Containers[i] = container
resourceCreate.Spec.Template.Spec.Containers[i] = container
}

return resourceCreate
}

func getAdmissionControllerContainerImageStringFromClusterInstance(clusterInstance *hwameistoriov1alpha1.Cluster) string {
Expand Down Expand Up @@ -207,21 +212,21 @@ func needOrNotToUpdateAdmissionController(cluster *hwameistoriov1alpha1.Cluster,

func (m *AdmissionControllerMaintainer) Ensure() (*hwameistoriov1alpha1.Cluster, error) {
newClusterInstance := m.ClusterInstance.DeepCopy()
SetAdmissionController(newClusterInstance)
resourceCreate := SetAdmissionController(newClusterInstance)

// ensure admission controller CA is generated
if err := m.ensureAdmissionCA(); err != nil {
log.WithError(err).Error("failed to ensure admission controller CA")
return newClusterInstance, err
}
key := types.NamespacedName{
Namespace: admissionController.Namespace,
Name: admissionController.Name,
Namespace: resourceCreate.Namespace,
Name: resourceCreate.Name,
}
var gottenAdmissionController appsv1.Deployment
if err := m.Client.Get(context.TODO(), key, &gottenAdmissionController); err != nil {
if apierrors.IsNotFound(err) {
if errCreate := m.Client.Create(context.TODO(), &admissionController); errCreate != nil {
if errCreate := m.Client.Create(context.TODO(), resourceCreate); errCreate != nil {
log.Errorf("Create AdmissionController err: %v", errCreate)
return newClusterInstance, errCreate
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/install/admissioncontroller/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ func (m *AdmissionControllerServiceMaintainer) Ensure() error {
var gottenService corev1.Service
if err := m.Client.Get(context.TODO(), key, &gottenService); err != nil {
if errors.IsNotFound(err) {
if errCreate := m.Client.Create(context.TODO(), &admissionControllerService); errCreate != nil {
resourceCreate := admissionControllerService.DeepCopy()
if errCreate := m.Client.Create(context.TODO(), resourceCreate); errCreate != nil {
log.Errorf("Create AdmissionController Service err: %v", err)
return errCreate
}
Expand Down
25 changes: 14 additions & 11 deletions pkg/install/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package apiserver
import (
"context"
"errors"
"k8s.io/apimachinery/pkg/runtime/schema"
"reflect"
"strconv"

Expand Down Expand Up @@ -95,13 +96,14 @@ var apiServer = appsv1.Deployment{
},
}

func SetApiServer(clusterInstance *hwameistoriov1alpha1.Cluster) {
apiServer.Namespace = clusterInstance.Spec.TargetNamespace
apiServer.OwnerReferences = append(apiServer.OwnerReferences, *metav1.NewControllerRef(clusterInstance, clusterInstance.GroupVersionKind()))
func SetApiServer(clusterInstance *hwameistoriov1alpha1.Cluster) *appsv1.Deployment {
resourceCreate := apiServer.DeepCopy()
resourceCreate.Namespace = clusterInstance.Spec.TargetNamespace
resourceCreate.OwnerReferences = append(resourceCreate.OwnerReferences, *metav1.NewControllerRef(clusterInstance, schema.FromAPIVersionAndKind("hwameistor.io/v1alpha1", "Cluster")))
replicas := getApiserverReplicasFromClusterInstance(clusterInstance)
apiServer.Spec.Replicas = &replicas
apiServer.Spec.Template.Spec.ServiceAccountName = clusterInstance.Spec.RBAC.ServiceAccountName
for i, container := range apiServer.Spec.Template.Spec.Containers {
resourceCreate.Spec.Replicas = &replicas
resourceCreate.Spec.Template.Spec.ServiceAccountName = clusterInstance.Spec.RBAC.ServiceAccountName
for i, container := range resourceCreate.Spec.Template.Spec.Containers {
if container.Name == apiserverContainerName {
container.Image = getApiserverContainerImageStringFromClusterInstance(clusterInstance)
if resources := clusterInstance.Spec.ApiServer.Server.Resources; resources != nil {
Expand All @@ -122,8 +124,9 @@ func SetApiServer(clusterInstance *hwameistoriov1alpha1.Cluster) {
},
}...)
}
apiServer.Spec.Template.Spec.Containers[i] = container
resourceCreate.Spec.Template.Spec.Containers[i] = container
}
return resourceCreate
}

func getApiserverContainerImageStringFromClusterInstance(clusterInstance *hwameistoriov1alpha1.Cluster) string {
Expand Down Expand Up @@ -161,15 +164,15 @@ func needOrNotToUpdateApiserver(cluster *hwameistoriov1alpha1.Cluster, gottenApi

func (m *ApiServerMaintainer) Ensure() (*hwameistoriov1alpha1.Cluster, error) {
newClusterInstance := m.ClusterInstance.DeepCopy()
SetApiServer(newClusterInstance)
resourceCreate := SetApiServer(newClusterInstance)
key := types.NamespacedName{
Namespace: apiServer.Namespace,
Name: apiServer.Name,
Namespace: resourceCreate.Namespace,
Name: resourceCreate.Name,
}
var gotten appsv1.Deployment
if err := m.Client.Get(context.TODO(), key, &gotten); err != nil {
if apierrors.IsNotFound(err) {
if errCreate := m.Client.Create(context.TODO(), &apiServer); errCreate != nil {
if errCreate := m.Client.Create(context.TODO(), resourceCreate); errCreate != nil {
log.Errorf("Create ApiServer err: %v", errCreate)
return newClusterInstance, errCreate
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/install/apiserver/apiserver_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ func (m *ApiServerServiceMaintainer) Ensure() error {
var gottenService corev1.Service
if err := m.Client.Get(context.TODO(), key, &gottenService); err != nil {
if errors.IsNotFound(err) {
if errCreate := m.Client.Create(context.TODO(), &apiServerService); errCreate != nil {
resourceCreate := apiServerService.DeepCopy()
if errCreate := m.Client.Create(context.TODO(), resourceCreate); errCreate != nil {
log.Errorf("Create ApiServer Service err: %v", err)
return errCreate
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/install/auditor/auditor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package auditor
import (
"context"
"errors"
"k8s.io/apimachinery/pkg/runtime/schema"
"reflect"

hwameistoriov1alpha1 "github.com/hwameistor/hwameistor-operator/api/v1alpha1"
Expand Down Expand Up @@ -102,7 +103,7 @@ func SetAuditor(clusterInstance *hwameistoriov1alpha1.Cluster) *appsv1.Deploymen
auditorToCreate := auditorTemplate.DeepCopy()

auditorToCreate.Namespace = clusterInstance.Spec.TargetNamespace
auditorToCreate.OwnerReferences = append(auditorToCreate.OwnerReferences, *metav1.NewControllerRef(clusterInstance, clusterInstance.GroupVersionKind()))
auditorToCreate.OwnerReferences = append(auditorToCreate.OwnerReferences, *metav1.NewControllerRef(clusterInstance, schema.FromAPIVersionAndKind("hwameistor.io/v1alpha1", "Cluster")))
replicas := getAuditorReplicasFromClusterInstance(clusterInstance)
auditorToCreate.Spec.Replicas = &replicas
auditorToCreate.Spec.Template.Spec.ServiceAccountName = clusterInstance.Spec.RBAC.ServiceAccountName
Expand Down
3 changes: 2 additions & 1 deletion pkg/install/dataloadmanager/dataloadmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
"reflect"
Expand Down Expand Up @@ -137,7 +138,7 @@ var dlmDaemonSetTemplate = appsv1.DaemonSet{

func SetDLMDaemonSet(clusterInstance *hwameistoriov1alpha1.Cluster) *appsv1.DaemonSet {
dlmDaemonSetToCreate := dlmDaemonSetTemplate.DeepCopy()
dlmDaemonSetToCreate.OwnerReferences = append(dlmDaemonSetToCreate.OwnerReferences, *metav1.NewControllerRef(clusterInstance, clusterInstance.GroupVersionKind()))
dlmDaemonSetToCreate.OwnerReferences = append(dlmDaemonSetToCreate.OwnerReferences, *metav1.NewControllerRef(clusterInstance, schema.FromAPIVersionAndKind("hwameistor.io/v1alpha1", "Cluster")))
dlmDaemonSetToCreate.Namespace = clusterInstance.Spec.TargetNamespace
dlmDaemonSetToCreate.Spec.Template.Spec.ServiceAccountName = clusterInstance.Spec.RBAC.ServiceAccountName
dlmDaemonSetToCreate = setDLMDaemonSetContainers(clusterInstance, dlmDaemonSetToCreate)
Expand Down
3 changes: 2 additions & 1 deletion pkg/install/datasetmanager/datasetmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down Expand Up @@ -80,7 +81,7 @@ func int64Ptr(i int64) *int64 { return &i }

func SetDSMDeployment(clusterInstance *hwameistoriov1alpha1.Cluster) *appsv1.Deployment {
dsmDeploymentToCreate := dsmDeploymentTemplate.DeepCopy()
dsmDeploymentToCreate.OwnerReferences = append(dsmDeploymentToCreate.OwnerReferences, *metav1.NewControllerRef(clusterInstance, clusterInstance.GroupVersionKind()))
dsmDeploymentToCreate.OwnerReferences = append(dsmDeploymentToCreate.OwnerReferences, *metav1.NewControllerRef(clusterInstance, schema.FromAPIVersionAndKind("hwameistor.io/v1alpha1", "Cluster")))
dsmDeploymentToCreate.Namespace = clusterInstance.Spec.TargetNamespace
dsmDeploymentToCreate.Spec.Template.Spec.ServiceAccountName = clusterInstance.Spec.RBAC.ServiceAccountName
dsmDeploymentToCreate = setdsmDeploymentContainers(clusterInstance, dsmDeploymentToCreate)
Expand Down
6 changes: 4 additions & 2 deletions pkg/install/evictor/evictor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package evictor
import (
"context"
"errors"
"k8s.io/apimachinery/pkg/runtime/schema"
"reflect"

hwameistoriov1alpha1 "github.com/hwameistor/hwameistor-operator/api/v1alpha1"
Expand Down Expand Up @@ -73,7 +74,7 @@ var evictorDeployment = appsv1.Deployment{

func SetEvictor(clusterInstance *hwameistoriov1alpha1.Cluster) {
evictorDeployment.Namespace = clusterInstance.Spec.TargetNamespace
evictorDeployment.OwnerReferences = append(evictorDeployment.OwnerReferences, *metav1.NewControllerRef(clusterInstance, clusterInstance.GroupVersionKind()))
evictorDeployment.OwnerReferences = append(evictorDeployment.OwnerReferences, *metav1.NewControllerRef(clusterInstance, schema.FromAPIVersionAndKind("hwameistor.io/v1alpha1", "Cluster")))
replicas := getEvictorReplicasFromClusterInstance(clusterInstance)
evictorDeployment.Spec.Replicas = &replicas
evictorDeployment.Spec.Template.Spec.ServiceAccountName = clusterInstance.Spec.RBAC.ServiceAccountName
Expand Down Expand Up @@ -152,7 +153,8 @@ func (m *EvictorMaintainer) Ensure() (*hwameistoriov1alpha1.Cluster, error) {
var gotten appsv1.Deployment
if err := m.Client.Get(context.TODO(), key, &gotten); err != nil {
if apierrors.IsNotFound(err) {
if errCreate := m.Client.Create(context.TODO(), &evictorDeployment); errCreate != nil {
resourceCreate := evictorDeployment.DeepCopy()
if errCreate := m.Client.Create(context.TODO(), resourceCreate); errCreate != nil {
log.Errorf("Create Evictor err: %v", errCreate)
return newClusterInstance, errCreate
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/install/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package exporter
import (
"context"
"errors"
"k8s.io/apimachinery/pkg/runtime/schema"
"reflect"

hwameistoriov1alpha1 "github.com/hwameistor/hwameistor-operator/api/v1alpha1"
Expand Down Expand Up @@ -88,7 +89,7 @@ var exporter = appsv1.Deployment{

func SetExporter(clusterInstance *hwameistoriov1alpha1.Cluster) {
exporter.Namespace = clusterInstance.Spec.TargetNamespace
exporter.OwnerReferences = append(exporter.OwnerReferences, *metav1.NewControllerRef(clusterInstance, clusterInstance.GroupVersionKind()))
exporter.OwnerReferences = append(exporter.OwnerReferences, *metav1.NewControllerRef(clusterInstance, schema.FromAPIVersionAndKind("hwameistor.io/v1alpha1", "Cluster")))
replicas := getExporterReplicasFromClusterInstance(clusterInstance)
exporter.Spec.Replicas = &replicas
exporter.Spec.Template.Spec.ServiceAccountName = clusterInstance.Spec.RBAC.ServiceAccountName
Expand Down Expand Up @@ -146,7 +147,8 @@ func (m *ExporterMaintainer) Ensure() (*hwameistoriov1alpha1.Cluster, error) {
var gotten appsv1.Deployment
if err := m.Client.Get(context.TODO(), key, &gotten); err != nil {
if apierrors.IsNotFound(err) {
if errCreate := m.Client.Create(context.TODO(), &exporter); errCreate != nil {
resourceCreate := exporter.DeepCopy()
if errCreate := m.Client.Create(context.TODO(), resourceCreate); errCreate != nil {
log.Errorf("Create Exporter err: %v", errCreate)
return newClusterInstance, errCreate
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/install/exporter/exporter_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ func (m *ExporterServiceMaintainer) Ensure() error {
var gottenService corev1.Service
if err := m.Client.Get(context.TODO(), key, &gottenService); err != nil {
if errors.IsNotFound(err) {
if errCreate := m.Client.Create(context.TODO(), &exporterService); errCreate != nil {
resourceCreate := exporterService.DeepCopy()
if errCreate := m.Client.Create(context.TODO(), resourceCreate); errCreate != nil {
log.Errorf("Create Exporter Service err: %v", err)
return errCreate
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/install/failoverassistant/failover_assistant.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package failoverassistant
import (
"context"
"errors"
"k8s.io/apimachinery/pkg/runtime/schema"
"reflect"

hwameistoriov1alpha1 "github.com/hwameistor/hwameistor-operator/api/v1alpha1"
Expand Down Expand Up @@ -102,7 +103,7 @@ func SetFailoverAssistant(clusterInstance *hwameistoriov1alpha1.Cluster) *appsv1
deployToCreate := failoverAssistantTemplate.DeepCopy()

deployToCreate.Namespace = clusterInstance.Spec.TargetNamespace
deployToCreate.OwnerReferences = append(deployToCreate.OwnerReferences, *metav1.NewControllerRef(clusterInstance, clusterInstance.GroupVersionKind()))
deployToCreate.OwnerReferences = append(deployToCreate.OwnerReferences, *metav1.NewControllerRef(clusterInstance, schema.FromAPIVersionAndKind("hwameistor.io/v1alpha1", "Cluster")))
replicas := getFailoverAssistantReplicasFromClusterInstance(clusterInstance)
deployToCreate.Spec.Replicas = &replicas
deployToCreate.Spec.Template.Spec.ServiceAccountName = clusterInstance.Spec.RBAC.ServiceAccountName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ldmcsicontroller
import (
"context"
"errors"
"k8s.io/apimachinery/pkg/runtime/schema"
"reflect"

hwameistoriov1alpha1 "github.com/hwameistor/hwameistor-operator/api/v1alpha1"
Expand Down Expand Up @@ -133,7 +134,7 @@ var ldmCSIController = appsv1.Deployment{
func SetLDMCSIController(clusterInstance *hwameistoriov1alpha1.Cluster) *appsv1.Deployment {
ldmCSIControllerToCreate := ldmCSIController.DeepCopy()
ldmCSIControllerToCreate.Namespace = clusterInstance.Spec.TargetNamespace
ldmCSIControllerToCreate.OwnerReferences = append(ldmCSIControllerToCreate.OwnerReferences, *metav1.NewControllerRef(clusterInstance, clusterInstance.GroupVersionKind()))
ldmCSIControllerToCreate.OwnerReferences = append(ldmCSIControllerToCreate.OwnerReferences, *metav1.NewControllerRef(clusterInstance, schema.FromAPIVersionAndKind("hwameistor.io/v1alpha1", "Cluster")))
// ldmCSIController.Spec.Template.Spec.PriorityClassName = clusterInstance.Spec.LocalDiskManager.CSI.Controller.Common.PriorityClassName
replicas := getReplicasFromClusterInstance(clusterInstance)
ldmCSIControllerToCreate.Spec.Replicas = &replicas
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package localdiskactioncontroller
import (
"context"
"errors"
"k8s.io/apimachinery/pkg/runtime/schema"
"reflect"

hwameistoriov1alpha1 "github.com/hwameistor/hwameistor-operator/api/v1alpha1"
Expand Down Expand Up @@ -101,7 +102,7 @@ func SetActionController(clusterInstance *hwameistoriov1alpha1.Cluster) *appsv1.
deployToCreate := deployTemplate.DeepCopy()

deployToCreate.Namespace = clusterInstance.Spec.TargetNamespace
deployToCreate.OwnerReferences = append(deployToCreate.OwnerReferences, *metav1.NewControllerRef(clusterInstance, clusterInstance.GroupVersionKind()))
deployToCreate.OwnerReferences = append(deployToCreate.OwnerReferences, *metav1.NewControllerRef(clusterInstance, schema.FromAPIVersionAndKind("hwameistor.io/v1alpha1", "Cluster")))
deployToCreate.Spec.Template.Spec.ServiceAccountName = clusterInstance.Spec.RBAC.ServiceAccountName
for i, container := range deployToCreate.Spec.Template.Spec.Containers {
if container.Name == ldaContainerName {
Expand Down
3 changes: 2 additions & 1 deletion pkg/install/localdiskmanager/localdiskmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package localdiskmanager

import (
"context"
"k8s.io/apimachinery/pkg/runtime/schema"
"reflect"

hwameistoriov1alpha1 "github.com/hwameistor/hwameistor-operator/api/v1alpha1"
Expand Down Expand Up @@ -223,7 +224,7 @@ var ldmDaemonSet = appsv1.DaemonSet{
func SetLDMDaemonSet(clusterInstance *hwameistoriov1alpha1.Cluster) *appsv1.DaemonSet {
ldmDaemonSetToCreate := ldmDaemonSet.DeepCopy()

ldmDaemonSetToCreate.OwnerReferences = append(ldmDaemonSetToCreate.OwnerReferences, *metav1.NewControllerRef(clusterInstance, clusterInstance.GroupVersionKind()))
ldmDaemonSetToCreate.OwnerReferences = append(ldmDaemonSetToCreate.OwnerReferences, *metav1.NewControllerRef(clusterInstance, schema.FromAPIVersionAndKind("hwameistor.io/v1alpha1", "Cluster")))
ldmDaemonSetToCreate.Namespace = clusterInstance.Spec.TargetNamespace

newClusterInstance := clusterInstance.DeepCopy()
Expand Down
Loading

0 comments on commit 9a302ea

Please sign in to comment.