-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from linkernetworks/hwchiu/VX-120
Refactor the storage to support multiple type. Former-commit-id: e2b3d4eba6df59dc1cdac3cfd86886c3a94606f4 [formerly e2b3d4eba6df59dc1cdac3cfd86886c3a94606f4 [formerly eff9da7]] Former-commit-id: 0909f1887eef2607b7a546134493f10327e141f6 Former-commit-id: 8311ae2
- Loading branch information
Showing
19 changed files
with
769 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package entity | ||
|
||
type FakeNetwork struct { | ||
FakeParameter string `bson:"bridgeName" json:"bridgeName"` | ||
IWantFail bool `bson:"iWantFail" json:"iWantFail"` | ||
FakeParameter string | ||
IWantFail bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package entity | ||
|
||
import ( | ||
"time" | ||
|
||
"gopkg.in/mgo.v2/bson" | ||
) | ||
|
||
type StorageType string | ||
|
||
const ( | ||
NFSStorageType = "nfs" | ||
FakeStorageType = "fake" | ||
) | ||
|
||
const ( | ||
StorageCollectionName string = "storage" | ||
) | ||
|
||
type Storage struct { | ||
ID bson.ObjectId `bson:"_id,omitempty" json:"id"` | ||
Type StorageType `bson:"type" json:"type"` | ||
Name string `bson:"name" json:"name"` | ||
CreatedAt *time.Time `bson:"createdAt,omitempty" json:"createdAt,omitempty"` | ||
NFS NFSStorage `bson:"nfs" json:"nfs"` | ||
Fake FakeStorage `json:"fake"` //FakeNetwork, for restful testing. | ||
} | ||
|
||
//GetCollection - get model mongo collection name. | ||
func (m Storage) GetCollection() string { | ||
return StorageCollectionName | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package entity | ||
|
||
type FakeStorage struct { | ||
FakeParameter string | ||
IWantFail bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package entity | ||
|
||
type NFSStorage struct { | ||
IP string `bson:"ip" json:"ip"` | ||
PATH string `bson:"path" json:"path"` | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package kubernetes | ||
|
||
import ( | ||
appsv1 "k8s.io/api/apps/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
//Get the external IP address of node | ||
func (kc *KubeCtl) CreateDeployment(deployment *appsv1.Deployment) (*appsv1.Deployment, error) { | ||
return kc.Clientset.AppsV1().Deployments(kc.Namespace).Create(deployment) | ||
} | ||
|
||
func (kc *KubeCtl) GetDeployment(name string) (*appsv1.Deployment, error) { | ||
return kc.Clientset.AppsV1().Deployments(kc.Namespace).Get(name, metav1.GetOptions{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package kubernetes | ||
|
||
import ( | ||
"math/rand" | ||
"testing" | ||
"time" | ||
|
||
"github.com/moby/moby/pkg/namesgenerator" | ||
"github.com/stretchr/testify/suite" | ||
appsv1 "k8s.io/api/apps/v1" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
fakeclientset "k8s.io/client-go/kubernetes/fake" | ||
) | ||
|
||
type KubeCtlDeploymentTestSuite struct { | ||
suite.Suite | ||
kubectl *KubeCtl | ||
fakeclient *fakeclientset.Clientset | ||
} | ||
|
||
func init() { | ||
rand.Seed(time.Now().UnixNano()) | ||
} | ||
|
||
func (suite *KubeCtlDeploymentTestSuite) SetupSuite() { | ||
suite.fakeclient = fakeclientset.NewSimpleClientset() | ||
namespace := "default" | ||
suite.kubectl = New(suite.fakeclient, namespace) | ||
} | ||
|
||
func (suite *KubeCtlDeploymentTestSuite) TearDownSuite() {} | ||
func (suite *KubeCtlDeploymentTestSuite) TestCreateDeployment() { | ||
|
||
var replicas int32 | ||
replicas = 3 | ||
name := namesgenerator.GetRandomName(0) | ||
deployment := appsv1.Deployment{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: name, | ||
}, | ||
Spec: appsv1.DeploymentSpec{ | ||
Replicas: &replicas, | ||
}, | ||
Status: appsv1.DeploymentStatus{}, | ||
} | ||
ret, err := suite.kubectl.CreateDeployment(&deployment) | ||
suite.NoError(err) | ||
suite.NotNil(ret) | ||
|
||
deploy, err := suite.kubectl.GetDeployment(name) | ||
suite.NoError(err) | ||
suite.NotNil(deploy) | ||
suite.Equal(replicas, *deploy.Spec.Replicas) | ||
} | ||
|
||
func TestDeploymentTestSuite(t *testing.T) { | ||
suite.Run(t, new(KubeCtlDeploymentTestSuite)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.