keikoproj / kube-forensics

Apache License 2.0
220 stars 26 forks source link

PodCheckpoint with long (>63 characters) CR name fail to be processed #20

Open tekenstam opened 4 years ago

tekenstam commented 4 years ago

Is this a BUG REPORT or FEATURE REQUEST?: BUG

What happened: When submitting a PodCheckpoint, if the name is long (>63 characters) then the PodCheckpoint will fail to process.

{"level":"error","ts":1593128067.005712,"logger":"kubebuilder.controller","msg":"Reconciler error","controller":"podsavestate-controller","request":"forensics-system/podsavestate-long-name-123456789012345678901234567890123456789012345678901234567890","error":"Job.batch \"podsavestate-long-name-123456789012345678901234567890123456789012345678901234567890-job\" is invalid: spec.template.labels: Invalid value: \"podsavestate-long-name-123456789012345678901234567890123456789012345678901234567890-job\": must be no more than 63 characters","stacktrace":"github.intuit.com/kubernetes/pod-savestate/vendor/github.com/go-logr/zapr.(*zapLogger).Error\n\t/go/src/github.intuit.com/kubernetes/pod-savestate/vendor/github.com/go-logr/zapr/zapr.go:128\ngithub.intuit.com/kubernetes/pod-savestate/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem\n\t/go/src/github.intuit.com/kubernetes/pod-savestate/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:217\ngithub.intuit.com/kubernetes/pod-savestate/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func1\n\t/go/src/github.intuit.com/kubernetes/pod-savestate/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:158\ngithub.intuit.com/kubernetes/pod-savestate/vendor/k8s.io/apimachinery/pkg/util/wait.JitterUntil.func1\n\t/go/src/github.intuit.com/kubernetes/pod-savestate/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:133\ngithub.intuit.com/kubernetes/pod-savestate/vendor/k8s.io/apimachinery/pkg/util/wait.JitterUntil\n\t/go/src/github.intuit.com/kubernetes/pod-savestate/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:134\ngithub.intuit.com/kubernetes/pod-savestate/vendor/k8s.io/apimachinery/pkg/util/wait.Until\n\t/go/src/github.intuit.com/kubernetes/pod-savestate/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:88"}

What you expected to happen: PodCheckpoint should be allowed to have long names. Instead of creating a Job with a name based on the PodCheckpoint name (just appending -job), the controller should check the length. If the length is >60 characters, get a short hash of the PodCheckpoint name and name the job by truncating the name of the PodCheckpoint an appropriate amount and then prepending the hash and -job such that the resulting length of the job name is <64 characters.

How to reproduce it (as minimally and precisely as possible):

apiVersion: forensics.keikoproj.io/v1alpha1
kind: PodCheckpoint
metadata:
  labels:
    controller-tools.k8s.io: "1.0"
  name: podsavestate-long-name-123456789012345678901234567890123456789012345678901234567890
  namespace: forensics-system
spec:
  destination: s3://kops-state-store-999999999-us-west-2
  subpath: tee-test.cluster.k8s.local
  pod: debug-pod
  namespace: default

Anything else we need to know?:

Environment:

Other debugging information (if applicable):

tekenstam commented 4 years ago

As part of fixing this issue and validating the job name, should also replace any dots (.) with dashes (-).