Skip to content

Commit

Permalink
Add ability to add annotations and labels to JobManager service (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sudokamikaze authored Mar 21, 2022
1 parent 94ea8d1 commit 2749ad0
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 7 deletions.
6 changes: 6 additions & 0 deletions apis/flinkcluster/v1beta1/flinkcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ type JobManagerSpec struct {
// Currently `VPC, External` are only available for GKE.
AccessScope string `json:"accessScope,omitempty"`

// _(Optional)_ Define JobManager Service annotations for configuration.
ServiceAnnotations map[string]string `json:"ServiceAnnotations,omitempty"`

// _(Optional)_ Define JobManager Service labels for configuration.
ServiceLabels map[string]string `json:"ServiceLabels,omitempty"`

// _(Optional)_ Provide external access to JobManager UI/API.
Ingress *JobManagerIngressSpec `json:"ingress,omitempty"`

Expand Down
14 changes: 14 additions & 0 deletions apis/flinkcluster/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions config/crd/bases/flinkoperator.k8s.io_flinkclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,14 @@ spec:
type: object
jobManager:
properties:
ServiceAnnotations:
additionalProperties:
type: string
type: object
ServiceLabels:
additionalProperties:
type: string
type: object
accessScope:
type: string
extraPorts:
Expand Down
11 changes: 7 additions & 4 deletions controllers/flinkcluster/flinkcluster_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,17 @@ func newJobManagerService(flinkCluster *v1beta1.FlinkCluster) *corev1.Service {
var jobManagerServiceName = getJobManagerServiceName(clusterName)
var podLabels = getComponentLabels(flinkCluster, "jobmanager")
podLabels = mergeLabels(podLabels, jobManagerSpec.PodLabels)
var serviceLabels = mergeLabels(podLabels, getRevisionHashLabels(&flinkCluster.Status.Revision))
var serviceLabels = mergeLabels(jobManagerSpec.ServiceLabels, getRevisionHashLabels(&flinkCluster.Status.Revision))
var serviceAnnotations = jobManagerSpec.ServiceAnnotations

var jobManagerService = &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Namespace: clusterNamespace,
Name: jobManagerServiceName,
OwnerReferences: []metav1.OwnerReference{
ToOwnerReference(flinkCluster)},
Labels: serviceLabels,
Labels: serviceLabels,
Annotations: serviceAnnotations,
},
Spec: corev1.ServiceSpec{
Selector: podLabels,
Expand All @@ -294,11 +297,11 @@ func newJobManagerService(flinkCluster *v1beta1.FlinkCluster) *corev1.Service {
jobManagerService.Spec.Type = corev1.ServiceTypeClusterIP
case v1beta1.AccessScopeVPC:
jobManagerService.Spec.Type = corev1.ServiceTypeLoadBalancer
jobManagerService.Annotations =
jobManagerService.Annotations = mergeLabels(serviceAnnotations,
map[string]string{
"networking.gke.io/load-balancer-type": "Internal",
"networking.gke.io/internal-load-balancer-allow-global-access": "true",
}
})
case v1beta1.AccessScopeExternal:
jobManagerService.Spec.Type = corev1.ServiceTypeLoadBalancer
case v1beta1.AccessScopeNodePort:
Expand Down
3 changes: 0 additions & 3 deletions controllers/flinkcluster/flinkcluster_converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,6 @@ func TestGetDesiredClusterState(t *testing.T) {
Name: "flinkjobcluster-sample-jobmanager",
Namespace: "default",
Labels: map[string]string{
"app": "flink",
"cluster": "flinkjobcluster-sample",
"component": "jobmanager",
RevisionNameLabel: "flinkjobcluster-sample-85dc8f749",
},
Annotations: map[string]string{
Expand Down
8 changes: 8 additions & 0 deletions helm-chart/flink-operator/templates/flink-cluster-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,14 @@ spec:
properties:
accessScope:
type: string
ServiceAnnotations:
additionalProperties:
type: string
type: object
ServiceLabels:
additionalProperties:
type: string
type: object
extraPorts:
items:
properties:
Expand Down

0 comments on commit 2749ad0

Please sign in to comment.