Skip to content

Commit

Permalink
Add manager and hub cluster info to cluster metadata (#494)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha authored Oct 18, 2024
1 parent b2dffcc commit 8452f78
Show file tree
Hide file tree
Showing 21 changed files with 336 additions and 132 deletions.
12 changes: 12 additions & 0 deletions apis/core/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions apis/identity/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions apis/management/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions apis/meta/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions apis/node/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions apis/ui/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions crds/core.k8s.appscode.com_genericresources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ spec:
type: string
displayName:
type: string
hubClusterID:
type: string
managerID:
type: string
name:
type: string
ownerID:
Expand Down
4 changes: 4 additions & 0 deletions crds/core.k8s.appscode.com_genericresourceservices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ spec:
type: string
displayName:
type: string
hubClusterID:
type: string
managerID:
type: string
name:
type: string
ownerID:
Expand Down
4 changes: 4 additions & 0 deletions crds/core.k8s.appscode.com_resourcesummaries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ spec:
type: string
displayName:
type: string
hubClusterID:
type: string
managerID:
type: string
name:
type: string
ownerID:
Expand Down
4 changes: 4 additions & 0 deletions crds/identity.k8s.appscode.com_clusteridentitys.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ spec:
type: string
displayName:
type: string
hubClusterID:
type: string
managerID:
type: string
name:
type: string
ownerID:
Expand Down
4 changes: 4 additions & 0 deletions crds/identity.k8s.appscode.com_siteinfos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ spec:
type: string
displayName:
type: string
hubClusterID:
type: string
managerID:
type: string
name:
type: string
ownerID:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
k8s.io/klog/v2 v2.130.1
k8s.io/kube-openapi v0.0.0-20240703190633-0aa61b46e8c2
kmodules.xyz/apiversion v0.2.0
kmodules.xyz/client-go v0.30.28
kmodules.xyz/client-go v0.30.29
kmodules.xyz/crd-schema-fuzz v0.29.1
kmodules.xyz/go-containerregistry v0.0.12
kmodules.xyz/offshoot-api v0.30.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0 h1:jgGTlFYnhF1PM1Ax/lAlxUPE+KfCI
k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
kmodules.xyz/apiversion v0.2.0 h1:vAQYqZFm4xu4pbB1cAdHbFEPES6EQkcR4wc06xdTOWk=
kmodules.xyz/apiversion v0.2.0/go.mod h1:oPX8g8LvlPdPX3Yc5YvCzJHQnw3YF/X4/jdW0b1am80=
kmodules.xyz/client-go v0.30.28 h1:YD5AZaUm3xakIbwLoKblLbE6mvayNZhIomgdXyuLo40=
kmodules.xyz/client-go v0.30.28/go.mod h1:CAu+JlA8RVGtj6LQHu0Q1w2mnFUajuti49c7T1AvGdM=
kmodules.xyz/client-go v0.30.29 h1:qiJH6inZNrjXKearnzacZZtch2sUxSWJMKntdwFUYC8=
kmodules.xyz/client-go v0.30.29/go.mod h1:CAu+JlA8RVGtj6LQHu0Q1w2mnFUajuti49c7T1AvGdM=
kmodules.xyz/crd-schema-fuzz v0.29.1 h1:zJTlWYOrT5dsVVHW8HGcnR/vaWfxQfNh11QwTtkYpcs=
kmodules.xyz/crd-schema-fuzz v0.29.1/go.mod h1:n708z9YQqLMP2KNLQVgBcRJw1QpSWLvpNCEi+KJDOYE=
kmodules.xyz/go-containerregistry v0.0.12 h1:Tl32QGmSqRVm9PUEb/f3dgDeu9zW5fVzt3qmAFIE37I=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ spec:
type: string
displayName:
type: string
hubClusterID:
type: string
managerID:
type: string
name:
type: string
ownerID:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ spec:
type: string
displayName:
type: string
hubClusterID:
type: string
managerID:
type: string
name:
type: string
ownerID:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ spec:
type: string
displayName:
type: string
hubClusterID:
type: string
managerID:
type: string
name:
type: string
ownerID:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ spec:
type: string
displayName:
type: string
hubClusterID:
type: string
managerID:
type: string
name:
type: string
ownerID:
Expand Down
27 changes: 18 additions & 9 deletions vendor/kmodules.xyz/client-go/api/v1/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,28 @@ const (
)

type ClusterMetadata struct {
UID string `json:"uid" protobuf:"bytes,1,opt,name=uid"`
Name string `json:"name,omitempty" protobuf:"bytes,2,opt,name=name"`
DisplayName string `json:"displayName,omitempty" protobuf:"bytes,3,opt,name=displayName"`
Provider HostingProvider `json:"provider,omitempty" protobuf:"bytes,4,opt,name=provider,casttype=HostingProvider"`
OwnerID string `json:"ownerID,omitempty" protobuf:"bytes,5,opt,name=ownerID"`
OwnerType string `json:"ownerType,omitempty" protobuf:"bytes,6,opt,name=ownerType"`
APIEndpoint string `json:"apiEndpoint,omitempty" protobuf:"bytes,7,opt,name=apiEndpoint"`
CABundle string `json:"caBundle,omitempty" protobuf:"bytes,8,opt,name=caBundle"`
UID string `json:"uid" protobuf:"bytes,1,opt,name=uid"`
Name string `json:"name,omitempty" protobuf:"bytes,2,opt,name=name"`
DisplayName string `json:"displayName,omitempty" protobuf:"bytes,3,opt,name=displayName"`
Provider HostingProvider `json:"provider,omitempty" protobuf:"bytes,4,opt,name=provider,casttype=HostingProvider"`
OwnerID string `json:"ownerID,omitempty" protobuf:"bytes,5,opt,name=ownerID"`
OwnerType string `json:"ownerType,omitempty" protobuf:"bytes,6,opt,name=ownerType"`
APIEndpoint string `json:"apiEndpoint,omitempty" protobuf:"bytes,7,opt,name=apiEndpoint"`
CABundle string `json:"caBundle,omitempty" protobuf:"bytes,8,opt,name=caBundle"`
ManagerID string `json:"managerID,omitempty" protobuf:"bytes,9,opt,name=managerID"`
HubClusterID string `json:"hubClusterID,omitempty" protobuf:"bytes,10,opt,name=hubClusterID"`
}

func (md ClusterMetadata) Manager() string {
if md.ManagerID != "" && md.ManagerID != "0" {
return md.ManagerID
}
return md.OwnerID
}

func (md ClusterMetadata) State() string {
hasher := hmac.New(sha256.New, []byte(md.UID))
state := fmt.Sprintf("%s,%s", md.APIEndpoint, md.OwnerID)
state := fmt.Sprintf("%s,%s", md.APIEndpoint, md.Manager())
hasher.Write([]byte(state))
return base64.URLEncoding.EncodeToString(hasher.Sum(nil))
}
Expand Down
Loading

0 comments on commit 8452f78

Please sign in to comment.