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

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lostbean committed Oct 3, 2024
1 parent 4e601e8 commit b5a83b3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 26 deletions.
41 changes: 16 additions & 25 deletions kontrol-service/engine/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,18 @@ func processGatewayAndRouteConfigs(gatewayConfigs []apitypes.GatewayConfig, rout

func getDeploymentForService(
serviceConfig apitypes.ServiceConfig,
workloadConfigs []apitypes.DeploymentConfig,
deploymentConfigs []apitypes.DeploymentConfig,
) *apitypes.DeploymentConfig {
service := serviceConfig.Service
workload, foundworkload := lo.Find(workloadConfigs, func(workloadConfig apitypes.DeploymentConfig) bool {
workload, foundworkload := lo.Find(deploymentConfigs, func(workloadConfig apitypes.DeploymentConfig) bool {
deploymentLabels := workloadConfig.Deployment.GetLabels()
matchSelectors := true
for key, value := range service.Spec.Selector {
label, found := deploymentLabels[key]
if !found || value != label {
return false
}
}
return matchSelectors
return true
})

if foundworkload {
Expand All @@ -175,19 +174,18 @@ func getDeploymentForService(

func getSatefulSetForService(
serviceConfig apitypes.ServiceConfig,
workloadConfigs []apitypes.StatefulSetConfig,
statefulSetConfigs []apitypes.StatefulSetConfig,
) *apitypes.StatefulSetConfig {
service := serviceConfig.Service
workload, foundworkload := lo.Find(workloadConfigs, func(workloadConfig apitypes.StatefulSetConfig) bool {
workload, foundworkload := lo.Find(statefulSetConfigs, func(workloadConfig apitypes.StatefulSetConfig) bool {
workloadLabel := workloadConfig.StatefulSet.GetLabels()
matchSelectors := true
for key, value := range service.Spec.Selector {
label, found := workloadLabel[key]
if !found || value != label {
return false
}
}
return matchSelectors
return true
})

if foundworkload {
Expand Down Expand Up @@ -222,7 +220,7 @@ func processServiceConfigs(

deploymentConfig := getDeploymentForService(serviceConfig, deploymentConfigs)
statefulSetConfig := getSatefulSetForService(serviceConfig, statefulSetConfigs)
clusterTopologyService, error := newClusterTopologyServiceFromServiceConfig(serviceConfig, deploymentConfig, statefulSetConfig, version)
clusterTopologyService, error := newClusterTopologyServiceFromConfigs(serviceConfig, deploymentConfig, statefulSetConfig, version)
if error != nil {
return nil, nil, stacktrace.Propagate(error, "An error occurred creating new cluster topology service from service config '%s'", service.Name)
}
Expand Down Expand Up @@ -327,35 +325,32 @@ func newStatefulPluginsAndExternalServicesFromServiceConfig(serviceConfig apityp
return serviceStatefulPlugins, externalServices, externalServiceDependencies, nil
}

func newClusterTopologyServiceFromServiceConfig(
func newClusterTopologyServiceFromConfigs(
serviceConfig apitypes.ServiceConfig,
deploymentConfig *apitypes.DeploymentConfig,
statefulSetConfig *apitypes.StatefulSetConfig,
version string,
) (resolved.Service, error) {
service := serviceConfig.Service
serviceName := service.GetObjectMeta().GetName()
serviceAnnotations := service.GetObjectMeta().GetAnnotations()

clusterTopologyService := resolved.Service{
ServiceID: service.GetObjectMeta().GetName(),
Version: version,
ServiceSpec: &service.Spec,
}

if deploymentConfig == nil && statefulSetConfig == nil {
logrus.Warnf("Service %s has no workload", serviceName)
}

if deploymentConfig != nil && statefulSetConfig != nil {
workloads := []string{
deploymentConfig.Deployment.GetObjectMeta().GetName(),
statefulSetConfig.StatefulSet.GetObjectMeta().GetName(),
}
logrus.Error("Service %s is associated with more than one workload: %v", serviceName, workloads)
}

serviceAnnotations := service.GetObjectMeta().GetAnnotations()

clusterTopologyService := resolved.Service{
ServiceID: service.GetObjectMeta().GetName(),
Version: version,
ServiceSpec: &service.Spec,
}

if deploymentConfig != nil {
workload := kardinal.NewDeploymentWorkloadSpec(deploymentConfig.Deployment.Spec)
clusterTopologyService.WorkloadSpec = &workload
Expand All @@ -365,12 +360,8 @@ func newClusterTopologyServiceFromServiceConfig(
clusterTopologyService.WorkloadSpec = &workload
}

if clusterTopologyService.WorkloadSpec == nil {
return clusterTopologyService, stacktrace.NewError("Service %s has no workload", serviceName)
}

// Set default for IsStateful to true if the workload is a StatefulSet, otherwise false
clusterTopologyService.IsExternal = clusterTopologyService.WorkloadSpec.IsStatefulSet()
clusterTopologyService.IsStateful = clusterTopologyService.WorkloadSpec.IsStatefulSet()

// Override the IsStateful value by manual annotations
isStateful, ok := serviceAnnotations["kardinal.dev.service/stateful"]
Expand Down
2 changes: 1 addition & 1 deletion kontrol-service/engine/flow/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func getStatefulSet(service *resolved.Service, namespace string) *appsv1.Statefu
statefulSet := appsv1.StatefulSet{
TypeMeta: metav1.TypeMeta{
APIVersion: "apps/v1",
Kind: "statefulSet",
Kind: "StatefulSet",
},
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-%s", service.ServiceID, service.Version),
Expand Down

0 comments on commit b5a83b3

Please sign in to comment.