Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use UUIDs #86

Closed
lippserd opened this issue May 23, 2024 · 1 comment
Closed

Use UUIDs #86

lippserd opened this issue May 23, 2024 · 1 comment
Assignees
Milestone

Comments

@lippserd
Copy link
Member

This is a pretty heavy change, but I think it's better to do it sooner rather than later: Kubernetes objects already provide UIDs, with most of them being UUIDs1:

UID is a type that holds unique ID values, including UUIDs. Because we
don't ONLY use UUIDs, this is an alias to string. Being a type captures
intent and helps make sure that UIDs and names do not get conflated.

Instead of creating our IDs from namespace/name, we should simply use the Kubernetes UUIDs:

  • Rename id to uuid and use github.com/google/uuid#UUID as type
  • Change foreign keys accordingly
  • Add uuid to schema/v1#Meta
  • For related objects like containers which do not provide UIDs, we can create UUIDs like uuid.NewSHA1(PodUUID, []byte(containerName))
  • Use the following code to create UUIDs from Kubernetes UIDs:
var NameSpaceKubernetes = uuid.MustParse("3f249403-2bb0-428f-8e91-504d1fd7ddb6")

func EnsureUUID(uid ktypes.UID) uuid.UUID {
	if id, err := uuid.Parse(string(uid)); err == nil {
		return id
	}

	return uuid.NewSHA1(NameSpaceKubernetes, []byte(uid))
}

Footnotes

  1. types.UID

@jhoxhaa jhoxhaa self-assigned this May 23, 2024
@lippserd
Copy link
Member Author

lippserd commented Jun 4, 2024

Implemented via #93 + Icinga/icinga-kubernetes-web#46.

@lippserd lippserd closed this as completed Jun 4, 2024
@lippserd lippserd added this to the 0.2.0 milestone Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants