-
Notifications
You must be signed in to change notification settings - Fork 10
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
Conversation
John-Lin
commented
Jun 2, 2018
- finding pause container
- docker client operate functions
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
docker/pause-container.go
Outdated
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) |
There was a problem hiding this comment.
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.
docker/pause-container.go
Outdated
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 { |
There was a problem hiding this comment.
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.
docker client is difficult to write tests. |
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. 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 |
Move out the err check function of regexp from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
ccb0723
to
a29bdff
Compare
) | ||
|
||
// docker ps -a <Container ID> | ||
func ListContainer() ([]types.Container, error) { |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.