Skip to content

Commit

Permalink
Support hostnetwork
Browse files Browse the repository at this point in the history
  • Loading branch information
hwchiu committed Jul 27, 2018
1 parent e7cbe75 commit 547f322
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,8 @@ For each Pod, we have fileds need to handle.
7. capability: the power of the container, if it's ture, it will get almost all capability and act as a privileged=true.
8. restartPolicy: the attribute how the pod restart is container, it should be a string and only valid for those following strings.
- Always,OnFailure,Never
9. hostNetwork: the bool option to run the Pod in the host network namespace, if it's true, all values in the networks will be ignored.


Example:

Expand Down
1 change: 1 addition & 0 deletions src/entity/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Pod struct {
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`
Capability bool `bson:"capability" json:"Capability" validate:"required"`
HostNetwork bool `bson:"hostNetwork" json:"hostNetwork" validate:"required"`
}

// GetCollection - get model mongo collection name.
Expand Down
14 changes: 11 additions & 3 deletions src/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,16 @@ func CreatePod(sp *serviceprovider.Container, pod *entity.Pod) error {
return err
}

nodeNames, initContainers, err := generateNetwork(session, pod)
if err != nil {
return err
nodeNames := []string{}
initContainers := []corev1.Container{}
hostNetwork := false
if pod.HostNetwork {
hostNetwork = true
} else {
nodeNames, initContainers, err = generateNetwork(session, pod)
if err != nil {
return err
}
}

volumes = append(volumes, corev1.Volume{
Expand Down Expand Up @@ -268,6 +275,7 @@ func CreatePod(sp *serviceprovider.Container, pod *entity.Pod) error {
Volumes: volumes,
Affinity: generateAffinity(nodeNames),
RestartPolicy: corev1.RestartPolicy(pod.RestartPolicy),
HostNetwork: hostNetwork,
},
}

Expand Down
1 change: 1 addition & 0 deletions src/server/handler_pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func (suite *PodTestSuite) TestCreatePod() {
Networks: []entity.PodNetwork{},
Capability: true,
RestartPolicy: "Never",
HostNetwork: false,
}
bodyBytes, err := json.MarshalIndent(pod, "", " ")
suite.NoError(err)
Expand Down
3 changes: 2 additions & 1 deletion tests/pod.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@
],
"volumes":[],
"restaryPolicy":"Always",
"capability": true
"capability": true,
"hostNetwork":false
}

0 comments on commit 547f322

Please sign in to comment.