[hyper-provider] 1.fix hyper.NewClient 2.add instanceType 3.fix incrementRefCounters and decrementRefCounters
This commit is contained in:
@@ -257,11 +257,11 @@ func (rm *ResourceManager) watchSecrets() {
|
|||||||
func (rm *ResourceManager) incrementRefCounters(p *v1.Pod) {
|
func (rm *ResourceManager) incrementRefCounters(p *v1.Pod) {
|
||||||
for _, c := range p.Spec.Containers {
|
for _, c := range p.Spec.Containers {
|
||||||
for _, e := range c.Env {
|
for _, e := range c.Env {
|
||||||
if e.ValueFrom.ConfigMapKeyRef != nil {
|
if e.ValueFrom != nil && e.ValueFrom.ConfigMapKeyRef != nil {
|
||||||
rm.configMapRef[e.ValueFrom.ConfigMapKeyRef.Name]++
|
rm.configMapRef[e.ValueFrom.ConfigMapKeyRef.Name]++
|
||||||
}
|
}
|
||||||
|
|
||||||
if e.ValueFrom.SecretKeyRef != nil {
|
if e.ValueFrom != nil && e.ValueFrom.SecretKeyRef != nil {
|
||||||
rm.secretRef[e.ValueFrom.SecretKeyRef.Name]++
|
rm.secretRef[e.ValueFrom.SecretKeyRef.Name]++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -277,11 +277,11 @@ func (rm *ResourceManager) incrementRefCounters(p *v1.Pod) {
|
|||||||
func (rm *ResourceManager) decrementRefCounters(p *v1.Pod) {
|
func (rm *ResourceManager) decrementRefCounters(p *v1.Pod) {
|
||||||
for _, c := range p.Spec.Containers {
|
for _, c := range p.Spec.Containers {
|
||||||
for _, e := range c.Env {
|
for _, e := range c.Env {
|
||||||
if e.ValueFrom.ConfigMapKeyRef != nil {
|
if e.ValueFrom != nil && e.ValueFrom.ConfigMapKeyRef != nil {
|
||||||
rm.configMapRef[e.ValueFrom.ConfigMapKeyRef.Name]--
|
rm.configMapRef[e.ValueFrom.ConfigMapKeyRef.Name]--
|
||||||
}
|
}
|
||||||
|
|
||||||
if e.ValueFrom.SecretKeyRef != nil {
|
if e.ValueFrom != nil && e.ValueFrom.SecretKeyRef != nil {
|
||||||
rm.secretRef[e.ValueFrom.SecretKeyRef.Name]--
|
rm.secretRef[e.ValueFrom.SecretKeyRef.Name]--
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/virtual-kubelet/virtual-kubelet/providers"
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
|
"github.com/virtual-kubelet/virtual-kubelet/providers"
|
||||||
)
|
)
|
||||||
|
|
||||||
type providerConfig struct {
|
type providerConfig struct {
|
||||||
@@ -15,6 +15,7 @@ type providerConfig struct {
|
|||||||
OperatingSystem string
|
OperatingSystem string
|
||||||
CPU string
|
CPU string
|
||||||
Memory string
|
Memory string
|
||||||
|
InstanceType string
|
||||||
Pods string
|
Pods string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,6 +28,11 @@ func (p *HyperProvider) loadConfig(r io.Reader) error {
|
|||||||
p.accessKey = config.AccessKey
|
p.accessKey = config.AccessKey
|
||||||
p.secretKey = config.SecretKey
|
p.secretKey = config.SecretKey
|
||||||
|
|
||||||
|
p.instanceType = "s4"
|
||||||
|
if config.InstanceType != "" {
|
||||||
|
p.instanceType = config.InstanceType
|
||||||
|
}
|
||||||
|
|
||||||
// Default to 20 mcpu
|
// Default to 20 mcpu
|
||||||
p.cpu = "20"
|
p.cpu = "20"
|
||||||
if config.CPU != "" {
|
if config.CPU != "" {
|
||||||
|
|||||||
@@ -6,8 +6,11 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
"github.com/docker/go-connections/nat"
|
"github.com/docker/go-connections/nat"
|
||||||
|
"github.com/docker/go-connections/sockets"
|
||||||
|
"github.com/docker/go-connections/tlsconfig"
|
||||||
hyper "github.com/hyperhq/hyper-api/client"
|
hyper "github.com/hyperhq/hyper-api/client"
|
||||||
"github.com/hyperhq/hyper-api/types"
|
"github.com/hyperhq/hyper-api/types"
|
||||||
"github.com/hyperhq/hyper-api/types/container"
|
"github.com/hyperhq/hyper-api/types/container"
|
||||||
@@ -20,11 +23,13 @@ import (
|
|||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var host = "tcp://*.hyper.sh:443"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
host = "https://us-west-1.hyper.sh"
|
verStr = "v1.23"
|
||||||
verStr = "v1.23"
|
containerLabel = "hyper-virtual-kubelet"
|
||||||
containerLabel = "hyper-virtual-kubelet"
|
nodeLabel = containerLabel + "-node"
|
||||||
nodeLabel = containerLabel + "-node"
|
instanceTypeLabel = "sh_hyper_instancetype"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HyperProvider implements the virtual-kubelet provider interface and communicates with hyper.sh APIs.
|
// HyperProvider implements the virtual-kubelet provider interface and communicates with hyper.sh APIs.
|
||||||
@@ -38,6 +43,7 @@ type HyperProvider struct {
|
|||||||
secretKey string
|
secretKey string
|
||||||
cpu string
|
cpu string
|
||||||
memory string
|
memory string
|
||||||
|
instanceType string
|
||||||
pods string
|
pods string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,10 +78,21 @@ func NewHyperProvider(config string, rm *manager.ResourceManager, nodeName, oper
|
|||||||
p.region = r
|
p.region = r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if it := os.Getenv("HYPERSH_INSTANCE_TYPE"); it != "" {
|
||||||
|
p.instanceType = it
|
||||||
|
}
|
||||||
|
|
||||||
|
host = fmt.Sprintf("tcp://%v.hyper.sh:443", p.region)
|
||||||
|
httpClient, err := newHTTPClient(host, &tlsconfig.Options{InsecureSkipVerify: false})
|
||||||
|
|
||||||
|
customHeaders := map[string]string{}
|
||||||
|
ver := "0.1"
|
||||||
|
customHeaders["User-Agent"] = fmt.Sprintf("Virtual-Kubelet-Client/%v (%v)", ver, runtime.GOOS)
|
||||||
|
|
||||||
p.operatingSystem = operatingSystem
|
p.operatingSystem = operatingSystem
|
||||||
p.nodeName = nodeName
|
p.nodeName = nodeName
|
||||||
|
|
||||||
p.hyperClient, err = hyper.NewClient(host, verStr, http.DefaultClient, nil, p.accessKey, p.secretKey, p.region)
|
p.hyperClient, err = hyper.NewClient(host, verStr, httpClient, customHeaders, p.accessKey, p.secretKey, p.region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -83,6 +100,31 @@ func NewHyperProvider(config string, rm *manager.ResourceManager, nodeName, oper
|
|||||||
return &p, nil
|
return &p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newHTTPClient(host string, tlsOptions *tlsconfig.Options) (*http.Client, error) {
|
||||||
|
if tlsOptions == nil {
|
||||||
|
// let the api client configure the default transport.
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
config, err := tlsconfig.Client(*tlsOptions)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
tr := &http.Transport{
|
||||||
|
TLSClientConfig: config,
|
||||||
|
}
|
||||||
|
proto, addr, _, err := hyper.ParseHost(host)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
sockets.ConfigureTransport(tr, proto, addr)
|
||||||
|
|
||||||
|
return &http.Client{
|
||||||
|
Transport: tr,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
// CreatePod accepts a Pod definition and creates
|
// CreatePod accepts a Pod definition and creates
|
||||||
// a hyper.sh deployment
|
// a hyper.sh deployment
|
||||||
func (p *HyperProvider) CreatePod(pod *v1.Pod) error {
|
func (p *HyperProvider) CreatePod(pod *v1.Pod) error {
|
||||||
@@ -98,10 +140,12 @@ func (p *HyperProvider) CreatePod(pod *v1.Pod) error {
|
|||||||
// Iterate over the containers to create and start them.
|
// Iterate over the containers to create and start them.
|
||||||
for k, ctr := range containers {
|
for k, ctr := range containers {
|
||||||
containerName := fmt.Sprintf("pod-%s-%s", pod.Name, pod.Spec.Containers[k].Name)
|
containerName := fmt.Sprintf("pod-%s-%s", pod.Name, pod.Spec.Containers[k].Name)
|
||||||
|
|
||||||
// Add labels to the pod containers.
|
// Add labels to the pod containers.
|
||||||
ctr.Labels = map[string]string{
|
ctr.Labels = map[string]string{
|
||||||
containerLabel: pod.Name,
|
containerLabel: pod.Name,
|
||||||
nodeLabel: p.nodeName,
|
nodeLabel: p.nodeName,
|
||||||
|
instanceTypeLabel: p.instanceType,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the container.
|
// Create the container.
|
||||||
@@ -147,7 +191,7 @@ func (p *HyperProvider) GetPodStatus(namespace, name string) (*v1.PodStatus, err
|
|||||||
|
|
||||||
// GetPods returns a list of all pods known to be running within hyper.sh.
|
// GetPods returns a list of all pods known to be running within hyper.sh.
|
||||||
func (p *HyperProvider) GetPods() ([]*v1.Pod, error) {
|
func (p *HyperProvider) GetPods() ([]*v1.Pod, error) {
|
||||||
filter, err := filters.FromParam(nodeLabel + "=" + p.nodeName)
|
filter, err := filters.FromParam(fmt.Sprintf("{\"%v\":{\"%v\":true}}", nodeLabel, p.nodeName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Creating filter to get containers by node name failed: %v", err)
|
return nil, fmt.Errorf("Creating filter to get containers by node name failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user