Runtime custom docker img (#1168)
* Add DeploymentOptions to K8s Client * WithBaseImage for Runtime * Revert Change * Fix sequencing
This commit is contained in:
@@ -226,9 +226,11 @@ func NewService(name, version, typ string) *Service {
|
||||
}
|
||||
|
||||
// NewService returns default micro kubernetes deployment definition
|
||||
func NewDeployment(name, version, typ string) *Deployment {
|
||||
func NewDeployment(name, version, typ string, opts ...DeploymentOption) *Deployment {
|
||||
log.Tracef("kubernetes default deployment: name: %s, version: %s", name, version)
|
||||
|
||||
options := NewDeploymentOptions(opts)
|
||||
|
||||
Labels := map[string]string{
|
||||
"name": name,
|
||||
"version": version,
|
||||
@@ -265,7 +267,7 @@ func NewDeployment(name, version, typ string) *Deployment {
|
||||
PodSpec: &PodSpec{
|
||||
Containers: []Container{{
|
||||
Name: name,
|
||||
Image: DefaultImage,
|
||||
Image: options.BaseImage,
|
||||
Env: []EnvVar{env},
|
||||
Command: []string{"go", "run", "main.go"},
|
||||
Ports: []ContainerPort{{
|
||||
|
@@ -1,5 +1,9 @@
|
||||
package client
|
||||
|
||||
type DeploymentOptions struct {
|
||||
BaseImage string
|
||||
}
|
||||
|
||||
type LogOptions struct {
|
||||
Params map[string]string
|
||||
}
|
||||
@@ -10,6 +14,7 @@ type WatchOptions struct {
|
||||
|
||||
type LogOption func(*LogOptions)
|
||||
type WatchOption func(*WatchOptions)
|
||||
type DeploymentOption func(*DeploymentOptions)
|
||||
|
||||
// LogParams provides additional params for logs
|
||||
func LogParams(p map[string]string) LogOption {
|
||||
@@ -24,3 +29,24 @@ func WatchParams(p map[string]string) WatchOption {
|
||||
w.Params = p
|
||||
}
|
||||
}
|
||||
|
||||
// WithBaseImage sets the base image for the deployment
|
||||
func WithBaseImage(img string) DeploymentOption {
|
||||
return func(d *DeploymentOptions) {
|
||||
d.BaseImage = img
|
||||
}
|
||||
}
|
||||
|
||||
// NewDeploymentOptions returns an initialized DeploymentOptions
|
||||
func NewDeploymentOptions(opts []DeploymentOption) DeploymentOptions {
|
||||
var options DeploymentOptions
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
|
||||
if options.BaseImage == "" {
|
||||
options.BaseImage = DefaultImage
|
||||
}
|
||||
|
||||
return options
|
||||
}
|
||||
|
Reference in New Issue
Block a user