Skip to content

Commit

Permalink
Set FsGroup for spring boot test (#6931)
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy authored Jun 26, 2023
1 parent 4b9c89e commit 535ee0a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ var _ = Describe("User guides: Quickstart test", func() {
Expect(diff).To(BeEmpty(), file)
})
By("running odo dev", func() {
helper.UpdateDevfileContent("devfile.yaml", []helper.DevfileUpdater{
helper.SetFsGroup("tools", 2000),
})
devSession, err := helper.StartDevMode(helper.DevSessionOpts{TimeoutInSeconds: 420})
Expect(err).To(BeNil())
devSession.Stop()
Expand Down
22 changes: 22 additions & 0 deletions tests/helper/helper_devfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"fmt"

"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/api/v2/pkg/attributes"
"github.com/devfile/library/v2/pkg/devfile/parser"
parsercommon "github.com/devfile/library/v2/pkg/devfile/parser/data/v2/common"
. "github.com/onsi/gomega"
apiext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/utils/pointer"
)

Expand Down Expand Up @@ -83,3 +85,23 @@ func UpdateDevfileContent(path string, handlers []DevfileUpdater) {
err = d.WriteYamlDevfile()
Expect(err).NotTo(HaveOccurred())
}

// SetFsGroup is a DevfileUpdater which sets an attribute to a container
// to set a specific fsGroup for the container's pod
func SetFsGroup(containerName string, fsGroup int) DevfileUpdater {
return func(d *parser.DevfileObj) error {
containers, err := d.Data.GetComponents(parsercommon.DevfileOptions{
FilterByName: containerName,
})
Expect(err).NotTo(HaveOccurred())
Expect(len(containers)).To(Equal(1))
containers[0].Attributes = attributes.Attributes{
"pod-overrides": apiext.JSON{
Raw: []byte(fmt.Sprintf(`{"spec": {"securityContext": {"fsGroup": %d}}}`, fsGroup)),
},
}
err = d.Data.UpdateComponent(containers[0])
Expect(err).NotTo(HaveOccurred())
return nil
}
}

0 comments on commit 535ee0a

Please sign in to comment.