@@ -35,27 +35,27 @@ type DockerPodController struct {
35
35
func (c * DockerPodController ) Apply (ctx context.Context , name string , container * Container ) error {
36
36
imageRef := c .imageRegistry .Fix (container .Image )
37
37
38
- if err := c .PullImageIfNotExists (ctx , imageRef ); err != nil {
38
+ if err := c .pullImageIfNotExists (ctx , imageRef ); err != nil {
39
39
return err
40
40
}
41
41
42
42
container .Annotations = map [string ]string {
43
43
"pipeline" : name ,
44
44
}
45
45
46
- list , err := c .ListMatchedRunningContainer (ctx , name )
46
+ list , err := c .listMatchedRunningContainer (ctx , name )
47
47
if err != nil {
48
48
return err
49
49
}
50
50
51
51
current := len (list )
52
52
53
- offset := current - container .Replicas
53
+ offset := current - int ( container .Replicas )
54
54
55
55
// scale up
56
56
if offset < 0 {
57
57
for i := 0 ; i < - offset ; i ++ {
58
- if err := c .RunContainer (ctx , imageRef , container ); err != nil {
58
+ if err := c .runContainer (ctx , imageRef , container ); err != nil {
59
59
return err
60
60
}
61
61
}
@@ -67,7 +67,7 @@ func (c *DockerPodController) Apply(ctx context.Context, name string, container
67
67
rand .Shuffle (len (list ), func (i , j int ) { list [i ], list [j ] = list [j ], list [i ] })
68
68
69
69
for _ , item := range list [0 :offset ] {
70
- if err := c .KillContainer (ctx , item .ID ); err != nil {
70
+ if err := c .killContainer (ctx , item .ID ); err != nil {
71
71
return err
72
72
}
73
73
}
@@ -77,33 +77,35 @@ func (c *DockerPodController) Apply(ctx context.Context, name string, container
77
77
}
78
78
79
79
func (c * DockerPodController ) Kill (ctx context.Context , name string ) error {
80
- list , err := c .ListMatchedRunningContainer (ctx , name )
80
+ list , err := c .listMatchedRunningContainer (ctx , name )
81
81
if err != nil {
82
82
return err
83
83
}
84
84
85
85
for i := range list {
86
- if err := c .KillContainer (ctx , list [i ].ID ); err != nil {
86
+ if err := c .killContainer (ctx , list [i ].ID ); err != nil {
87
87
return err
88
88
}
89
89
}
90
90
91
91
return nil
92
92
}
93
93
94
- func (c * DockerPodController ) ListMatchedRunningContainer (ctx context.Context , name string ) ([]types.Container , error ) {
94
+ func (c * DockerPodController ) listMatchedRunningContainer (ctx context.Context , name string ) ([]types.Container , error ) {
95
95
containerListFilters := filters .NewArgs ()
96
96
containerListFilters .Add ("label" , "pipeline=" + name )
97
97
98
- return c .ListRunningContainer (ctx , containerListFilters )
98
+ return c .listRunningContainer (ctx , containerListFilters )
99
99
}
100
100
101
- func (c * DockerPodController ) RunContainer (ctx context.Context , image string , cc * Container ) error {
101
+ func (c * DockerPodController ) runContainer (ctx context.Context , image string , cc * Container ) error {
102
102
logrus .WithContext (ctx ).Debugf ("running from %s" , image )
103
103
104
104
containerConfig := & container.Config {
105
- Image : image ,
106
- Labels : cc .Annotations ,
105
+ Image : image ,
106
+ Labels : cc .Annotations ,
107
+ Entrypoint : cc .Command ,
108
+ Cmd : cc .Args ,
107
109
}
108
110
109
111
for k := range cc .Envs {
@@ -143,20 +145,20 @@ func (c *DockerPodController) RunContainer(ctx context.Context, image string, cc
143
145
return nil
144
146
}
145
147
146
- func (c * DockerPodController ) ListRunningContainer (ctx context.Context , args filters.Args ) ([]types.Container , error ) {
148
+ func (c * DockerPodController ) listRunningContainer (ctx context.Context , args filters.Args ) ([]types.Container , error ) {
147
149
return c .client .ContainerList (ctx , types.ContainerListOptions {
148
150
Filters : args ,
149
151
All : false ,
150
152
})
151
153
}
152
154
153
- func (c * DockerPodController ) KillContainer (ctx context.Context , containerID string ) error {
155
+ func (c * DockerPodController ) killContainer (ctx context.Context , containerID string ) error {
154
156
logrus .WithContext (ctx ).Debugf ("killing %s" , containerID )
155
157
156
158
return c .client .ContainerKill (ctx , containerID , "SIGKILL" )
157
159
}
158
160
159
- func (c * DockerPodController ) PullImageIfNotExists (ctx context.Context , image string ) error {
161
+ func (c * DockerPodController ) pullImageIfNotExists (ctx context.Context , image string ) error {
160
162
imageListFilters := filters .NewArgs ()
161
163
imageListFilters .Add ("reference" , strings .Replace (image , "docker.io/library/" , "" , 1 ))
162
164
0 commit comments