Runtime Custom Source (Part 2) (#1169)
This commit is contained in:
commit
16552620e0
@ -270,8 +270,10 @@ func (k *kubernetes) Create(s *runtime.Service, opts ...runtime.CreateOption) er
|
|||||||
if len(options.Type) == 0 {
|
if len(options.Type) == 0 {
|
||||||
options.Type = k.options.Type
|
options.Type = k.options.Type
|
||||||
}
|
}
|
||||||
|
if len(k.options.Source) > 0 {
|
||||||
|
s.Source = k.options.Source
|
||||||
|
}
|
||||||
|
|
||||||
// create new kubernetes micro service
|
|
||||||
service := newService(s, options)
|
service := newService(s, options)
|
||||||
|
|
||||||
// start the service
|
// start the service
|
||||||
@ -344,7 +346,6 @@ func (k *kubernetes) Delete(s *runtime.Service) error {
|
|||||||
// create new kubernetes micro service
|
// create new kubernetes micro service
|
||||||
service := newService(s, runtime.CreateOptions{
|
service := newService(s, runtime.CreateOptions{
|
||||||
Type: k.options.Type,
|
Type: k.options.Type,
|
||||||
BaseImage: k.options.Source,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return service.Stop(k.client)
|
return service.Stop(k.client)
|
||||||
|
@ -34,6 +34,14 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service {
|
|||||||
kservice := client.NewService(name, version, c.Type)
|
kservice := client.NewService(name, version, c.Type)
|
||||||
kdeploy := client.NewDeployment(name, version, c.Type)
|
kdeploy := client.NewDeployment(name, version, c.Type)
|
||||||
|
|
||||||
|
if len(s.Source) > 0 {
|
||||||
|
for i := range kdeploy.Spec.Template.PodSpec.Containers {
|
||||||
|
kdeploy.Spec.Template.PodSpec.Containers[i].Image = s.Source
|
||||||
|
kdeploy.Spec.Template.PodSpec.Containers[i].Command = []string{}
|
||||||
|
kdeploy.Spec.Template.PodSpec.Containers[i].Args = []string{name}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// attach our values to the deployment; name, version, source
|
// attach our values to the deployment; name, version, source
|
||||||
kdeploy.Metadata.Annotations["name"] = s.Name
|
kdeploy.Metadata.Annotations["name"] = s.Name
|
||||||
kdeploy.Metadata.Annotations["version"] = s.Version
|
kdeploy.Metadata.Annotations["version"] = s.Version
|
||||||
@ -64,9 +72,6 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service {
|
|||||||
// specify the command to exec
|
// specify the command to exec
|
||||||
if len(c.Command) > 0 {
|
if len(c.Command) > 0 {
|
||||||
kdeploy.Spec.Template.PodSpec.Containers[0].Command = c.Command
|
kdeploy.Spec.Template.PodSpec.Containers[0].Command = c.Command
|
||||||
} else if len(s.Source) > 0 {
|
|
||||||
// default command for our k8s service should be source
|
|
||||||
kdeploy.Spec.Template.PodSpec.Containers[0].Command = []string{"go", "run", s.Source}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return &service{
|
return &service{
|
||||||
|
@ -51,8 +51,6 @@ type CreateOptions struct {
|
|||||||
Output io.Writer
|
Output io.Writer
|
||||||
// Type of service to create
|
// Type of service to create
|
||||||
Type string
|
Type string
|
||||||
// Base image for docker
|
|
||||||
BaseImage string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadOptions queries runtime services
|
// ReadOptions queries runtime services
|
||||||
@ -94,13 +92,6 @@ func WithOutput(out io.Writer) CreateOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithBaseImage sets the docker img
|
|
||||||
func WithBaseImage(img string) CreateOption {
|
|
||||||
return func(o *CreateOptions) {
|
|
||||||
o.BaseImage = img
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReadService returns services with the given name
|
// ReadService returns services with the given name
|
||||||
func ReadService(service string) ReadOption {
|
func ReadService(service string) ReadOption {
|
||||||
return func(o *ReadOptions) {
|
return func(o *ReadOptions) {
|
||||||
|
@ -226,11 +226,9 @@ func NewService(name, version, typ string) *Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewService returns default micro kubernetes deployment definition
|
// NewService returns default micro kubernetes deployment definition
|
||||||
func NewDeployment(name, version, typ string, opts ...DeploymentOption) *Deployment {
|
func NewDeployment(name, version, typ string) *Deployment {
|
||||||
log.Tracef("kubernetes default deployment: name: %s, version: %s", name, version)
|
log.Tracef("kubernetes default deployment: name: %s, version: %s", name, version)
|
||||||
|
|
||||||
options := NewDeploymentOptions(opts)
|
|
||||||
|
|
||||||
Labels := map[string]string{
|
Labels := map[string]string{
|
||||||
"name": name,
|
"name": name,
|
||||||
"version": version,
|
"version": version,
|
||||||
@ -267,7 +265,7 @@ func NewDeployment(name, version, typ string, opts ...DeploymentOption) *Deploym
|
|||||||
PodSpec: &PodSpec{
|
PodSpec: &PodSpec{
|
||||||
Containers: []Container{{
|
Containers: []Container{{
|
||||||
Name: name,
|
Name: name,
|
||||||
Image: options.BaseImage,
|
Image: DefaultImage,
|
||||||
Env: []EnvVar{env},
|
Env: []EnvVar{env},
|
||||||
Command: []string{"go", "run", "main.go"},
|
Command: []string{"go", "run", "main.go"},
|
||||||
Ports: []ContainerPort{{
|
Ports: []ContainerPort{{
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
type DeploymentOptions struct {
|
|
||||||
BaseImage string
|
|
||||||
}
|
|
||||||
|
|
||||||
type LogOptions struct {
|
type LogOptions struct {
|
||||||
Params map[string]string
|
Params map[string]string
|
||||||
}
|
}
|
||||||
@ -14,7 +10,6 @@ type WatchOptions struct {
|
|||||||
|
|
||||||
type LogOption func(*LogOptions)
|
type LogOption func(*LogOptions)
|
||||||
type WatchOption func(*WatchOptions)
|
type WatchOption func(*WatchOptions)
|
||||||
type DeploymentOption func(*DeploymentOptions)
|
|
||||||
|
|
||||||
// LogParams provides additional params for logs
|
// LogParams provides additional params for logs
|
||||||
func LogParams(p map[string]string) LogOption {
|
func LogParams(p map[string]string) LogOption {
|
||||||
@ -29,24 +24,3 @@ func WatchParams(p map[string]string) WatchOption {
|
|||||||
w.Params = p
|
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
|
|
||||||
}
|
|
||||||
|
@ -60,6 +60,10 @@ spec:
|
|||||||
value: "{{ .Value }}"
|
value: "{{ .Value }}"
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
args:
|
||||||
|
{{- range .Args }}
|
||||||
|
- {{.}}
|
||||||
|
{{- end }}
|
||||||
command:
|
command:
|
||||||
{{- range .Command }}
|
{{- range .Command }}
|
||||||
- {{.}}
|
- {{.}}
|
||||||
|
@ -20,6 +20,7 @@ type Container struct {
|
|||||||
Image string `json:"image"`
|
Image string `json:"image"`
|
||||||
Env []EnvVar `json:"env,omitempty"`
|
Env []EnvVar `json:"env,omitempty"`
|
||||||
Command []string `json:"command,omitempty"`
|
Command []string `json:"command,omitempty"`
|
||||||
|
Args []string `json:"args,omitempty"`
|
||||||
Ports []ContainerPort `json:"ports,omitempty"`
|
Ports []ContainerPort `json:"ports,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user