Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Commit

Permalink
Allow setting ServiceType and ClusterIP (#273)
Browse files Browse the repository at this point in the history
Resolves: #269

Signed-off-by: Sergio Arroutbi <[email protected]>
  • Loading branch information
sarroutbi authored Mar 26, 2024
1 parent 4954510 commit 311b852
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 3 deletions.
4 changes: 4 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Code generated by tool. DO NOT EDIT.
# This file is used to track the info used to scaffold your project
# and allow the plugins properly work.
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: redhat.com
layout:
- go.kubebuilder.io/v3
Expand Down
10 changes: 10 additions & 0 deletions api/v1alpha1/tangserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ type TangServerSpec struct {
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Required Active Key Pairs (1 by default)"
// +optional
RequiredActiveKeyPairs uint32 `json:"requiredActiveKeyPairs,omitempty"`

// ServiceType
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="ServiceType (LoadBalancer by default)"
// +optional
ServiceType string `json:"serviceType,omitempty"`

// ClusterIP
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="ClusterIP (empty by default)"
// +optional
ClusterIP string `json:"clusterIP,omitempty"`
}

// ResourcesRequest contains the struct to provide resources requests to Tang Server
Expand Down
6 changes: 6 additions & 0 deletions bundle/manifests/daemons.redhat.com_tangservers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ spec:
spec:
description: TangServerSpec defines the desired state of TangServer
properties:
clusterIP:
description: ClusterIP
type: string
healthScript:
description: HealthScript is the script to run for healthiness/readiness
type: string
Expand Down Expand Up @@ -148,6 +151,9 @@ spec:
for traffic
format: int32
type: integer
serviceType:
description: ServiceType
type: string
version:
description: Version is the version of the TangServer container to
use (empty=>latest)
Expand Down
8 changes: 7 additions & 1 deletion bundle/manifests/tang-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ metadata:
}
]
capabilities: Basic Install
createdAt: "2024-01-09T09:15:11Z"
createdAt: "2024-03-26T11:07:45Z"
operators.operatorframework.io/builder: operator-sdk-v1.33.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
name: tang-operator.v1.0.7
Expand All @@ -50,6 +50,9 @@ spec:
- kind: Service
version: v1
specDescriptors:
- description: ClusterIP
displayName: ClusterIP (empty by default)
path: clusterIP
- description: HealthScript is the script to run for healthiness/readiness
displayName: Health Script to execute
path: healthScript
Expand Down Expand Up @@ -91,6 +94,9 @@ spec:
- description: ServiceListenPort is the port where service will listen for traffic
displayName: Port where service will listen
path: serviceListenPort
- description: ServiceType
displayName: ServiceType (LoadBalancer by default)
path: serviceType
- description: Version is the version of the TangServer container to use (empty=>latest)
displayName: Image Version of Container to deploy
path: version
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/daemons.redhat.com_tangservers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ spec:
spec:
description: TangServerSpec defines the desired state of TangServer
properties:
clusterIP:
description: ClusterIP
type: string
healthScript:
description: HealthScript is the script to run for healthiness/readiness
type: string
Expand Down Expand Up @@ -149,6 +152,9 @@ spec:
for traffic
format: int32
type: integer
serviceType:
description: ServiceType
type: string
version:
description: Version is the version of the TangServer container to
use (empty=>latest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ spec:
kind: TangServer
name: tangservers.daemons.redhat.com
specDescriptors:
- description: ClusterIP
displayName: ClusterIP (empty by default)
path: clusterIP
- description: HealthScript is the script to run for healthiness/readiness
displayName: Health Script to execute
path: healthScript
Expand Down Expand Up @@ -56,6 +59,9 @@ spec:
- description: ServiceListenPort is the port where service will listen for traffic
displayName: Port where service will listen
path: serviceListenPort
- description: ServiceType
displayName: ServiceType (LoadBalancer by default)
path: serviceType
- description: Version is the version of the TangServer container to use (empty=>latest)
displayName: Image Version of Container to deploy
path: version
Expand Down
21 changes: 20 additions & 1 deletion controllers/tangserver_controller_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ func getServicePort(tangserver *daemonsv1alpha1.TangServer) uint32 {
return servicePort
}

// getServiceType function returns the service type depending on CR information
func getServiceType(tangserver *daemonsv1alpha1.TangServer) corev1.ServiceType {
if tangserver.Spec.ServiceType == "ClusterIP" {
return corev1.ServiceTypeClusterIP
}
if tangserver.Spec.ServiceType == "NodePort" {
return corev1.ServiceTypeNodePort
}
if tangserver.Spec.ServiceType == "ExternalName" {
return corev1.ServiceTypeExternalName
}
return corev1.ServiceTypeLoadBalancer
}

func getClusterIP(tangserver *daemonsv1alpha1.TangServer) string {
return tangserver.Spec.ClusterIP
}

// getService function returns correctly created service
func getService(tangserver *daemonsv1alpha1.TangServer) *corev1.Service {
GetLogInstance().Info("getService")
Expand All @@ -67,7 +85,7 @@ func getService(tangserver *daemonsv1alpha1.TangServer) *corev1.Service {
Labels: labels,
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeLoadBalancer,
Type: getServiceType(tangserver),
Selector: labels,
Ports: []corev1.ServicePort{
{
Expand All @@ -76,6 +94,7 @@ func getService(tangserver *daemonsv1alpha1.TangServer) *corev1.Service {
TargetPort: intstr.FromInt(int(getPodListenPort(tangserver))),
},
},
ClusterIP: getClusterIP(tangserver),
},
}
}
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: nbde
12 changes: 12 additions & 0 deletions operator_configs/none-cluster-ip/daemons_v1alpha1_pv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: tangserver-pvc
namespace: nbde
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
14 changes: 14 additions & 0 deletions operator_configs/none-cluster-ip/daemons_v1alpha1_tangserver.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
apiVersion: daemons.redhat.com/v1alpha1
kind: TangServer
metadata:
name: tangserver-none-cluster-ip
namespace: nbde
finalizers:
- finalizer.daemons.tangserver.redhat.com
spec:
replicas: 1
image: "quay.io/sec-eng-special/fedora_tang_server"
version: "latest"
clusterIP: "None"
serviceType: "ClusterIP"

0 comments on commit 311b852

Please sign in to comment.