gofmt the project files (#205)
This commit is contained in:
@@ -17,15 +17,15 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/virtual-kubelet/virtual-kubelet/version"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/virtual-kubelet/virtual-kubelet/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
// versionCmd represents the version command
|
// versionCmd represents the version command
|
||||||
var versionCmd = &cobra.Command{
|
var versionCmd = &cobra.Command{
|
||||||
Use: "version",
|
Use: "version",
|
||||||
Short: "Show the version of the program",
|
Short: "Show the version of the program",
|
||||||
Long: `Show the version of the program`,
|
Long: `Show the version of the program`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
fmt.Printf("Version: %s, Built: %s", version.Version, version.BuildTime)
|
fmt.Printf("Version: %s, Built: %s", version.Version, version.BuildTime)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ import (
|
|||||||
|
|
||||||
// AADMock implements a AAD mock server .
|
// AADMock implements a AAD mock server .
|
||||||
type AADMock struct {
|
type AADMock struct {
|
||||||
server *httptest.Server
|
server *httptest.Server
|
||||||
OnAcquireToken func(http.ResponseWriter,*http.Request)
|
OnAcquireToken func(http.ResponseWriter, *http.Request)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAADMock creates a new AAD server mocker.
|
// NewAADMock creates a new AAD server mocker.
|
||||||
@@ -26,7 +26,7 @@ func NewAADMock() *AADMock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start the AAD server mocker.
|
// Start the AAD server mocker.
|
||||||
func (mock *AADMock)start() {
|
func (mock *AADMock) start() {
|
||||||
if mock.server != nil {
|
if mock.server != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -40,8 +40,8 @@ func (mock *AADMock)start() {
|
|||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
token := adal.Token{
|
token := adal.Token{
|
||||||
AccessToken: "Test Token",
|
AccessToken: "Test Token",
|
||||||
NotBefore: strconv.FormatInt(time.Now().UnixNano(), 10),
|
NotBefore: strconv.FormatInt(time.Now().UnixNano(), 10),
|
||||||
ExpiresIn: strconv.FormatInt(int64(time.Minute), 10),
|
ExpiresIn: strconv.FormatInt(int64(time.Minute), 10),
|
||||||
}
|
}
|
||||||
|
|
||||||
b := new(bytes.Buffer)
|
b := new(bytes.Buffer)
|
||||||
@@ -51,7 +51,7 @@ func (mock *AADMock)start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetServerURL returns the mock server URL.
|
// GetServerURL returns the mock server URL.
|
||||||
func (mock *AADMock)GetServerURL() string {
|
func (mock *AADMock) GetServerURL() string {
|
||||||
if mock.server != nil {
|
if mock.server != nil {
|
||||||
return mock.server.URL
|
return mock.server.URL
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,7 @@ func (mock *AADMock)GetServerURL() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Close terminates the AAD server mocker.
|
// Close terminates the AAD server mocker.
|
||||||
func (mock *AADMock)Close() {
|
func (mock *AADMock) Close() {
|
||||||
if mock.server != nil {
|
if mock.server != nil {
|
||||||
mock.server.Close()
|
mock.server.Close()
|
||||||
mock.server = nil
|
mock.server = nil
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ import (
|
|||||||
|
|
||||||
// ACIMock implements a Azure Container Instance mock server.
|
// ACIMock implements a Azure Container Instance mock server.
|
||||||
type ACIMock struct {
|
type ACIMock struct {
|
||||||
server *httptest.Server
|
server *httptest.Server
|
||||||
OnCreate func(string, string, string, *aci.ContainerGroup) (int, interface{})
|
OnCreate func(string, string, string, *aci.ContainerGroup) (int, interface{})
|
||||||
OnGetContainerGroups func(string, string) (int, interface{})
|
OnGetContainerGroups func(string, string) (int, interface{})
|
||||||
OnGetContainerGroup func(string, string, string) (int, interface{})
|
OnGetContainerGroup func(string, string, string) (int, interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ import (
|
|||||||
azure "github.com/virtual-kubelet/virtual-kubelet/providers/azure/client"
|
azure "github.com/virtual-kubelet/virtual-kubelet/providers/azure/client"
|
||||||
"github.com/virtual-kubelet/virtual-kubelet/providers/azure/client/aci"
|
"github.com/virtual-kubelet/virtual-kubelet/providers/azure/client/aci"
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/client-go/kubernetes/fake"
|
"k8s.io/client-go/kubernetes/fake"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ const (
|
|||||||
fakeClientID = "f14193ad-4c4c-4876-a18a-c0badb3bbd40"
|
fakeClientID = "f14193ad-4c4c-4876-a18a-c0badb3bbd40"
|
||||||
fakeClientSecret = "VGhpcyBpcyBhIHNlY3JldAo="
|
fakeClientSecret = "VGhpcyBpcyBhIHNlY3JldAo="
|
||||||
fakeTenantID = "8cb81aca-83fe-4c6f-b667-4ec09c45a8bf"
|
fakeTenantID = "8cb81aca-83fe-4c6f-b667-4ec09c45a8bf"
|
||||||
fakeNodeName = "vk"
|
fakeNodeName = "vk"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Tests create pod without resource spec
|
// Tests create pod without resource spec
|
||||||
@@ -47,7 +47,7 @@ func TestCreatePodWithoutResourceSpec(t *testing.T) {
|
|||||||
assert.Equal(t, fakeSubscription, subscription, "Subscription doesn't match")
|
assert.Equal(t, fakeSubscription, subscription, "Subscription doesn't match")
|
||||||
assert.Equal(t, fakeResourceGroup, resourceGroup, "Resource group doesn't match")
|
assert.Equal(t, fakeResourceGroup, resourceGroup, "Resource group doesn't match")
|
||||||
assert.NotNil(t, cg, "Container group is nil")
|
assert.NotNil(t, cg, "Container group is nil")
|
||||||
assert.Equal(t, podNamespace + "-" + podName, containerGroup, "Container group name is not expected")
|
assert.Equal(t, podNamespace+"-"+podName, containerGroup, "Container group name is not expected")
|
||||||
assert.NotNil(t, cg.ContainerGroupProperties, "Container group properties should not be nil")
|
assert.NotNil(t, cg.ContainerGroupProperties, "Container group properties should not be nil")
|
||||||
assert.NotNil(t, cg.ContainerGroupProperties.Containers, "Containers should not be nil")
|
assert.NotNil(t, cg.ContainerGroupProperties.Containers, "Containers should not be nil")
|
||||||
assert.Equal(t, 1, len(cg.ContainerGroupProperties.Containers), "1 Container is expected")
|
assert.Equal(t, 1, len(cg.ContainerGroupProperties.Containers), "1 Container is expected")
|
||||||
@@ -95,7 +95,7 @@ func TestCreatePodWithResourceRequestOnly(t *testing.T) {
|
|||||||
assert.Equal(t, fakeSubscription, subscription, "Subscription doesn't match")
|
assert.Equal(t, fakeSubscription, subscription, "Subscription doesn't match")
|
||||||
assert.Equal(t, fakeResourceGroup, resourceGroup, "Resource group doesn't match")
|
assert.Equal(t, fakeResourceGroup, resourceGroup, "Resource group doesn't match")
|
||||||
assert.NotNil(t, cg, "Container group is nil")
|
assert.NotNil(t, cg, "Container group is nil")
|
||||||
assert.Equal(t, podNamespace + "-" + podName, containerGroup, "Container group name is not expected")
|
assert.Equal(t, podNamespace+"-"+podName, containerGroup, "Container group name is not expected")
|
||||||
assert.NotNil(t, cg.ContainerGroupProperties, "Container group properties should not be nil")
|
assert.NotNil(t, cg.ContainerGroupProperties, "Container group properties should not be nil")
|
||||||
assert.NotNil(t, cg.ContainerGroupProperties.Containers, "Containers should not be nil")
|
assert.NotNil(t, cg.ContainerGroupProperties.Containers, "Containers should not be nil")
|
||||||
assert.Equal(t, 1, len(cg.ContainerGroupProperties.Containers), "1 Container is expected")
|
assert.Equal(t, 1, len(cg.ContainerGroupProperties.Containers), "1 Container is expected")
|
||||||
@@ -120,7 +120,7 @@ func TestCreatePodWithResourceRequestOnly(t *testing.T) {
|
|||||||
Name: "nginx",
|
Name: "nginx",
|
||||||
Resources: v1.ResourceRequirements{
|
Resources: v1.ResourceRequirements{
|
||||||
Requests: v1.ResourceList{
|
Requests: v1.ResourceList{
|
||||||
"cpu": resource.MustParse("1.981"),
|
"cpu": resource.MustParse("1.981"),
|
||||||
"memory": resource.MustParse("3.49G"),
|
"memory": resource.MustParse("3.49G"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -149,7 +149,7 @@ func TestCreatePodWithResourceRequestAndLimit(t *testing.T) {
|
|||||||
assert.Equal(t, fakeSubscription, subscription, "Subscription doesn't match")
|
assert.Equal(t, fakeSubscription, subscription, "Subscription doesn't match")
|
||||||
assert.Equal(t, fakeResourceGroup, resourceGroup, "Resource group doesn't match")
|
assert.Equal(t, fakeResourceGroup, resourceGroup, "Resource group doesn't match")
|
||||||
assert.NotNil(t, cg, "Container group is nil")
|
assert.NotNil(t, cg, "Container group is nil")
|
||||||
assert.Equal(t, podNamespace + "-" + podName, containerGroup, "Container group name is not expected")
|
assert.Equal(t, podNamespace+"-"+podName, containerGroup, "Container group name is not expected")
|
||||||
assert.NotNil(t, cg.ContainerGroupProperties, "Container group properties should not be nil")
|
assert.NotNil(t, cg.ContainerGroupProperties, "Container group properties should not be nil")
|
||||||
assert.NotNil(t, cg.ContainerGroupProperties.Containers, "Containers should not be nil")
|
assert.NotNil(t, cg.ContainerGroupProperties.Containers, "Containers should not be nil")
|
||||||
assert.Equal(t, 1, len(cg.ContainerGroupProperties.Containers), "1 Container is expected")
|
assert.Equal(t, 1, len(cg.ContainerGroupProperties.Containers), "1 Container is expected")
|
||||||
@@ -175,11 +175,11 @@ func TestCreatePodWithResourceRequestAndLimit(t *testing.T) {
|
|||||||
Name: "nginx",
|
Name: "nginx",
|
||||||
Resources: v1.ResourceRequirements{
|
Resources: v1.ResourceRequirements{
|
||||||
Requests: v1.ResourceList{
|
Requests: v1.ResourceList{
|
||||||
"cpu": resource.MustParse("1.981"),
|
"cpu": resource.MustParse("1.981"),
|
||||||
"memory": resource.MustParse("3.49G"),
|
"memory": resource.MustParse("3.49G"),
|
||||||
},
|
},
|
||||||
Limits: v1.ResourceList{
|
Limits: v1.ResourceList{
|
||||||
"cpu": resource.MustParse("3999m"),
|
"cpu": resource.MustParse("3999m"),
|
||||||
"memory": resource.MustParse("8010M"),
|
"memory": resource.MustParse("8010M"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -252,8 +252,8 @@ func TestGetPodsWithoutResourceRequestsLimits(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Resources: aci.ResourceRequirements{
|
Resources: aci.ResourceRequirements{
|
||||||
Requests: &aci.ResourceRequests{
|
Requests: &aci.ResourceRequests{
|
||||||
CPU: 0.99,
|
CPU: 0.99,
|
||||||
MemoryInGB: 1.5,
|
MemoryInGB: 1.5,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -308,7 +308,7 @@ func TestGetPodWithoutResourceRequestsLimits(t *testing.T) {
|
|||||||
aciServerMocker.OnGetContainerGroup = func(subscription, resourceGroup, containerGroup string) (int, interface{}) {
|
aciServerMocker.OnGetContainerGroup = func(subscription, resourceGroup, containerGroup string) (int, interface{}) {
|
||||||
assert.Equal(t, fakeSubscription, subscription, "Subscription doesn't match")
|
assert.Equal(t, fakeSubscription, subscription, "Subscription doesn't match")
|
||||||
assert.Equal(t, fakeResourceGroup, resourceGroup, "Resource group doesn't match")
|
assert.Equal(t, fakeResourceGroup, resourceGroup, "Resource group doesn't match")
|
||||||
assert.Equal(t, podNamespace + "-" + podName, containerGroup, "Container group name is not expected")
|
assert.Equal(t, podNamespace+"-"+podName, containerGroup, "Container group name is not expected")
|
||||||
|
|
||||||
return http.StatusOK, aci.ContainerGroup{
|
return http.StatusOK, aci.ContainerGroup{
|
||||||
Tags: map[string]string{
|
Tags: map[string]string{
|
||||||
@@ -330,8 +330,8 @@ func TestGetPodWithoutResourceRequestsLimits(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Resources: aci.ResourceRequirements{
|
Resources: aci.ResourceRequirements{
|
||||||
Requests: &aci.ResourceRequests{
|
Requests: &aci.ResourceRequests{
|
||||||
CPU: 0.99,
|
CPU: 0.99,
|
||||||
MemoryInGB: 1.5,
|
MemoryInGB: 1.5,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
azure "github.com/virtual-kubelet/virtual-kubelet/providers/azure/client"
|
azure "github.com/virtual-kubelet/virtual-kubelet/providers/azure/client"
|
||||||
"github.com/virtual-kubelet/virtual-kubelet/providers/azure/client/resourcegroups"
|
"github.com/virtual-kubelet/virtual-kubelet/providers/azure/client/resourcegroups"
|
||||||
"github.com/google/uuid"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -72,9 +72,9 @@ func TestMain(m *testing.M) {
|
|||||||
|
|
||||||
func TestNewClient(t *testing.T) {
|
func TestNewClient(t *testing.T) {
|
||||||
auth, err := azure.NewAuthenticationFromFile("../../../../credentials.json")
|
auth, err := azure.NewAuthenticationFromFile("../../../../credentials.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to load Azure authentication file: %v", err)
|
log.Fatalf("Failed to load Azure authentication file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := NewClient(auth)
|
c, err := NewClient(auth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -33,29 +33,29 @@ func NewAuthentication(azureCloud, clientID, clientSecret, subscriptionID, tenan
|
|||||||
switch azureCloud {
|
switch azureCloud {
|
||||||
case PublicCloud.Name:
|
case PublicCloud.Name:
|
||||||
environment = PublicCloud
|
environment = PublicCloud
|
||||||
break;
|
break
|
||||||
case USGovernmentCloud.Name:
|
case USGovernmentCloud.Name:
|
||||||
environment = USGovernmentCloud
|
environment = USGovernmentCloud
|
||||||
break;
|
break
|
||||||
case ChinaCloud.Name:
|
case ChinaCloud.Name:
|
||||||
environment = ChinaCloud
|
environment = ChinaCloud
|
||||||
break;
|
break
|
||||||
case GermanCloud.Name:
|
case GermanCloud.Name:
|
||||||
environment = GermanCloud
|
environment = GermanCloud
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Authentication{
|
return &Authentication{
|
||||||
ClientID: clientID,
|
ClientID: clientID,
|
||||||
ClientSecret: clientSecret,
|
ClientSecret: clientSecret,
|
||||||
SubscriptionID: subscriptionID,
|
SubscriptionID: subscriptionID,
|
||||||
TenantID: tenantID,
|
TenantID: tenantID,
|
||||||
ActiveDirectoryEndpoint: environment.ActiveDirectoryEndpoint,
|
ActiveDirectoryEndpoint: environment.ActiveDirectoryEndpoint,
|
||||||
ResourceManagerEndpoint: environment.ResourceManagerEndpoint,
|
ResourceManagerEndpoint: environment.ResourceManagerEndpoint,
|
||||||
GraphResourceID: environment.GraphEndpoint,
|
GraphResourceID: environment.GraphEndpoint,
|
||||||
SQLManagementEndpoint: environment.SQLDatabaseDNSSuffix,
|
SQLManagementEndpoint: environment.SQLDatabaseDNSSuffix,
|
||||||
GalleryEndpoint: environment.GalleryEndpoint,
|
GalleryEndpoint: environment.GalleryEndpoint,
|
||||||
ManagementEndpoint: environment.ServiceManagementEndpoint,
|
ManagementEndpoint: environment.ServiceManagementEndpoint,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"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 {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
var p Provider
|
var p Provider
|
||||||
var r mux.Router
|
var r mux.Router
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package vkubelet
|
|||||||
import (
|
import (
|
||||||
"github.com/virtual-kubelet/virtual-kubelet/providers/aws"
|
"github.com/virtual-kubelet/virtual-kubelet/providers/aws"
|
||||||
"github.com/virtual-kubelet/virtual-kubelet/providers/azure"
|
"github.com/virtual-kubelet/virtual-kubelet/providers/azure"
|
||||||
|
"github.com/virtual-kubelet/virtual-kubelet/providers/cri"
|
||||||
"github.com/virtual-kubelet/virtual-kubelet/providers/hypersh"
|
"github.com/virtual-kubelet/virtual-kubelet/providers/hypersh"
|
||||||
"github.com/virtual-kubelet/virtual-kubelet/providers/web"
|
"github.com/virtual-kubelet/virtual-kubelet/providers/web"
|
||||||
"github.com/virtual-kubelet/virtual-kubelet/providers/cri"
|
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ import (
|
|||||||
"github.com/virtual-kubelet/virtual-kubelet/manager"
|
"github.com/virtual-kubelet/virtual-kubelet/manager"
|
||||||
"github.com/virtual-kubelet/virtual-kubelet/providers/aws"
|
"github.com/virtual-kubelet/virtual-kubelet/providers/aws"
|
||||||
"github.com/virtual-kubelet/virtual-kubelet/providers/azure"
|
"github.com/virtual-kubelet/virtual-kubelet/providers/azure"
|
||||||
|
"github.com/virtual-kubelet/virtual-kubelet/providers/cri"
|
||||||
"github.com/virtual-kubelet/virtual-kubelet/providers/hypersh"
|
"github.com/virtual-kubelet/virtual-kubelet/providers/hypersh"
|
||||||
"github.com/virtual-kubelet/virtual-kubelet/providers/mock"
|
"github.com/virtual-kubelet/virtual-kubelet/providers/mock"
|
||||||
"github.com/virtual-kubelet/virtual-kubelet/providers/web"
|
"github.com/virtual-kubelet/virtual-kubelet/providers/web"
|
||||||
"github.com/virtual-kubelet/virtual-kubelet/providers/cri"
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/errors"
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
@@ -150,10 +150,10 @@ func (s *Server) registerNode() error {
|
|||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: s.nodeName,
|
Name: s.nodeName,
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
"type": "virtual-kubelet",
|
"type": "virtual-kubelet",
|
||||||
"kubernetes.io/role": "agent",
|
"kubernetes.io/role": "agent",
|
||||||
"beta.kubernetes.io/os": strings.ToLower(s.provider.OperatingSystem()),
|
"beta.kubernetes.io/os": strings.ToLower(s.provider.OperatingSystem()),
|
||||||
"kubernetes.io/hostname": s.nodeName,
|
"kubernetes.io/hostname": s.nodeName,
|
||||||
"alpha.service-controller.kubernetes.io/exclude-balancer": "true",
|
"alpha.service-controller.kubernetes.io/exclude-balancer": "true",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user