diff --git a/PROJECT b/PROJECT index 52af5bdc..4bea3f02 100644 --- a/PROJECT +++ b/PROJECT @@ -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 diff --git a/api/v1alpha1/tangserver_types.go b/api/v1alpha1/tangserver_types.go index 81ba38b8..e43aa3f3 100644 --- a/api/v1alpha1/tangserver_types.go +++ b/api/v1alpha1/tangserver_types.go @@ -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 diff --git a/bundle/manifests/daemons.redhat.com_tangservers.yaml b/bundle/manifests/daemons.redhat.com_tangservers.yaml index 5c19a831..897a2868 100644 --- a/bundle/manifests/daemons.redhat.com_tangservers.yaml +++ b/bundle/manifests/daemons.redhat.com_tangservers.yaml @@ -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 @@ -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) diff --git a/bundle/manifests/tang-operator.clusterserviceversion.yaml b/bundle/manifests/tang-operator.clusterserviceversion.yaml index aac19b67..d22ddcf2 100644 --- a/bundle/manifests/tang-operator.clusterserviceversion.yaml +++ b/bundle/manifests/tang-operator.clusterserviceversion.yaml @@ -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 @@ -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 @@ -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 diff --git a/config/crd/bases/daemons.redhat.com_tangservers.yaml b/config/crd/bases/daemons.redhat.com_tangservers.yaml index b6c3542a..7dd39bc9 100644 --- a/config/crd/bases/daemons.redhat.com_tangservers.yaml +++ b/config/crd/bases/daemons.redhat.com_tangservers.yaml @@ -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 @@ -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) diff --git a/config/manifests/bases/tang-operator.clusterserviceversion.yaml b/config/manifests/bases/tang-operator.clusterserviceversion.yaml index c68774b4..ec4112d9 100644 --- a/config/manifests/bases/tang-operator.clusterserviceversion.yaml +++ b/config/manifests/bases/tang-operator.clusterserviceversion.yaml @@ -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 @@ -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 diff --git a/controllers/tangserver_controller_service.go b/controllers/tangserver_controller_service.go index 1c038e64..d96e9deb 100644 --- a/controllers/tangserver_controller_service.go +++ b/controllers/tangserver_controller_service.go @@ -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") @@ -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{ { @@ -76,6 +94,7 @@ func getService(tangserver *daemonsv1alpha1.TangServer) *corev1.Service { TargetPort: intstr.FromInt(int(getPodListenPort(tangserver))), }, }, + ClusterIP: getClusterIP(tangserver), }, } } diff --git a/go.sum b/go.sum index f367a6d7..db28c1ca 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/operator_configs/none-cluster-ip/daemons_v1alpha1_namespace.yaml b/operator_configs/none-cluster-ip/daemons_v1alpha1_namespace.yaml new file mode 100644 index 00000000..d19def9c --- /dev/null +++ b/operator_configs/none-cluster-ip/daemons_v1alpha1_namespace.yaml @@ -0,0 +1,5 @@ +--- +apiVersion: v1 +kind: Namespace +metadata: + name: nbde diff --git a/operator_configs/none-cluster-ip/daemons_v1alpha1_pv.yaml b/operator_configs/none-cluster-ip/daemons_v1alpha1_pv.yaml new file mode 100644 index 00000000..4b46edcd --- /dev/null +++ b/operator_configs/none-cluster-ip/daemons_v1alpha1_pv.yaml @@ -0,0 +1,12 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: tangserver-pvc + namespace: nbde +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi diff --git a/operator_configs/none-cluster-ip/daemons_v1alpha1_tangserver.yaml b/operator_configs/none-cluster-ip/daemons_v1alpha1_tangserver.yaml new file mode 100644 index 00000000..e24453a8 --- /dev/null +++ b/operator_configs/none-cluster-ip/daemons_v1alpha1_tangserver.yaml @@ -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"