Skip to content

Commit

Permalink
Merge branch 'main' into mojtaba/595-adding-file-to-image
Browse files Browse the repository at this point in the history
  • Loading branch information
mojtaba-esk authored Dec 13, 2024
2 parents cef0ab0 + 83a1a24 commit 3f29216
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 @@ -30,6 +30,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 @@ -214,6 +215,15 @@ func (b *build) buildInitImage(ctx context.Context) error {
return factory.PushBuilderImage(ctx, imageName)
}

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 @@ -418,6 +418,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 @@ -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
}

// DeployPod creates a new pod in the namespace that k8s client is initiate with if it doesn't already exist.
Expand Down Expand Up @@ -596,6 +597,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 3f29216

Please sign in to comment.