Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker client & pause container find #5

Merged
merged 11 commits into from
Jun 2, 2018
Merged

Conversation

John-Lin
Copy link
Contributor

@John-Lin John-Lin commented Jun 2, 2018

  • finding pause container
  • docker client operate functions

@codecov
Copy link

codecov bot commented Jun 2, 2018

Codecov Report

Merging #5 into master will increase coverage by 14.12%.
The diff coverage is 38.09%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master       #5       +/-   ##
===========================================
+ Coverage   46.15%   60.27%   +14.12%     
===========================================
  Files           1        3        +2     
  Lines          52       73       +21     
===========================================
+ Hits           24       44       +20     
- Misses         22       23        +1     
  Partials        6        6
Impacted Files Coverage Δ
docker/docker.go 16.66% <16.66%> (ø)
docker/pause-container.go 66.66% <66.66%> (ø)
ovs/ovs.go 69.23% <0%> (+23.07%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4e7b84b...a29bdff. Read the comment docs.

@John-Lin John-Lin changed the title Johnlin/docker cli docker client & pause container find Jun 2, 2018
for _, container := range containers {
// ex: k8s_POD_myinit_default_05ab36d8-65aa-11e8-b35e-42010af00248_0
pattern := fmt.Sprintf("k8s_POD_%s_%s_%s_\\d+", PodName, Namespace, PodUUID)
r, err := regexp.Compile(pattern)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move out the regexp to out of the for loop, we don't need to compile it every time.

for _, container := range containers {
// ex: k8s_POD_myinit_default_05ab36d8-65aa-11e8-b35e-42010af00248_0
pattern := fmt.Sprintf("k8s_POD_%s_%s_%s_\\d+", PodName, Namespace, PodUUID)
r, err := regexp.Compile(pattern)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The err checking should also be moved out.

@John-Lin
Copy link
Contributor Author

John-Lin commented Jun 2, 2018

docker client is difficult to write tests.

@John-Lin
Copy link
Contributor Author

John-Lin commented Jun 2, 2018

init container can get pod name, namespace, pod uuid from downward API. we could use these to send to network controller server. the network controller using these information to find pause container ID and network namespace path.
example pod yaml

apiVersion: v1
kind: Pod
metadata:
  name: myinit
spec:
  containers:
  - name: app-container
    image: busybox
    command:
      - env
  initContainers:
  - name: init-container
    image: busybox
    command:
    - env
    env:
    - name: MY_POD_NAME
      valueFrom:
        fieldRef:
          fieldPath: metadata.name
    - name: MY_POD_NAMESPACE
      valueFrom:
        fieldRef:
          fieldPath: metadata.namespace
    - name: MY_POD_UUID
      valueFrom:
        fieldRef:
          fieldPath: metadata.uid
    - name: MY_POD_IP
      valueFrom:
        fieldRef:
          fieldPath: status.podIP

@hwchiu hwchiu added the enhancement New feature or request label Jun 2, 2018
@hwchiu
Copy link
Contributor

hwchiu commented Jun 2, 2018

Move out the err check function of regexp from for loop and add some invalid testing.

@linkernetworks linkernetworks locked and limited conversation to collaborators Jun 2, 2018
@linkernetworks linkernetworks unlocked this conversation Jun 2, 2018
Copy link
Contributor

@hwchiu hwchiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hwchiu hwchiu requested a review from chenyunchen June 2, 2018 15:24
@John-Lin John-Lin force-pushed the johnlin/docker-cli branch from ccb0723 to a29bdff Compare June 2, 2018 15:46
@John-Lin John-Lin merged commit 217d6b7 into master Jun 2, 2018
)

// docker ps -a <Container ID>
func ListContainer() ([]types.Container, error) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use new struct to composite the parent one so that you don’t have to recreate the client.


// docker ps -a <Container ID>
func ListContainer() ([]types.Container, error) {
cli, err := client.NewEnvClient()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapping the env client constructor inside the function makes it hard to be customized.

@John-Lin John-Lin deleted the johnlin/docker-cli branch June 5, 2018 03:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants