Skip to content

Commit

Permalink
Fix volumizing platform into functions pod (#1894)
Browse files Browse the repository at this point in the history
  • Loading branch information
liranbg committed Nov 3, 2020
1 parent 5e4a4b1 commit bd24c3e
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 25 deletions.
4 changes: 4 additions & 0 deletions cmd/controller/app/controller.go
Expand Up @@ -39,6 +39,7 @@ func Run(kubeconfigPath string,
namespace string,
imagePullSecrets string,
platformConfigurationPath string,
platformConfigurationName string,
functionOperatorNumWorkersStr string,
functionOperatorResyncIntervalStr string,
cronJobStaleResourcesCleanupIntervalStr string,
Expand All @@ -50,6 +51,7 @@ func Run(kubeconfigPath string,
namespace,
imagePullSecrets,
platformConfigurationPath,
platformConfigurationName,
functionOperatorNumWorkersStr,
functionOperatorResyncIntervalStr,
cronJobStaleResourcesCleanupIntervalStr,
Expand All @@ -73,6 +75,7 @@ func createController(kubeconfigPath string,
namespace string,
imagePullSecrets string,
platformConfigurationPath string,
platformConfigurationName string,
functionOperatorNumWorkersStr string,
functionOperatorResyncIntervalStr string,
cronJobStaleResourcesCleanupIntervalStr string,
Expand Down Expand Up @@ -165,6 +168,7 @@ func createController(kubeconfigPath string,
functionOperatorResyncInterval,
cronJobStaleResourcesCleanupInterval,
platformConfiguration,
platformConfigurationName,
functionOperatorNumWorkers,
functionEventOperatorNumWorkers,
projectOperatorNumWorkers,
Expand Down
2 changes: 2 additions & 0 deletions cmd/controller/main.go
Expand Up @@ -48,6 +48,7 @@ func main() {
namespace := flag.String("namespace", "", "Namespace to listen on, or * for all")
imagePullSecrets := flag.String("image-pull-secrets", os.Getenv("NUCLIO_CONTROLLER_IMAGE_PULL_SECRETS"), "Optional secret name to use for pull")
platformConfigurationPath := flag.String("platform-config", "/etc/nuclio/config/platform/platform.yaml", "Path of platform configuration file")
platformConfigurationName := flag.String("platform-config-name", common.GetEnvOrDefaultString("NUCLIO_CONTROLLER_PLATFORM_CONFIGURATION_NAME", "nuclio-platform-config"), "Platform configuration resource name")
functionOperatorNumWorkersStr := flag.String("function-operator-num-workers", common.GetEnvOrDefaultString("NUCLIO_CONTROLLER_FUNCTION_OPERATOR_NUM_WORKERS", "4"), "Set number of workers for the function operator (optional)")
functionOperatorResyncIntervalStr := flag.String("function-operator-resync-interval", common.GetEnvOrDefaultString("NUCLIO_CONTROLLER_FUNCTION_OPERATOR_RESYNC_INTERVAL", "10m"), "Set resync interval for the function operator (optional)")
cronJobStaleResourcesCleanupIntervalStr := flag.String("cron-job-stale-resources-cleanup-interval", common.GetEnvOrDefaultString("NUCLIO_CONTROLLER_CRON_JOB_STALE_RESOURCES_CLEANUP_INTERVAL", "1m"), "Set interval for the cleanup of stale cron job resources (optional)")
Expand All @@ -73,6 +74,7 @@ func main() {
resolvedNamespace,
*imagePullSecrets,
*platformConfigurationPath,
*platformConfigurationName,
*functionOperatorNumWorkersStr,
*functionOperatorResyncIntervalStr,
*cronJobStaleResourcesCleanupIntervalStr,
Expand Down
4 changes: 4 additions & 0 deletions hack/k8s/helm/nuclio/templates/deployment/controller.yaml
Expand Up @@ -50,6 +50,10 @@ spec:
value: {{ .Values.controller.cronTriggerCronJobImage.repository }}:{{ .Values.controller.cronTriggerCronJobImage.tag }}
- name: NUCLIO_CONTROLLER_CRON_TRIGGER_CRON_JOB_IMAGE_PULL_POLICY
value: {{ .Values.controller.cronTriggerCronJobImage.pullPolicy }}
{{- if .Values.platform }}
- name: NUCLIO_CONTROLLER_PLATFORM_CONFIGURATION_NAME
value: {{ template "nuclio.platformConfigName" . }}
{{- end}}
{{- if .Values.controller.namespace }}
- name: NUCLIO_CONTROLLER_NAMESPACE
value: {{ .Values.controller.namespace | quote }}
Expand Down
53 changes: 30 additions & 23 deletions pkg/platform/kube/controller/controller.go
Expand Up @@ -31,20 +31,21 @@ import (
)

type Controller struct {
logger logger.Logger
namespace string
kubeClientSet kubernetes.Interface
nuclioClientSet nuclioioclient.Interface
functionresClient functionres.Client
apigatewayresClient apigatewayres.Client
imagePullSecrets string
functionOperator *functionOperator
projectOperator *projectOperator
functionEventOperator *functionEventOperator
apiGatewayOperator *apiGatewayOperator
cronJobMonitoring *CronJobMonitoring
platformConfiguration *platformconfig.Config
resyncInterval time.Duration
logger logger.Logger
namespace string
kubeClientSet kubernetes.Interface
nuclioClientSet nuclioioclient.Interface
functionresClient functionres.Client
apigatewayresClient apigatewayres.Client
imagePullSecrets string
functionOperator *functionOperator
projectOperator *projectOperator
functionEventOperator *functionEventOperator
apiGatewayOperator *apiGatewayOperator
cronJobMonitoring *CronJobMonitoring
platformConfiguration *platformconfig.Config
platformConfigurationName string
resyncInterval time.Duration
}

func NewController(parentLogger logger.Logger,
Expand All @@ -57,6 +58,7 @@ func NewController(parentLogger logger.Logger,
resyncInterval time.Duration,
cronJobStaleResourcesCleanupInterval time.Duration,
platformConfiguration *platformconfig.Config,
platformConfigurationName string,
functionOperatorNumWorkers int,
functionEventOperatorNumWorkers int,
projectOperatorNumWorkers int,
Expand All @@ -69,15 +71,16 @@ func NewController(parentLogger logger.Logger,
}

newController := &Controller{
logger: parentLogger,
namespace: namespace,
imagePullSecrets: imagePullSecrets,
kubeClientSet: kubeClientSet,
nuclioClientSet: nuclioClientSet,
functionresClient: functionresClient,
apigatewayresClient: apigatewayresClient,
platformConfiguration: platformConfiguration,
resyncInterval: resyncInterval,
logger: parentLogger,
namespace: namespace,
imagePullSecrets: imagePullSecrets,
kubeClientSet: kubeClientSet,
nuclioClientSet: nuclioClientSet,
functionresClient: functionresClient,
apigatewayresClient: apigatewayresClient,
platformConfiguration: platformConfiguration,
platformConfigurationName: platformConfigurationName,
resyncInterval: resyncInterval,
}

newController.logger.DebugWith("Read configuration",
Expand Down Expand Up @@ -174,6 +177,10 @@ func (c *Controller) GetPlatformConfiguration() *platformconfig.Config {
return c.platformConfiguration
}

func (c *Controller) GetPlatformConfigurationName() string {
return c.platformConfigurationName
}

func (c *Controller) GetResyncInterval() time.Duration {
return c.resyncInterval
}
2 changes: 1 addition & 1 deletion pkg/platform/kube/functionres/lazy.go
Expand Up @@ -1873,7 +1873,7 @@ func (lc *lazyClient) getFunctionVolumeAndMounts(function *nuclioio.NuclioFuncti
platformConfigVolume := functionconfig.Volume{}
platformConfigVolume.Volume.Name = platformConfigVolumeName
platformConfigMapVolumeSource := v1.ConfigMapVolumeSource{}
platformConfigMapVolumeSource.Name = "platform-config"
platformConfigMapVolumeSource.Name = lc.platformConfigurationProvider.GetPlatformConfigurationName()
platformConfigMapVolumeSource.Optional = &trueVal
platformConfigVolume.Volume.ConfigMap = &platformConfigMapVolumeSource
platformConfigVolume.VolumeMount.Name = platformConfigVolumeName
Expand Down
4 changes: 4 additions & 0 deletions pkg/platform/kube/functionres/lazy_test.go
Expand Up @@ -37,6 +37,10 @@ type mockedPlatformConfigurationProvider struct {
platformConfiguration *platformconfig.Config
}

func (c *mockedPlatformConfigurationProvider) GetPlatformConfigurationName() string {
return "mocked-platform-configuration"
}

func (c *mockedPlatformConfigurationProvider) GetPlatformConfiguration() *platformconfig.Config {
return c.platformConfiguration
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/platform/kube/functionres/types.go
Expand Up @@ -17,6 +17,9 @@ type PlatformConfigurationProvider interface {

// GetPlatformConfiguration returns a platform configuration
GetPlatformConfiguration() *platformconfig.Config

// GetPlatformConfigurationName returns platform configuration resource name
GetPlatformConfigurationName() string
}

type Client interface {
Expand Down
1 change: 1 addition & 0 deletions pkg/platform/kube/test/suite.go
Expand Up @@ -278,6 +278,7 @@ func (suite *KubeTestSuite) createController() *controller.Controller {
time.Second*5,
time.Second*30,
suite.PlatformConfiguration,
"nuclio-platform-config",
4,
4,
4,
Expand Down
2 changes: 1 addition & 1 deletion test/_functions/common/file-streamer/golang/filestream.go
Expand Up @@ -25,7 +25,7 @@ func FileStreamer(context *nuclio.Context, event nuclio.Event) (interface{}, err

headers := map[string]interface{}{
"X-nuclio-filestream-path": event.GetPath(),
"X-request-body": string(event.GetBody()),
"X-request-body": string(event.GetBody()),
}

if event.GetFieldString("delete_after_send") == "true" {
Expand Down

0 comments on commit bd24c3e

Please sign in to comment.