Skip to content

Commit

Permalink
feat: use kurtosis service name as the kubernetes service name (#713)
Browse files Browse the repository at this point in the history
## Description:
With this change, the Kubernetes service (and pod) name is now set as
the _Kurtosis service name_ and we are moving away from randomly
assigned names that followed the template `user-service-<uuid>`.
Instead, Kubernetes services (and pods) will be named after the Kurtosis
service, e.g. `webserver`.

The motivation behind this change is that Kubernetes services (that
operate inside the same namespace) will at times need to communicate
with each other using their respective hostnames. In Kubernetes,
hostnames originate from the Kubernetes service name and are managed by
CoreDNS. From a Kurtosis perspective, this is fine as long as you can
spin up your Kurtosis service, and thereafter wire in the assigned
hostname into other services that need to know what the name was.
However, at times this is not practical, particularly if the service
need to be spun up with information such as the names of other hosts
that in turn depend on each other in a circular fashion (a chicken-egg
style problem).

With this change, Kubernetes services can depend on the Kubernetes set
hostname matching the Kurtosis service name (just like it works when
running on the Docker backend), thus enabling the services to
deterministically resolve the names of other services, prior to actual
run-time.

In the next PR, I'll add a regex to ensure that the Kurtosis service
name will not take a form that is not supported by Kubernetes and
docker.

## Is this change user facing?
NO
  • Loading branch information
adschwartz committed Jun 13, 2023
1 parent faffc07 commit b0d6b8e
Showing 1 changed file with 21 additions and 20 deletions.
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_annotation_value"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_key"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_label_value"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_object_name"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/kubernetes_port_spec_serializer"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_key_consts"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/kubernetes/object_attributes_provider/label_value_consts"
Expand All @@ -18,8 +19,7 @@ import (
)

const (
namespacePrefix = "kurtosis-enclave"
userServicePrefix = "user-service"
namespacePrefix = "kurtosis-enclave"
)

type KubernetesEnclaveObjectAttributesProvider interface {
Expand Down Expand Up @@ -127,14 +127,8 @@ func (provider *kubernetesEnclaveObjectAttributesProviderImpl) ForNetworkingSide
func (provider *kubernetesEnclaveObjectAttributesProviderImpl) ForUserServiceService(
serviceUUID service.ServiceUUID,
serviceName service.ServiceName,
) (
KubernetesObjectAttributes,
error,
) {
name, err := getCompositeKubernetesObjectName([]string{
userServicePrefix,
string(serviceUUID),
})
) (KubernetesObjectAttributes, error) {
name, err := getKubernetesObjectName(serviceName)
if err != nil {
return nil, stacktrace.Propagate(err, "Failed to get name for user service service.")
}
Expand Down Expand Up @@ -162,14 +156,11 @@ func (provider *kubernetesEnclaveObjectAttributesProviderImpl) ForUserServiceSer
}

func (provider *kubernetesEnclaveObjectAttributesProviderImpl) ForUserServicePod(
uuid service.ServiceUUID,
id service.ServiceName,
serviceUUID service.ServiceUUID,
serviceName service.ServiceName,
privatePorts map[string]*port_spec.PortSpec,
) (KubernetesObjectAttributes, error) {
name, err := getCompositeKubernetesObjectName([]string{
userServicePrefix,
string(uuid),
})
name, err := getKubernetesObjectName(serviceName)
if err != nil {
return nil, stacktrace.Propagate(err, "Failed to get name for user service pod")
}
Expand All @@ -179,13 +170,13 @@ func (provider *kubernetesEnclaveObjectAttributesProviderImpl) ForUserServicePod
return nil, stacktrace.Propagate(err, "An error occurred serializing the following user service port specs to a string for storing in the ports label: %+v", privatePorts)
}

labels, err := provider.getLabelsForEnclaveObjectWithIDAndGUID(string(id), string(uuid))
labels, err := provider.getLabelsForEnclaveObjectWithIDAndGUID(string(serviceName), string(serviceUUID))
if err != nil {
return nil, stacktrace.Propagate(
err,
"Failed to get labels for user service pod with ID '%s' and UUID '%s'",
id,
uuid,
"Failed to get labels for user service pod with name '%s' and UUID '%s'",
serviceName,
serviceUUID,
)
}
labels[label_key_consts.KurtosisResourceTypeKubernetesLabelKey] = label_value_consts.UserServiceKurtosisResourceTypeKubernetesLabelValue
Expand All @@ -207,6 +198,16 @@ func (provider *kubernetesEnclaveObjectAttributesProviderImpl) ForUserServicePod
// Private Helper Functions
//
// ====================================================================================================
func getKubernetesObjectName(
serviceName service.ServiceName,
) (*kubernetes_object_name.KubernetesObjectName, error) {
name, err := getCompositeKubernetesObjectName(
[]string{
string(serviceName),
})
return name, err
}

func (provider *kubernetesEnclaveObjectAttributesProviderImpl) getLabelsForEnclaveObject() (map[*kubernetes_label_key.KubernetesLabelKey]*kubernetes_label_value.KubernetesLabelValue, error) {
enclaveIdLabelValue, err := kubernetes_label_value.CreateNewKubernetesLabelValue(provider.enclaveId)
if err != nil {
Expand Down

0 comments on commit b0d6b8e

Please sign in to comment.