Skip to content

Commit

Permalink
Added debug label to additional ephemral pods
Browse files Browse the repository at this point in the history
Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>
  • Loading branch information
mabhi committed Mar 25, 2024
1 parent bfb8d89 commit 444786f
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 6 deletions.
3 changes: 3 additions & 0 deletions pkg/function/backup_data_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ func backupDataStats(ctx context.Context, cli kubernetes.Interface, tp param.Tem
Command: []string{"sh", "-c", "tail -f /dev/null"},
PodOverride: podOverride,
}
// Mark labels to pods with prefix `kanister.io`. Add the jobID as reference to the origin for the pod.
kube.AddDebugLabelsToPodOptions(ctx, options, consts.LabelPrefix, "JobID")

pr := kube.NewPodRunner(cli, options)
podFunc := backupDataStatsPodFunc(tp, encryptionKey, backupArtifactPrefix, backupID, mode)
return pr.Run(ctx, podFunc)
Expand Down
3 changes: 3 additions & 0 deletions pkg/function/checkRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ func CheckRepository(ctx context.Context, cli kubernetes.Interface, tp param.Tem
Command: []string{"sh", "-c", "tail -f /dev/null"},
PodOverride: podOverride,
}
// Mark labels to pods with prefix `kanister.io`. Add the jobID as reference to the origin for the pod.
kube.AddDebugLabelsToPodOptions(ctx, options, consts.LabelPrefix, "JobID")

pr := kube.NewPodRunner(cli, options)
podFunc := CheckRepositoryPodFunc(cli, tp, encryptionKey, targetPaths, insecureTLS)
return pr.Run(ctx, podFunc)
Expand Down
3 changes: 3 additions & 0 deletions pkg/function/copy_volume_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ func copyVolumeData(
}},
PodOverride: podOverride,
}
// Mark labels to pods with prefix `kanister.io`. Add the jobID as reference to the origin for the pod.
kube.AddDebugLabelsToPodOptions(ctx, options, consts.LabelPrefix, "JobID")

pr := kube.NewPodRunner(cli, options)
podFunc := copyVolumeDataPodFunc(cli, tp, mountPoint, targetPath, encryptionKey, insecureTLS)
return pr.Run(ctx, podFunc)
Expand Down
3 changes: 3 additions & 0 deletions pkg/function/delete_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ func deleteData(
Command: []string{"sh", "-c", "tail -f /dev/null"},
PodOverride: podOverride,
}
// Mark labels to pods with prefix `kanister.io`. Add the jobID as reference to the origin for the pod.
kube.AddDebugLabelsToPodOptions(ctx, options, consts.LabelPrefix, "JobID")

pr := kube.NewPodRunner(cli, options)
podFunc := deleteDataPodFunc(tp, reclaimSpace, encryptionKey, insecureTLS, targetPaths, deleteTags, deleteIdentifiers)
return pr.Run(ctx, podFunc)
Expand Down
4 changes: 4 additions & 0 deletions pkg/function/delete_data_using_kopia_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

kanister "github.com/kanisterio/kanister/pkg"
crv1alpha1 "github.com/kanisterio/kanister/pkg/apis/cr/v1alpha1"
"github.com/kanisterio/kanister/pkg/consts"
"github.com/kanisterio/kanister/pkg/format"
kankopia "github.com/kanisterio/kanister/pkg/kopia"
kopiacmd "github.com/kanisterio/kanister/pkg/kopia/command"
Expand Down Expand Up @@ -158,6 +159,9 @@ func deleteDataFromServer(
Image: image,
Command: []string{"bash", "-c", "tail -f /dev/null"},
}
// Mark labels to pods with prefix `kanister.io`. Add the jobID as reference to the origin for the pod.
kube.AddDebugLabelsToPodOptions(ctx, options, consts.LabelPrefix, "JobID")

