未验证 提交 8fe64ab7 编写于 作者: Y Yaron Schneider 提交者: GitHub

externalize image to config (#52)

上级 3d7e9323
......@@ -19,7 +19,11 @@ func main() {
log.Fatalf("Error building Kubernetes clients: %s", err)
}
controller.NewController(kubeClient, actionsClient).Run(ctx)
cfg, err := controller.GetConfigFromEnvironment()
if err != nil {
log.Fatalf("Error getting config: %s", err)
}
controller.NewController(kubeClient, actionsClient, cfg).Run(ctx)
shutdownDuration := 5 * time.Second
log.Infof("allowing %s for graceful shutdown to complete", shutdownDuration)
......
package controller
import "github.com/kelseyhightower/envconfig"
type Config struct {
ActionsRuntimeImage string `envconfig:"RUNTIME_IMAGE" required:"true"`
}
func GetConfigFromEnvironment() (Config, error) {
c := Config{}
err := envconfig.Process("", &c)
return c, err
}
......@@ -27,7 +27,7 @@ type controller struct {
EventSourcesHandler handlers.Handler
}
func NewController(kubeClient kubernetes.Interface, actionsClient scheme.Interface) *controller {
func NewController(kubeClient kubernetes.Interface, actionsClient scheme.Interface, config Config) *controller {
c := &controller{
KubeClient: kubeClient,
ActionsClient: actionsClient,
......@@ -43,7 +43,7 @@ func NewController(kubeClient kubernetes.Interface, actionsClient scheme.Interfa
nil,
nil,
),
ActionsHandler: handlers.NewActionsHandler(actionsClient),
ActionsHandler: handlers.NewActionsHandler(actionsClient, handlers.ActionsHandlerConfig{RuntimeImage: config.ActionsRuntimeImage}),
EventSourcesHandler: handlers.NewEventSourcesHandler(kubeClient),
}
......
......@@ -25,7 +25,6 @@ const (
actionSidecarContainerName = "action"
actionSidecarHTTPPortName = "actions-http"
actionSidecarGRPCPortName = "actions-grpc"
actionSidecarImage = "yaron2/actionsedge:v2"
actionSidecarHTTPPort = 3500
actionSidecarGRPCPort = 50001
apiAddress = "http://actions-api.default.svc.cluster.local"
......@@ -37,10 +36,16 @@ const (
type ActionsHandler struct {
Client scheme.Interface
DeploymentsLock *sync.Mutex
Config ActionsHandlerConfig
}
func NewActionsHandler(client scheme.Interface) *ActionsHandler {
type ActionsHandlerConfig struct {
RuntimeImage string
}
func NewActionsHandler(client scheme.Interface, config ActionsHandlerConfig) *ActionsHandler {
return &ActionsHandler{
Config: config,
Client: client,
DeploymentsLock: &sync.Mutex{},
}
......@@ -51,7 +56,7 @@ func (r *ActionsHandler) Init() error {
return nil
}
func (r *ActionsHandler) GetEventingSidecar(applicationPort, applicationProtocol, actionName string) v1.Container {
func (r *ActionsHandler) GetEventingSidecar(applicationPort, applicationProtocol, actionName, actionSidecarImage string) v1.Container {
return v1.Container{
Name: actionSidecarContainerName,
Image: actionSidecarImage,
......@@ -149,7 +154,7 @@ func (r *ActionsHandler) EnableAction(deployment *appsv1.Deployment) error {
appPort := r.GetApplicationPort(deployment.Spec.Template.Spec.Containers)
appProtocol := r.GetAppProtocol(deployment)
actionName := r.GetActionName(deployment)
sidecar := r.GetEventingSidecar(appPort, appProtocol, actionName)
sidecar := r.GetEventingSidecar(appPort, appProtocol, actionName, r.Config.RuntimeImage)
deployment.Spec.Template.Spec.Containers = append(deployment.Spec.Template.Spec.Containers, sidecar)
err := r.CreateEventingService(actionName, deployment)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册