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

Add labels and loadBalancerClass to the cluster.service spec #821

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions api/k0smotron.io/v1beta1/k0smotroncluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ type ServiceSpec struct {
// Annotations defines extra annotations to be added to the service.
//+kubebuilder:validation:Optional
Annotations map[string]string `json:"annotations,omitempty"`
// Labels defines extra labels to be added to the service.
//+kubebuilder:validation:Optional
Labels map[string]string `json:"labels,omitempty"`
// LoadBalancerClass defines the load balancer class to be used for the service. Used only when service type is LoadBalancer.
//+kubebuilder:validation:Optional
LoadBalancerClass *string `json:"loadBalancerClass,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
12 changes: 12 additions & 0 deletions api/k0smotron.io/v1beta1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -3942,6 +3942,15 @@ spec:
KonnectivityPort defines the konnectivity port. If empty k0smotron
will pick it automatically.
type: integer
labels:
additionalProperties:
type: string
description: Labels defines extra labels to be added to the service.
type: object
loadBalancerClass:
description: LoadBalancerClass defines the load balancer class
to be used for the service. Used only when service type is LoadBalancer.
type: string
type:
default: ClusterIP
description: Service Type string describes ingress methods for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4020,6 +4020,17 @@ spec:
KonnectivityPort defines the konnectivity port. If empty k0smotron
will pick it automatically.
type: integer
labels:
additionalProperties:
type: string
description: Labels defines extra labels to be added to
the service.
type: object
loadBalancerClass:
description: LoadBalancerClass defines the load balancer
class to be used for the service. Used only when service
type is LoadBalancer.
type: string
type:
default: ClusterIP
description: Service Type string describes ingress methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3945,6 +3945,15 @@ spec:
KonnectivityPort defines the konnectivity port. If empty k0smotron
will pick it automatically.
type: integer
labels:
additionalProperties:
type: string
description: Labels defines extra labels to be added to the service.
type: object
loadBalancerClass:
description: LoadBalancerClass defines the load balancer class
to be used for the service. Used only when service type is LoadBalancer.
type: string
type:
default: ClusterIP
description: Service Type string describes ingress methods for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3942,6 +3942,15 @@ spec:
KonnectivityPort defines the konnectivity port. If empty k0smotron
will pick it automatically.
type: integer
labels:
additionalProperties:
type: string
description: Labels defines extra labels to be added to the service.
type: object
loadBalancerClass:
description: LoadBalancerClass defines the load balancer class
to be used for the service. Used only when service type is LoadBalancer.
type: string
type:
default: ClusterIP
description: Service Type string describes ingress methods for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4020,6 +4020,17 @@ spec:
KonnectivityPort defines the konnectivity port. If empty k0smotron
will pick it automatically.
type: integer
labels:
additionalProperties:
type: string
description: Labels defines extra labels to be added to
the service.
type: object
loadBalancerClass:
description: LoadBalancerClass defines the load balancer
class to be used for the service. Used only when service
type is LoadBalancer.
type: string
type:
default: ClusterIP
description: Service Type string describes ingress methods
Expand Down
9 changes: 9 additions & 0 deletions config/crd/bases/k0smotron.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3945,6 +3945,15 @@ spec:
KonnectivityPort defines the konnectivity port. If empty k0smotron
will pick it automatically.
type: integer
labels:
additionalProperties:
type: string
description: Labels defines extra labels to be added to the service.
type: object
loadBalancerClass:
description: LoadBalancerClass defines the load balancer class
to be used for the service. Used only when service type is LoadBalancer.
type: string
type:
default: ClusterIP
description: Service Type string describes ingress methods for
Expand Down
42 changes: 42 additions & 0 deletions docs/resource-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -10949,6 +10949,20 @@ will pick it automatically.<br/>
<i>Default</i>: 30132<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>labels</b></td>
<td>map[string]string</td>
<td>
Labels defines extra labels to be added to the service.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>loadBalancerClass</b></td>
<td>string</td>
<td>
LoadBalancerClass defines the load balancer class to be used for the service. Used only when service type is LoadBalancer.<br/>
</td>
<td>false</td>
</tr></tbody>
</table>

Expand Down Expand Up @@ -19370,6 +19384,20 @@ will pick it automatically.<br/>
<i>Default</i>: 30132<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>labels</b></td>
<td>map[string]string</td>
<td>
Labels defines extra labels to be added to the service.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>loadBalancerClass</b></td>
<td>string</td>
<td>
LoadBalancerClass defines the load balancer class to be used for the service. Used only when service type is LoadBalancer.<br/>
</td>
<td>false</td>
</tr></tbody>
</table>

Expand Down Expand Up @@ -43706,6 +43734,20 @@ will pick it automatically.<br/>
<i>Default</i>: 30132<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>labels</b></td>
<td>map[string]string</td>
<td>
Labels defines extra labels to be added to the service.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>loadBalancerClass</b></td>
<td>string</td>
<td>
LoadBalancerClass defines the load balancer class to be used for the service. Used only when service type is LoadBalancer.<br/>
</td>
<td>false</td>
</tr></tbody>
</table>

Expand Down
16 changes: 14 additions & 2 deletions internal/controller/k0smotron.io/k0smotroncluster_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ package k0smotronio
import (
"context"
"fmt"
"github.com/k0sproject/k0smotron/internal/controller/util"
"time"

"github.com/k0sproject/k0smotron/internal/controller/util"

km "github.com/k0sproject/k0smotron/api/k0smotron.io/v1beta1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -86,7 +87,14 @@ func (r *ClusterReconciler) generateService(kmc *km.Cluster) v1.Service {
})
}

labels := labelsForCluster(kmc)
// Copy both Cluster level labels and Service labels
labels := map[string]string{}
for k, v := range labelsForCluster(kmc) {
labels[k] = v
}
for k, v := range kmc.Spec.Service.Labels {
labels[k] = v
}

// Copy both Cluster level annotations and Service annotations
annotations := map[string]string{}
Expand Down Expand Up @@ -115,6 +123,10 @@ func (r *ClusterReconciler) generateService(kmc *km.Cluster) v1.Service {
},
}

if kmc.Spec.Service.Type == v1.ServiceTypeLoadBalancer {
svc.Spec.LoadBalancerClass = kmc.Spec.Service.LoadBalancerClass
}

return svc
}

Expand Down
Loading
Loading