Пример #1
0
func (p *kubeBuildletPool) pollCapacity(ctx context.Context) {
	nodes, err := kubeClient.GetNodes(ctx)
	if err != nil {
		log.Printf("Failed to get Kubernetes cluster capacity for %s/%s: %v", projectID, projectRegion, err)
		return
	}
	p.mu.Lock()
	defer p.mu.Unlock()

	// Calculate the total CPU and memory capacity of the cluster
	var sumCPU = api.NewQuantity(0, api.DecimalSI)
	var sumMemory = api.NewQuantity(0, api.BinarySI)
	for _, n := range nodes {
		sumCPU.Add(n.Status.Capacity[api.ResourceCPU])
		sumMemory.Add(n.Status.Capacity[api.ResourceMemory])
	}
	p.cpuCapacity = sumCPU
	p.memoryCapacity = sumMemory
}
Пример #2
0
		Transport: &http.Transport{
			TLSClientConfig: tlsConfig,
		},
	}

	kubeClient, err = kubernetes.NewClient("https://"+cluster.Endpoint, kubeHTTPClient)
	if err != nil {
		return fmt.Errorf("kubernetes HTTP client could not be created: %v", err)
	}

	go kubePool.pollCapacityLoop()
	return nil
}

var kubePool = &kubeBuildletPool{
	cpuCapacity:    api.NewQuantity(0, api.DecimalSI),
	cpuUsage:       api.NewQuantity(0, api.DecimalSI),
	memoryCapacity: api.NewQuantity(0, api.BinarySI),
	memoryUsage:    api.NewQuantity(0, api.BinarySI),
}

// kubeBuildletPool is the Kubernetes buildlet pool.
type kubeBuildletPool struct {
	mu sync.Mutex // guards all following

	pods           map[string]time.Time // pod instance name -> creationTime
	cpuCapacity    *api.Quantity        // cpu capacity as reported by the Kubernetes api
	memoryCapacity *api.Quantity
	cpuUsage       *api.Quantity
	memoryUsage    *api.Quantity
}