From 608da764f9fbf35f5678ebe85373b9bddc60643c Mon Sep 17 00:00:00 2001 From: Filipe Regadas Date: Tue, 20 Jul 2021 11:19:25 +0100 Subject: [PATCH] Remove usage of embeded fields (#60) --- api/v1beta1/zz_generated.deepcopy.go | 5 +++++ controllers/flinkcluster_converter.go | 18 +++++++++--------- controllers/flinkcluster_updater.go | 14 +++++++------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 86832e6f..5e0c5d60 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -700,6 +700,11 @@ func (in *JobStatus) DeepCopyInto(out *JobStatus) { in, out := &in.CompletionTime, &out.CompletionTime *out = (*in).DeepCopy() } + if in.FailureReasons != nil { + in, out := &in.FailureReasons, &out.FailureReasons + *out = make([]string, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new JobStatus. diff --git a/controllers/flinkcluster_converter.go b/controllers/flinkcluster_converter.go index 6d2b31f4..77f66dc3 100644 --- a/controllers/flinkcluster_converter.go +++ b/controllers/flinkcluster_converter.go @@ -332,8 +332,8 @@ func getDesiredJobManagerIngress( return nil } - var clusterNamespace = flinkCluster.ObjectMeta.Namespace - var clusterName = flinkCluster.ObjectMeta.Name + var clusterNamespace = flinkCluster.Namespace + var clusterName = flinkCluster.Name var jobManagerServiceName = getJobManagerServiceName(clusterName) var jobManagerServiceUIPort = intstr.FromString("ui") var ingressName = getJobManagerIngressName(clusterName) @@ -401,8 +401,8 @@ func getDesiredTaskManagerStatefulSet( return nil } - var clusterNamespace = flinkCluster.ObjectMeta.Namespace - var clusterName = flinkCluster.ObjectMeta.Name + var clusterNamespace = flinkCluster.Namespace + var clusterName = flinkCluster.Name var clusterSpec = flinkCluster.Spec var imageSpec = flinkCluster.Spec.Image var serviceAccount = clusterSpec.ServiceAccountName @@ -568,8 +568,8 @@ func getDesiredConfigMap( return nil } - var clusterNamespace = flinkCluster.ObjectMeta.Namespace - var clusterName = flinkCluster.ObjectMeta.Name + var clusterNamespace = flinkCluster.Namespace + var clusterName = flinkCluster.Name var flinkProperties = flinkCluster.Spec.FlinkProperties var jmPorts = flinkCluster.Spec.JobManager.Ports var tmPorts = flinkCluster.Spec.TaskManager.Ports @@ -645,7 +645,7 @@ func getDesiredJob(observed *ObservedClusterState) *batchv1.Job { } // Unless update has been triggered or the job needs to be restarted, keep the job to be stopped in that state. - if !(isUpdateTriggered(flinkCluster.Status) || shouldRestartJob(jobSpec.RestartPolicy, jobStatus)) { + if !isUpdateTriggered(flinkCluster.Status) && !shouldRestartJob(jobSpec.RestartPolicy, jobStatus) { // Job cancel requested or stopped already if isJobCancelRequested(*flinkCluster) || isJobStopped(jobStatus) { return nil @@ -656,8 +656,8 @@ func getDesiredJob(observed *ObservedClusterState) *batchv1.Job { var imageSpec = clusterSpec.Image var serviceAccount = clusterSpec.ServiceAccountName var jobManagerSpec = clusterSpec.JobManager - var clusterNamespace = flinkCluster.ObjectMeta.Namespace - var clusterName = flinkCluster.ObjectMeta.Name + var clusterNamespace = flinkCluster.Namespace + var clusterName = flinkCluster.Name var jobName = getJobName(clusterName) var jobManagerServiceName = clusterName + "-jobmanager" var jobManagerAddress = fmt.Sprintf( diff --git a/controllers/flinkcluster_updater.go b/controllers/flinkcluster_updater.go index 7443f5d7..c1979447 100644 --- a/controllers/flinkcluster_updater.go +++ b/controllers/flinkcluster_updater.go @@ -204,7 +204,7 @@ func (updater *ClusterStatusUpdater) deriveClusterStatus( recorded.Components.ConfigMap.DeepCopyInto(&status.Components.ConfigMap) status.Components.ConfigMap.State = v1beta1.ComponentStateUpdating } else if observedConfigMap != nil { - status.Components.ConfigMap.Name = observedConfigMap.ObjectMeta.Name + status.Components.ConfigMap.Name = observedConfigMap.Name status.Components.ConfigMap.State = v1beta1.ComponentStateReady } else if recorded.Components.ConfigMap.Name != "" { status.Components.ConfigMap = @@ -220,7 +220,7 @@ func (updater *ClusterStatusUpdater) deriveClusterStatus( recorded.Components.JobManagerStatefulSet.DeepCopyInto(&status.Components.JobManagerStatefulSet) status.Components.JobManagerStatefulSet.State = v1beta1.ComponentStateUpdating } else if observedJmStatefulSet != nil { - status.Components.JobManagerStatefulSet.Name = observedJmStatefulSet.ObjectMeta.Name + status.Components.JobManagerStatefulSet.Name = observedJmStatefulSet.Name status.Components.JobManagerStatefulSet.State = getStatefulSetState(observedJmStatefulSet) if status.Components.JobManagerStatefulSet.State == v1beta1.ComponentStateReady { runningComponents++ @@ -269,7 +269,7 @@ func (updater *ClusterStatusUpdater) deriveClusterStatus( status.Components.JobManagerService = v1beta1.JobManagerServiceStatus{ - Name: observedJmService.ObjectMeta.Name, + Name: observedJmService.Name, State: state, NodePort: nodePort, LoadBalancerIngress: loadBalancerIngress, @@ -352,7 +352,7 @@ func (updater *ClusterStatusUpdater) deriveClusterStatus( status.Components.JobManagerIngress = &v1beta1.JobManagerIngressStatus{ - Name: observedJmIngress.ObjectMeta.Name, + Name: observedJmIngress.Name, State: state, URLs: urls, } @@ -372,7 +372,7 @@ func (updater *ClusterStatusUpdater) deriveClusterStatus( status.Components.TaskManagerStatefulSet.State = v1beta1.ComponentStateUpdating } else if observedTmStatefulSet != nil { status.Components.TaskManagerStatefulSet.Name = - observedTmStatefulSet.ObjectMeta.Name + observedTmStatefulSet.Name status.Components.TaskManagerStatefulSet.State = getStatefulSetState(observedTmStatefulSet) if status.Components.TaskManagerStatefulSet.State == @@ -388,7 +388,7 @@ func (updater *ClusterStatusUpdater) deriveClusterStatus( } // (Optional) Job. - var jobStatus = updater.getJobStatus() + var jobStatus = updater.deriveJobStatus() status.Components.Job = jobStatus // Derive the new cluster state. @@ -695,7 +695,7 @@ func (updater *ClusterStatusUpdater) getFlinkJobID() *string { return nil } -func (updater *ClusterStatusUpdater) getJobStatus() *v1beta1.JobStatus { +func (updater *ClusterStatusUpdater) deriveJobStatus() *v1beta1.JobStatus { var observed = updater.observed var observedJob = updater.observed.job var observedFlinkJob = updater.observed.flinkJobStatus.flinkJob