feat: use common labels instead of custom ones
This commit is contained in:
1 parent
9cd0644883
commit
632b26905a
2 files changed
+68
-68
No files matched your search
@@ -174,18 +174,16 @@ func templateKubernetesCronJob(input Job) (batchv1.CronJob, error) {
|
|||||||
return batchv1.CronJob{}, fmt.Errorf("Schedule cannot be empty")
|
return batchv1.CronJob{}, fmt.Errorf("Schedule cannot be empty")
|
||||||
}
|
}
|
||||||
labels := map[string]string{
|
labels := map[string]string{
|
||||||
"dokku.com/app-name": input.AppName,
|
"app.kubernetes.io/instance": fmt.Sprintf("%s-%s", input.AppName, input.ProcessType),
|
||||||
"dokku.com/app-process-type": fmt.Sprintf("%s-%s", input.AppName, input.ProcessType),
|
"app.kubernetes.io/name": input.ProcessType,
|
||||||
|
"app.kubernetes.io/part-of": input.AppName,
|
||||||
"dokku.com/cron-id": input.ID,
|
"dokku.com/cron-id": input.ID,
|
||||||
"dokku.com/process-type": input.ProcessType,
|
|
||||||
}
|
}
|
||||||
annotations := map[string]string{
|
annotations := map[string]string{
|
||||||
"dokku.com/app-name": input.AppName,
|
"app.kubernetes.io/version": "DEPLOYMENT_ID_QUOTED",
|
||||||
"dokku.com/builder-type": input.ImageSourceType,
|
"dokku.com/builder-type": input.ImageSourceType,
|
||||||
"dokku.com/cron-id": input.ID,
|
"dokku.com/cron-id": input.ID,
|
||||||
"dokku.com/deployment-id": "DEPLOYMENT_ID_QUOTED",
|
"dokku.com/managed": "true",
|
||||||
"dokku.com/managed": "true",
|
|
||||||
"dokku.com/process-type": input.ProcessType,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for key, value := range input.Labels {
|
for key, value := range input.Labels {
|
||||||
@@ -347,16 +345,14 @@ func templateKubernetesCronJob(input Job) (batchv1.CronJob, error) {
|
|||||||
|
|
||||||
func templateKubernetesDeployment(input Deployment) (appsv1.Deployment, error) {
|
func templateKubernetesDeployment(input Deployment) (appsv1.Deployment, error) {
|
||||||
labels := map[string]string{
|
labels := map[string]string{
|
||||||
"dokku.com/app-name": input.AppName,
|
"app.kubernetes.io/instance": fmt.Sprintf("%s-%s", input.AppName, input.ProcessType),
|
||||||
"dokku.com/app-process-type": fmt.Sprintf("%s-%s", input.AppName, input.ProcessType),
|
"app.kubernetes.io/name": input.ProcessType,
|
||||||
"dokku.com/process-type": input.ProcessType,
|
"app.kubernetes.io/part-of": input.AppName,
|
||||||
}
|
}
|
||||||
annotations := map[string]string{
|
annotations := map[string]string{
|
||||||
"dokku.com/app-name": input.AppName,
|
"app.kubernetes.io/version": "DEPLOYMENT_ID_QUOTED",
|
||||||
"dokku.com/builder-type": input.ImageSourceType,
|
"dokku.com/builder-type": input.ImageSourceType,
|
||||||
"dokku.com/deployment-id": "DEPLOYMENT_ID_QUOTED",
|
"dokku.com/managed": "true",
|
||||||
"dokku.com/managed": "true",
|
|
||||||
"dokku.com/process-type": input.ProcessType,
|
|
||||||
}
|
}
|
||||||
secretName := fmt.Sprintf("env-%s.DEPLOYMENT_ID", input.AppName)
|
secretName := fmt.Sprintf("env-%s.DEPLOYMENT_ID", input.AppName)
|
||||||
|
|
||||||
@@ -575,19 +571,22 @@ func templateKubernetesIngressRoute(input IngressRoute) traefikv1alpha1.IngressR
|
|||||||
entryPoint = IngressRouteEntrypoint_HTTPS
|
entryPoint = IngressRouteEntrypoint_HTTPS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
labels := map[string]string{
|
||||||
|
"app.kubernetes.io/instance": fmt.Sprintf("%s-%s", input.AppName, input.ProcessType),
|
||||||
|
"app.kubernetes.io/name": input.ProcessType,
|
||||||
|
"app.kubernetes.io/part-of": input.AppName,
|
||||||
|
}
|
||||||
|
annotations := map[string]string{
|
||||||
|
"dokku.com/managed": "true",
|
||||||
|
}
|
||||||
|
|
||||||
port := fmt.Sprintf("%s-%d-%d", input.PortMap.Scheme, input.PortMap.HostPort, input.PortMap.ContainerPort)
|
port := fmt.Sprintf("%s-%d-%d", input.PortMap.Scheme, input.PortMap.HostPort, input.PortMap.ContainerPort)
|
||||||
ingressRoute := traefikv1alpha1.IngressRoute{
|
ingressRoute := traefikv1alpha1.IngressRoute{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: fmt.Sprintf("%s-%s", input.ServiceName, port),
|
Name: fmt.Sprintf("%s-%s", input.ServiceName, port),
|
||||||
Namespace: input.Namespace,
|
Namespace: input.Namespace,
|
||||||
Labels: map[string]string{
|
Labels: labels,
|
||||||
"dokku.com/app-name": input.AppName,
|
Annotations: annotations,
|
||||||
"dokku.com/app-process-type": fmt.Sprintf("%s-%s", input.AppName, input.ProcessType),
|
|
||||||
"dokku.com/process-type": input.ProcessType,
|
|
||||||
},
|
|
||||||
Annotations: map[string]string{
|
|
||||||
"dokku.com/managed": "true",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
Spec: traefikv1alpha1.IngressRouteSpec{
|
Spec: traefikv1alpha1.IngressRouteSpec{
|
||||||
EntryPoints: []string{string(entryPoint)},
|
EntryPoints: []string{string(entryPoint)},
|
||||||
@@ -620,16 +619,14 @@ func templateKubernetesIngressRoute(input IngressRoute) traefikv1alpha1.IngressR
|
|||||||
|
|
||||||
func templateKubernetesJob(input Job) (batchv1.Job, error) {
|
func templateKubernetesJob(input Job) (batchv1.Job, error) {
|
||||||
labels := map[string]string{
|
labels := map[string]string{
|
||||||
"dokku.com/app-name": input.AppName,
|
"app.kubernetes.io/instance": fmt.Sprintf("%s-%s", input.AppName, input.ProcessType),
|
||||||
"dokku.com/app-process-type": fmt.Sprintf("%s-%s", input.AppName, input.ProcessType),
|
"app.kubernetes.io/name": input.ProcessType,
|
||||||
"dokku.com/process-type": input.ProcessType,
|
"app.kubernetes.io/part-of": input.AppName,
|
||||||
}
|
}
|
||||||
annotations := map[string]string{
|
annotations := map[string]string{
|
||||||
"dokku.com/app-name": input.AppName,
|
"app.kubernetes.io/version": fmt.Sprint(input.DeploymentID),
|
||||||
"dokku.com/builder-type": input.ImageSourceType,
|
"dokku.com/builder-type": input.ImageSourceType,
|
||||||
"dokku.com/deployment-id": fmt.Sprint(input.DeploymentID),
|
"dokku.com/managed": "true",
|
||||||
"dokku.com/managed": "true",
|
|
||||||
"dokku.com/process-type": input.ProcessType,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for key, value := range input.Labels {
|
for key, value := range input.Labels {
|
||||||
@@ -773,17 +770,22 @@ func templateKubernetesJob(input Job) (batchv1.Job, error) {
|
|||||||
|
|
||||||
func templateKubernetesSecret(input Secret) corev1.Secret {
|
func templateKubernetesSecret(input Secret) corev1.Secret {
|
||||||
secretName := fmt.Sprintf("env-%s.DEPLOYMENT_ID", input.AppName)
|
secretName := fmt.Sprintf("env-%s.DEPLOYMENT_ID", input.AppName)
|
||||||
|
labels := map[string]string{
|
||||||
|
"app.kubernetes.io/instance": secretName,
|
||||||
|
"app.kubernetes.io/name": fmt.Sprintf("%s-env", input.AppName),
|
||||||
|
"app.kubernetes.io/part-of": input.AppName,
|
||||||
|
}
|
||||||
|
|
||||||
|
annotations := map[string]string{
|
||||||
|
"app.kubernetes.io/version": "DEPLOYMENT_ID_QUOTED",
|
||||||
|
"dokku.com/managed": "true",
|
||||||
|
}
|
||||||
secret := corev1.Secret{
|
secret := corev1.Secret{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: secretName,
|
Name: secretName,
|
||||||
Namespace: input.Namespace,
|
Namespace: input.Namespace,
|
||||||
Labels: map[string]string{
|
Labels: labels,
|
||||||
"dokku.com/app-name": input.AppName,
|
Annotations: annotations,
|
||||||
"dokku.com/deployment-id": "DEPLOYMENT_ID_QUOTED",
|
|
||||||
},
|
|
||||||
Annotations: map[string]string{
|
|
||||||
"dokku.com/managed": "true",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
Data: map[string][]byte{},
|
Data: map[string][]byte{},
|
||||||
}
|
}
|
||||||
@@ -792,25 +794,23 @@ func templateKubernetesSecret(input Secret) corev1.Secret {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func templateKubernetesService(input Service) corev1.Service {
|
func templateKubernetesService(input Service) corev1.Service {
|
||||||
|
labels := map[string]string{
|
||||||
|
"app.kubernetes.io/instance": fmt.Sprintf("%s-%s", input.AppName, "web"),
|
||||||
|
"app.kubernetes.io/name": "web",
|
||||||
|
"app.kubernetes.io/part-of": input.AppName,
|
||||||
|
}
|
||||||
|
annotations := map[string]string{
|
||||||
|
"dokku.com/managed": "true",
|
||||||
|
}
|
||||||
service := corev1.Service{
|
service := corev1.Service{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: fmt.Sprintf("%s-%s", input.AppName, "web"),
|
Name: fmt.Sprintf("%s-%s", input.AppName, "web"),
|
||||||
Namespace: input.Namespace,
|
Namespace: input.Namespace,
|
||||||
Labels: map[string]string{
|
Labels: labels,
|
||||||
"dokku.com/app-name": input.AppName,
|
Annotations: annotations,
|
||||||
"dokku.com/app-process-type": fmt.Sprintf("%s-%s", input.AppName, "web"),
|
|
||||||
"dokku.com/process-type": "web",
|
|
||||||
},
|
|
||||||
Annotations: map[string]string{
|
|
||||||
"dokku.com/managed": "true",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
Spec: corev1.ServiceSpec{
|
Spec: corev1.ServiceSpec{
|
||||||
Selector: map[string]string{
|
Selector: labels,
|
||||||
"dokku.com/app-name": input.AppName,
|
|
||||||
"dokku.com/app-process-type": fmt.Sprintf("%s-%s", input.AppName, "web"),
|
|
||||||
"dokku.com/process-type": "web",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -296,7 +296,7 @@ data:
|
|||||||
}
|
}
|
||||||
|
|
||||||
cronJobs, err := clientset.ListCronJobs(ctx, ListCronJobsInput{
|
cronJobs, err := clientset.ListCronJobs(ctx, ListCronJobsInput{
|
||||||
LabelSelector: fmt.Sprintf("dokku.com/app-name=%s", appName),
|
LabelSelector: fmt.Sprintf("app.kubernetes.io/part-of=%s", appName),
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -487,7 +487,7 @@ func TriggerSchedulerEnter(scheduler string, appName string, processType string,
|
|||||||
|
|
||||||
namespace := common.PropertyGetDefault("scheduler-k3s", appName, "namespace", "default")
|
namespace := common.PropertyGetDefault("scheduler-k3s", appName, "namespace", "default")
|
||||||
|
|
||||||
labelSelector := []string{fmt.Sprintf("dokku.com/app-name=%s", appName)}
|
labelSelector := []string{fmt.Sprintf("app.kubernetes.io/part-of=%s", appName)}
|
||||||
processIndex := 1
|
processIndex := 1
|
||||||
if processType != "" {
|
if processType != "" {
|
||||||
parts := strings.SplitN(processType, ".", 2)
|
parts := strings.SplitN(processType, ".", 2)
|
||||||
@@ -498,7 +498,7 @@ func TriggerSchedulerEnter(scheduler string, appName string, processType string,
|
|||||||
return fmt.Errorf("Error parsing process index: %w", err)
|
return fmt.Errorf("Error parsing process index: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
labelSelector = append(labelSelector, fmt.Sprintf("dokku.com/process-type=%s", processType))
|
labelSelector = append(labelSelector, fmt.Sprintf("app.kubernetes.io/name=%s", processType))
|
||||||
}
|
}
|
||||||
|
|
||||||
pods, err := clientset.ListPods(ctx, ListPodsInput{
|
pods, err := clientset.ListPods(ctx, ListPodsInput{
|
||||||
@@ -577,7 +577,7 @@ func TriggerSchedulerLogs(scheduler string, appName string, processType string,
|
|||||||
cancel()
|
cancel()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
labelSelector := []string{fmt.Sprintf("dokku.com/app-name=%s", appName)}
|
labelSelector := []string{fmt.Sprintf("app.kubernetes.io/part-of=%s", appName)}
|
||||||
processIndex := 0
|
processIndex := 0
|
||||||
if processType != "" {
|
if processType != "" {
|
||||||
parts := strings.SplitN(processType, ".", 2)
|
parts := strings.SplitN(processType, ".", 2)
|
||||||
@@ -588,7 +588,7 @@ func TriggerSchedulerLogs(scheduler string, appName string, processType string,
|
|||||||
return fmt.Errorf("Error parsing process index: %w", err)
|
return fmt.Errorf("Error parsing process index: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
labelSelector = append(labelSelector, fmt.Sprintf("dokku.com/process-type=%s", processType))
|
labelSelector = append(labelSelector, fmt.Sprintf("app.kubernetes.io/name=%s", processType))
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace := common.PropertyGetDefault("scheduler-k3s", appName, "namespace", "default")
|
namespace := common.PropertyGetDefault("scheduler-k3s", appName, "namespace", "default")
|
||||||
@@ -743,7 +743,7 @@ func TriggerSchedulerRun(scheduler string, appName string, envCount int, args []
|
|||||||
}
|
}
|
||||||
|
|
||||||
labels := map[string]string{
|
labels := map[string]string{
|
||||||
"dokku.com/app-name": appName,
|
"app.kubernetes.io/part-of": appName,
|
||||||
}
|
}
|
||||||
|
|
||||||
if os.Getenv("DOKKU_TRACE") == "1" {
|
if os.Getenv("DOKKU_TRACE") == "1" {
|
||||||
@@ -990,7 +990,7 @@ func TriggerSchedulerRunList(scheduler string, appName string, format string) er
|
|||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
cronJobs, err := clientset.ListCronJobs(ctx, ListCronJobsInput{
|
cronJobs, err := clientset.ListCronJobs(ctx, ListCronJobsInput{
|
||||||
LabelSelector: fmt.Sprintf("dokku.com/app-name=%s", appName),
|
LabelSelector: fmt.Sprintf("app.kubernetes.io/part-of=%s", appName),
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1087,14 +1087,14 @@ func TriggerSchedulerStop(scheduler string, appName string) error {
|
|||||||
namespace := common.PropertyGetDefault("scheduler-k3s", appName, "namespace", "default")
|
namespace := common.PropertyGetDefault("scheduler-k3s", appName, "namespace", "default")
|
||||||
deployments, err := clientset.ListDeployments(ctx, ListDeploymentsInput{
|
deployments, err := clientset.ListDeployments(ctx, ListDeploymentsInput{
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
LabelSelector: fmt.Sprintf("dokku.com/app-name=%s", appName),
|
LabelSelector: fmt.Sprintf("app.kubernetes.io/part-of=%s", appName),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error listing deployments: %w", err)
|
return fmt.Errorf("Error listing deployments: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, deployment := range deployments {
|
for _, deployment := range deployments {
|
||||||
processType, ok := deployment.Annotations["dokku.com/process-type"]
|
processType, ok := deployment.Annotations["app.kubernetes.io/name"]
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("Deployment %s does not have a process type annotation", deployment.Name)
|
return fmt.Errorf("Deployment %s does not have a process type annotation", deployment.Name)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user