Skip to content

Commit

Permalink
fix default securityContext passing to restore init-container/job + f…
Browse files Browse the repository at this point in the history
…ix container name (#823)
  • Loading branch information
Md. Emruz Hossain authored and tamalsaha committed Jul 3, 2019
1 parent 4aa9467 commit 08b0f50
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
9 changes: 7 additions & 2 deletions pkg/backup/backupsession.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,10 @@ func (c *BackupSessionController) electBackupLeader(backupSession *api_v1beta1.B
err := c.backup(backupSession, backupConfiguration)
if err != nil {
// send failure metrics and update BackupSession status
err = c.handleBackupFailure(backupSession, err)
err2 := c.handleBackupFailure(backupSession, err)
if err2 != nil {
err = errors.NewAggregate([]error{err, err2})
}
// step down from leadership so that other replicas can start backup
cancel()
// log failure. don't fail the container as it may interrupt user's service
Expand Down Expand Up @@ -423,7 +426,9 @@ func (c *BackupSessionController) HandleBackupSetupFailure(setupErr error) {
backupConfiguration, err := c.StashClient.StashV1beta1().BackupConfigurations(c.Namespace).Get(c.BackupConfigurationName, metav1.GetOptions{})
if err != nil {
e2 := errors.NewAggregate([]error{setupErr, err})
log.Fatalln("failed to setup backup process. Reason: ", e2.Error())
if e2 != nil {
log.Fatalln("failed to setup backup process. Reason: ", e2.Error())
}
}
c.Metrics.Labels = append(c.Metrics.Labels, fmt.Sprintf("BackupConfiguration=%s", backupConfiguration.Name))
if backupConfiguration.Spec.Target != nil {
Expand Down
3 changes: 2 additions & 1 deletion pkg/resolve/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package resolve
import (
"encoding/json"
"fmt"
"strings"

"gomodules.xyz/envsubst"
core "k8s.io/api/core/v1"
Expand Down Expand Up @@ -63,7 +64,7 @@ func (o TaskResolver) GetPodSpec() (core.PodSpec, error) {

// container from function spec
container := core.Container{
Name: fmt.Sprintf("%s-%d", function.Name, i), // TODO
Name: fmt.Sprintf("%s-%d", strings.ReplaceAll(function.Name, ".", "-"), i), // TODO
Image: function.Spec.Image,
Command: function.Spec.Command,
Args: function.Spec.Args,
Expand Down
2 changes: 2 additions & 0 deletions pkg/util/init_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ func NewRestoreInitContainer(rs *v1beta1_api.RestoreSession, repository *v1alpha
}
if rs.Spec.RuntimeSettings.Container != nil {
initContainer.SecurityContext = UpsertSecurityContext(securityContext, rs.Spec.RuntimeSettings.Container.SecurityContext)
} else {
initContainer.SecurityContext = securityContext
}

return initContainer
Expand Down
2 changes: 2 additions & 0 deletions pkg/util/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ func NewPVCRestorerJob(rs *api_v1beta1.RestoreSession, repository *api_v1alpha1.
}
if rs.Spec.RuntimeSettings.Container != nil {
container.SecurityContext = UpsertSecurityContext(securityContext, rs.Spec.RuntimeSettings.Container.SecurityContext)
} else {
container.SecurityContext = securityContext
}

jobTemplate := &core.PodTemplateSpec{
Expand Down

0 comments on commit 08b0f50

Please sign in to comment.