From e73f1879d4c9dd77de793dd50a3e3642cea7ab74 Mon Sep 17 00:00:00 2001 From: Tamal Saha Date: Thu, 15 Aug 2024 20:29:49 -0700 Subject: [PATCH] Add state to cluster metadata (#592) Signed-off-by: Tamal Saha --- api/v1/cluster.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/api/v1/cluster.go b/api/v1/cluster.go index 057cb55ab..1de796faf 100644 --- a/api/v1/cluster.go +++ b/api/v1/cluster.go @@ -16,7 +16,13 @@ limitations under the License. package v1 -import "strings" +import ( + "crypto/hmac" + "crypto/sha256" + "encoding/base64" + "fmt" + "strings" +) // +kubebuilder:validation:Enum=Aws;Azure;DigitalOcean;GoogleCloud;Linode;Packet;Scaleway;Vultr;BareMetal;KIND;Generic;Private type HostingProvider string @@ -56,6 +62,13 @@ type ClusterMetadata struct { CABundle string `json:"caBundle,omitempty"` } +func (md ClusterMetadata) State() string { + hasher := hmac.New(sha256.New, []byte(md.UID)) + state := fmt.Sprintf("%s,%s", md.APIEndpoint, md.OwnerID) + hasher.Write([]byte(state)) + return base64.URLEncoding.EncodeToString(hasher.Sum(nil)) +} + /* ENUM(