Create a restore from a backup with a long name defaults to a Restore name that's even longer:
Backup: k8s-dev-auth-namespace-backup-schedule-20181026050059
Restore: k8s-dev-auth-namespace-backup-schedule-20181026050059-20181026153607
ark restore describe k8s-dev-auth-namespace-backup-schedule-20181026050059-20181026153607
...
Phase: Completed
...
Errors:
...
Namespaces:
auth: error restoring /tmp/046287764/resources/secrets/namespaces/auth/default-token-kg2bm.json: Secret "default-token-kg2bm" is invalid: metadata.labels: Invalid value: "k8s-dev-auth-namespace-backup-schedule-20181026050059-20181026153607": must be no more than 63 characters
Ark restore applies labels to restored objects which includes the name of the restore the object is created from. Kubernetes label values must be less than 63 characters, and will be rejected if they are longer.
We ran into similar issues in Gimbal for replicating Services -- That solution is documented here: https://github.com/heptio/gimbal/blob/master/docs/discovery-naming-conventions.md#handling-discovered-names-that-are-longer-than-63-characters which might be of interest.
I am trying to fix this. I suspect that ctx.restore.Name and ctx.restore.Spec.backupName are the two componenets that you @rosskukulinski are talking about above, right?
@nzoueidi to summarize this issue - Kubernetes object names have a maximum length of 253 characters. When Velero executes a restore, it adds a label, velero.io/restore-name, to each restored object, whose value is the name of the restore. However, label values have a maximum length of 63 characters.
We need to come up with a way to ensure that the label values have at most 63 characters, while still being able to represent objects with names of length up to 253 characters.
A couple ways we could do this:
ShortName label to it, and use some kind of hash to populate this label with a unique name that's <= 63 characters. Use this value when labeling resources.Also note that there are likely additional places where this same issue is possible - we use object names as label value in multiple places. It would be best to address all of these, and in a consistent way.
A few references:
https://kubernetes.io/docs/concepts/overview/working-with-objects/names/
https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
I hope I can push my PR by the end of this week.
I'd recommend proposing an approach in a comment here before doing all of the coding!
Yep, sorry for the delay. This is my approach, please correct me if I am mistaken.
ShortName (the same first point that you mentioned above).@skriss wdyt?
Reading through this again, I think an approach similar to the one used in Gimbal (https://github.com/heptio/gimbal/blob/master/docs/discovery-naming-conventions.md#handling-discovered-names-that-are-longer-than-63-characters) makes sense. This would look something like:
@nzoueidi - Let's start by doing that for all labels that are applied in this function: https://github.com/heptio/velero/blob/master/pkg/restore/restore.go#L993
Anshul is actively working on this issue.