Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add node selector to intance #594

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading