Skip to content

Commit

Permalink
Add cluster join everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
lmq1999 committed Sep 28, 2023
1 parent b77d1d9 commit 21aebe5
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
2 changes: 2 additions & 0 deletions kubernetes_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
kubeConfig = "kubeconfig"
k8sVersion = "/k8s_versions"
adminWorkerConfig = "/admin/worker_config"
clusterJoinEverywhere = "/engine/cluster_join_everywhere"
)

var _ KubernetesEngineService = (*kubernetesEngineService)(nil)
Expand All @@ -39,6 +40,7 @@ type KubernetesEngineService interface {
GetKubeConfig(ctx context.Context, clusterUID string) (string, error)
GetKubernetesVersion(ctx context.Context) (*KubernetesVersionResponse, error)
GetAdminWorkerConfig(ctx context.Context) (*WorkerConfigs, error)
AddClusterEverywhere(ctx context.Context, id string, cjer *clusterJoinEverywhereRequest) (*clusterJoinEverywhereResponse, error)
}

// KubernetesVersionResponse represents the get versions from the Kubernetes Engine API
Expand Down
68 changes: 68 additions & 0 deletions kubernetes_engine_engine.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package gobizfly

import (
"context"
"encoding/json"
"net/http"
)

type clusterJoinEverywhereRequest struct {
Hostname string `json:"hostname" yaml:"hostname"`
IPAddresses []string `json:"ip_addresses" yaml:"ip_addresses"`
Capacity []everywhereNodeCapacity `json:"capacity" yaml:"capacity"`
}

type everywhereNodeCapacity struct {
Cores int `json:"cores" yaml:"cores"`
MemoryKB int `json:"memory_kb" yaml:"memory_kb"`
}

type clusterCertificate struct {
CaCert string `json:"ca.pem" yaml:"ca.pem"`
ClientKey string `json:"client-key.pem" yaml:"client-key.pem"`
ClientCert string `json:"client.pem" yaml:"client.pem"`
}

type clusterReserved struct {
SystemReserved clusterSystemReserved `json:"system_reserved" yaml:"system_reserved"`
KubeReserved clusterKubeReserved `json:"kube_reserved" yaml:"kube_reserved"`
}

type clusterSystemReserved struct {
CPU string `json:"cpu" yaml:"cpu"`
Memory string `json:"memory" yaml:"memory"`
}

type clusterKubeReserved struct {
CPU string `json:"cpu" yaml:"cpu"`
Memory string `json:"memory" yaml:"memory"`
}

type clusterJoinEverywhereResponse struct {
APIServer string `json:"apiserver" yaml:"apiserver"`
ClusterDNS string `json:"cluster_dns" yaml:"cluster_dns"`
ClusterCIDR string `json:"cluster_cidr" yaml:"cluster_cidr"`
CloudProvider string `json:"cloud_provider" yaml:"cloud_provider"`
Certificate clusterCertificate `json:"certificate" yaml:"certificate"`
UUID string `json:"uuid" yaml:"uuid"`
MaxPods int `json:"max_pods" yaml:"max_pods"`
Reserved clusterReserved `json:"reserved" yaml:"reserved"`
}

func (c *kubernetesEngineService) AddClusterEverywhere(ctx context.Context, id string, cjer *clusterJoinEverywhereRequest) (*clusterJoinEverywhereResponse, error) {
var joinEverywhereResponse *clusterJoinEverywhereResponse
req, err := c.client.NewRequest(ctx, http.MethodPost, kubernetesServiceName, clusterJoinEverywhere, &cjer)
if err != nil {
return nil, err
}
resp, err := c.client.Do(ctx, req)
if err != nil {
return nil, err
}
defer resp.Body.Close()

if err := json.NewDecoder(resp.Body).Decode(joinEverywhereResponse); err != nil {
return nil, err
}
return joinEverywhereResponse, nil
}

0 comments on commit 21aebe5

Please sign in to comment.