Set FsGroup for spring boot test (#6931)

This commit is contained in:
Philippe Martin
2023-06-26 11:55:09 +02:00
committed by GitHub
parent 4b9c89e086
commit 535ee0a105
2 changed files with 25 additions and 0 deletions

View File

@@ -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()

View File

@@ -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"
)
@@ -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
}
}