Skip to content

Commit

Permalink
feat: add node selector to intance (#594)
Browse files Browse the repository at this point in the history
Signed-off-by: Smuu <18609909+Smuu@users.noreply.github.com>
  • Loading branch information
smuu authored Dec 13, 2024
1 parent 21d8b67 commit 83a1a24
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/instance/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/instance/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions pkg/instance/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ func (e *execution) prepareReplicaSetConfig() k8s.ReplicaSetConfig {
ServiceAccountName: e.instance.name,
ContainerConfig: containerConfig,
SidecarConfigs: sidecarConfigs,
NodeSelector: e.instance.build.nodeSelector,
}

return k8s.ReplicaSetConfig{
Expand Down
2 changes: 2 additions & 0 deletions pkg/k8s/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,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 {
Expand Down Expand Up @@ -623,6 +624,7 @@ func (c *Client) preparePodSpec(spec PodConfig, init bool) v1.PodSpec {
InitContainers: c.prepareInitContainers(spec.ContainerConfig, init),
Containers: []v1.Container{prepareContainer(spec.ContainerConfig)},
Volumes: preparePodVolumes(spec.ContainerConfig),
NodeSelector: spec.NodeSelector,
}

// Prepare sidecar containers and append to the pod spec
Expand Down
2 changes: 2 additions & 0 deletions pkg/knuu/knuu.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,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)
}()
}
Expand Down

0 comments on commit 83a1a24

Please sign in to comment.