pr := kube.NewPodRunner(cli, options)
podFunc := deleteDataFromServerPodFunc(
hostname,
Expand Down
1 change: 0 additions & 1 deletion pkg/function/kube_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func kubeTask(ctx context.Context, cli kubernetes.Interface, namespace, image st
Command: command,
PodOverride: podOverride,
}

// Mark labels to pods with prefix `kanister.io`. Add the jobID as reference to the origin for the pod.
kube.AddDebugLabelsToPodOptions(ctx, options, consts.LabelPrefix, "JobID")

Expand Down
7 changes: 5 additions & 2 deletions pkg/function/prepare_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import (
"io"
"time"

"github.com/kanisterio/kanister/pkg/consts"
"github.com/kanisterio/kanister/pkg/field"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"

kanister "github.com/kanisterio/kanister/pkg"
crv1alpha1 "github.com/kanisterio/kanister/pkg/apis/cr/v1alpha1"
"github.com/kanisterio/kanister/pkg/consts"
"github.com/kanisterio/kanister/pkg/field"
"github.com/kanisterio/kanister/pkg/format"
"github.com/kanisterio/kanister/pkg/kube"
"github.com/kanisterio/kanister/pkg/param"
Expand Down Expand Up @@ -107,6 +107,9 @@ func prepareData(ctx context.Context, cli kubernetes.Interface, namespace, servi
ServiceAccountName: serviceAccount,
PodOverride: podOverride,
}
// Mark labels to pods with prefix `kanister.io`. Add the jobID as reference to the origin for the pod.
kube.AddDebugLabelsToPodOptions(ctx, options, consts.LabelPrefix, "JobID")

pr := kube.NewPodRunner(cli, options)
podFunc := prepareDataPodFunc(cli)
return pr.Run(ctx, podFunc)
Expand Down
4 changes: 4 additions & 0 deletions pkg/function/restore_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

kanister "github.com/kanisterio/kanister/pkg"
crv1alpha1 "github.com/kanisterio/kanister/pkg/apis/cr/v1alpha1"
"github.com/kanisterio/kanister/pkg/consts"
"github.com/kanisterio/kanister/pkg/format"
"github.com/kanisterio/kanister/pkg/kube"
"github.com/kanisterio/kanister/pkg/param"
Expand Down Expand Up @@ -140,6 +141,9 @@ func restoreData(ctx context.Context, cli kubernetes.Interface, tp param.Templat
Volumes: validatedVols,
PodOverride: podOverride,
}
// Mark labels to pods with prefix `kanister.io`. Add the jobID as reference to the origin for the pod.
kube.AddDebugLabelsToPodOptions(ctx, options, consts.LabelPrefix, "JobID")

pr := kube.NewPodRunner(cli, options)
podFunc := restoreDataPodFunc(tp, encryptionKey, backupArtifactPrefix, restorePath, backupTag, backupID, insecureTLS)
return pr.Run(ctx, podFunc)
Expand Down
3 changes: 3 additions & 0 deletions pkg/function/restore_data_using_kopia_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

kanister "github.com/kanisterio/kanister/pkg"
crv1alpha1 "github.com/kanisterio/kanister/pkg/apis/cr/v1alpha1"
"github.com/kanisterio/kanister/pkg/consts"
"github.com/kanisterio/kanister/pkg/format"
kankopia "github.com/kanisterio/kanister/pkg/kopia"
kopiacmd "github.com/kanisterio/kanister/pkg/kopia/command"
Expand Down Expand Up @@ -206,6 +207,8 @@ func restoreDataFromServer(
Volumes: validatedVols,
PodOverride: podOverride,
}
// Mark labels to pods with prefix `kanister.io`. Add the jobID as reference to the origin for the pod.
kube.AddDebugLabelsToPodOptions(ctx, options, consts.LabelPrefix, "JobID")

pr := kube.NewPodRunner(cli, options)
podFunc := restoreDataFromServerPodFunc(
Expand Down
6 changes: 3 additions & 3 deletions pkg/kube/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"

"github.com/kanisterio/kanister/pkg/consts"
"github.com/kanisterio/kanister/pkg/field"
)

Expand Down Expand Up @@ -179,14 +178,15 @@ func PVCContainsReadOnlyAccessMode(pvc *corev1.PersistentVolumeClaim) bool {
// AddDebugLabelsToPodOptions adds additional label selector to `PodOptions`,
// provided the context has a key starting with `keyPrefix`.
func AddDebugLabelsToPodOptions(ctx context.Context, options *PodOptions, keyPrefix, keySuffix string) {
if fields := field.FromContext(ctx); fields != nil {
fields := field.FromContext(ctx)
if fields != nil {
for _, f := range fields.Fields() {
if strings.HasPrefix(f.Key(), keyPrefix) {
value := f.Value().(string)
if options.Labels == nil {
options.Labels = make(map[string]string)
}
options.Labels[consts.LabelPrefix+keySuffix] = value
options.Labels[keyPrefix+keySuffix] = value
}
}
}
Expand Down

0 comments on commit 444786f

Please sign in to comment.