diff --git a/pkg/instance/build.go b/pkg/instance/build.go index 8755c43..b0f54f6 100644 --- a/pkg/instance/build.go +++ b/pkg/instance/build.go @@ -25,6 +25,7 @@ type build struct { env map[string]string imageCache *sync.Map buildDir string + nodeSelector map[string]string } func (i *Instance) Build() *build { @@ -159,6 +160,15 @@ func (b *build) SetUser(user string) error { return nil } +func (b *build) SetNodeSelector(nodeSelector map[string]string) error { + if !b.instance.IsInState(StatePreparing, StateCommitted) { + return ErrSettingNodeSelectorNotAllowed.WithParams(b.instance.state.String()) + } + + b.nodeSelector = nodeSelector + return nil +} + // Commit commits the instance // This function can only be called in the state 'Preparing' func (b *build) Commit(ctx context.Context) error { diff --git a/pkg/instance/errors.go b/pkg/instance/errors.go index 6a87395..7dd6d6a 100644 --- a/pkg/instance/errors.go +++ b/pkg/instance/errors.go @@ -114,6 +114,7 @@ var ( ErrSrcDoesNotExistOrIsNotDirectory = errors.New("SrcDoesNotExistOrIsNotDirectory", "src '%s' does not exist or is not a directory") ErrCopyingFolderToInstance = errors.New("CopyingFolderToInstance", "error copying folder '%s' to instance '%s") ErrSettingUserNotAllowed = errors.New("SettingUserNotAllowed", "setting user is only allowed in state 'Preparing'. Current state is '%s") + ErrSettingNodeSelectorNotAllowed = errors.New("SettingNodeSelectorNotAllowed", "setting node selector is only allowed in state 'Preparing'. Current state is '%s") ErrSettingUser = errors.New("SettingUser", "error setting user '%s' for instance '%s") ErrCommittingNotAllowed = errors.New("CommittingNotAllowed", "committing is only allowed in state 'Preparing'. Current state is '%s") ErrGettingImageRegistry = errors.New("GettingImageRegistry", "error getting image registry") diff --git a/pkg/instance/execution.go b/pkg/instance/execution.go index 3e8cc01..220ccf5 100644 --- a/pkg/instance/execution.go +++ b/pkg/instance/execution.go @@ -421,6 +421,7 @@ func (e *execution) prepareReplicaSetConfig() k8s.ReplicaSetConfig { ServiceAccountName: e.instance.name, ContainerConfig: containerConfig, SidecarConfigs: sidecarConfigs, + NodeSelector: e.instance.build.nodeSelector, } return k8s.ReplicaSetConfig{ diff --git a/pkg/k8s/pod.go b/pkg/k8s/pod.go index eca4f62..767ac13 100644 --- a/pkg/k8s/pod.go +++ b/pkg/k8s/pod.go @@ -63,6 +63,7 @@ type PodConfig struct { ContainerConfig ContainerConfig // ContainerConfig for the Pod SidecarConfigs []ContainerConfig // SideCarConfigs for the Pod Annotations map[string]string // Annotations to apply to the Pod + NodeSelector map[string]string // NodeSelector to apply to the Pod } type Volume struct { @@ -621,6 +622,7 @@ func (c *Client) preparePodSpec(spec PodConfig, init bool) *corev1.PodSpecApplyC InitContainers: c.prepareInitContainers(spec.ContainerConfig, init), Containers: []corev1.ContainerApplyConfiguration{prepareContainer(spec.ContainerConfig)}, Volumes: preparePodVolumes(spec.ContainerConfig), + NodeSelector: spec.NodeSelector, } // Prepare sidecar containers and append to the pod spec diff --git a/pkg/knuu/knuu.go b/pkg/knuu/knuu.go index 0523809..a7fde53 100644 --- a/pkg/knuu/knuu.go +++ b/pkg/knuu/knuu.go @@ -116,6 +116,8 @@ func (k *Knuu) HandleStopSignal(ctx context.Context) { k.Logger.Errorf("Error cleaning up resources with timeout handler: %v", err) } k.K8sClient.Terminate() + // Allow other signal handlers to run + signal.Reset(syscall.SIGINT, syscall.SIGTERM, os.Interrupt) os.Exit(ExitCodeSIGINT) }() }