Skip to content

Commit

Permalink
Add state to cluster metadata (#592)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha authored Aug 16, 2024
1 parent 5160156 commit e73f187
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion api/v1/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit e73f187

Please sign in to comment.