Skip to content

Commit

Permalink
Support the restart policy for pod
Browse files Browse the repository at this point in the history
  • Loading branch information
hwchiu committed Jul 25, 2018
1 parent e355d85 commit 602918e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
19 changes: 10 additions & 9 deletions src/entity/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,23 @@ type PodNetwork struct {
BridgeName string `bson:"bridgeName" json:"bridgeName"` //its from the entity.Network entity
}

// PodVolume is the structure for pof volume info
// PodVolume is the structure for pof volume info
type PodVolume struct {
Name string `bson:"name" json:"name" validate:"required"`
MountPath string `bson:"mountPath" json:"mountPath" validate:"required"`
}

// Pod is the structure for pod info
type Pod struct {
ID bson.ObjectId `bson:"_id,omitempty" json:"id" validate:"-"`
Name string `bson:"name" json:"name" validate:"required,k8sname"`
Namespace string `bson:"namespace" json:"namespace" validate:"required"`
Labels map[string]string `bson:"labels,omitempty" json:"labels" validate:"required,dive,keys,alphanum,endkeys,required,alphanum"`
Containers []Container `bson:"containers" json:"containers" validate:"required,dive,required"`
CreatedAt *time.Time `bson:"createdAt,omitempty" json:"createdAt,omitempty" validate:"-"`
Volumes []PodVolume `bson:"volumes,omitempty" json:"volumes" validate:"required,dive,required"`
Networks []PodNetwork `bson:"networks,omitempty" json:"networks" validate:"required,dive,required"`
ID bson.ObjectId `bson:"_id,omitempty" json:"id" validate:"-"`
Name string `bson:"name" json:"name" validate:"required,k8sname"`
Namespace string `bson:"namespace" json:"namespace" validate:"required"`
Labels map[string]string `bson:"labels,omitempty" json:"labels" validate:"required,dive,keys,alphanum,endkeys,required,alphanum"`
Containers []Container `bson:"containers" json:"containers" validate:"required,dive,required"`
CreatedAt *time.Time `bson:"createdAt,omitempty" json:"createdAt,omitempty" validate:"-"`
Volumes []PodVolume `bson:"volumes,omitempty" json:"volumes" validate:"required,dive,required"`
Networks []PodNetwork `bson:"networks,omitempty" json:"networks" validate:"required,dive,required"`
RestartPolicy string `bson:"restartPolicy" json:"restartPolicy" validate:"required,eq=Always|eq=OnFailure|eq=Never`
}

// GetCollection - get model mongo collection name.
Expand Down
2 changes: 1 addition & 1 deletion src/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func CreatePod(sp *serviceprovider.Container, pod *entity.Pod) error {
Containers: containers,
Volumes: volumes,
Affinity: generateAffinity(nodeNames),
RestartPolicy: corev1.RestartPolicyOnFailure,
RestartPolicy: corev1.RestartPolicy(pod.RestartPolicy),
},
}

Expand Down
14 changes: 7 additions & 7 deletions src/server/handler_pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ func (suite *PodTestSuite) TestCreatePod() {
}
tName := namesgenerator.GetRandomName(0)
pod := entity.Pod{
Name: tName,
Namespace: namespace,
Labels: map[string]string{},
Containers: containers,
Volumes: []entity.PodVolume{},
Networks: []entity.PodNetwork{},
Name: tName,
Namespace: namespace,
Labels: map[string]string{},
Containers: containers,
Volumes: []entity.PodVolume{},
Networks: []entity.PodNetwork{},
RestartPolicy: "Never",
}

bodyBytes, err := json.MarshalIndent(pod, "", " ")
suite.NoError(err)

Expand Down

0 comments on commit 602918e

Please sign in to comment.