Skip to content

Commit

Permalink
feat: read only executors (#1758)
Browse files Browse the repository at this point in the history
  • Loading branch information
vsukhin authored Jul 7, 2022
1 parent 824cfae commit b6d796a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
TESTKUBE_NAMESPACE=testkube
TESTKUBE_TEMPLATE_JOB=YXBpVmVyc2lvbjogYmF0Y2gvdjEKa2luZDogSm9iCm1ldGFkYXRhOgogIG5hbWU6IHt7IC5OYW1lIH19CiAgbmFtZXNwYWNlOiB7eyAuTmFtZXNwYWNlIH19CnNwZWM6CiAgdGVtcGxhdGU6CiAgICBzcGVjOgogICAgICBpbml0Q29udGFpbmVyczoKICAgICAgLSBuYW1lOiB7eyAuTmFtZSB9fS1pbml0CiAgICAgICAgaW1hZ2U6IHt7IC5Jbml0SW1hZ2UgfX0KICAgICAgICBpbWFnZVB1bGxQb2xpY3k6IEFsd2F5cwogICAgICAgIGNvbW1hbmQ6IAogICAgICAgICAgLSAiL2Jpbi9ydW5uZXIiCiAgICAgICAgICAtICd7eyAuSnNuIH19JwogICAgICAgIHZvbHVtZU1vdW50czoKICAgICAgICAtIG5hbWU6IGRhdGEtdm9sdW1lCiAgICAgICAgICBtb3VudFBhdGg6IC9kYXRhIAogICAgICBjb250YWluZXJzOgogICAgICAtIG5hbWU6IHt7IC5OYW1lIH19CiAgICAgICAgaW1hZ2U6IHt7IC5JbWFnZSB9fQogICAgICAgIGltYWdlUHVsbFBvbGljeTogQWx3YXlzCiAgICAgICAgY29tbWFuZDogCiAgICAgICAgICAtICIvYmluL3J1bm5lciIKICAgICAgICAgIC0gJ3t7IC5Kc24gfX0nCiAgICAgICAgdm9sdW1lTW91bnRzOgogICAgICAgIC0gbmFtZTogZGF0YS12b2x1bWUKICAgICAgICAgIG1vdW50UGF0aDogL2RhdGEKICAgICAgdm9sdW1lczoKICAgICAgLSBuYW1lOiBkYXRhLXZvbHVtZQogICAgICAgIGVtcHR5RGlyOiB7fQogICAgICByZXN0YXJ0UG9saWN5OiBOZXZlcgogIGJhY2tvZmZMaW1pdDogMAogIHR0bFNlY29uZHNBZnRlckZpbmlzaGVkOiAxODAgIAo=
TESTKUBE_DEFAULT_EXECUTORS=
TESTKUBE_DEFAULT_EXECUTORS=WwogICAgewogICAgICAgICJuYW1lIjogImt1YmVwdWctZXhlY3V0b3IiLAogICAgICAgICJleGVjdXRvciI6IHsKICAgICAgICAgICAgImV4ZWN1dG9yX3R5cGUiOiAiam9iIiwKICAgICAgICAgICAgImltYWdlIjogImt1YmVzaG9wL3Rlc3RrdWJlLWt1YmVwdWctZXhlY3V0b3I6MC4wLjEiLAogICAgICAgICAgICAidHlwZXMiOlsia3ViZXB1Zy95YW1sIiwgImt1YmVwdWcvanNvbiJdLAogICAgICAgICAgICAiY29udGVudF90eXBlcyI6IFsic3RyaW5nIiwgImZpbGUtdXJpIiwgImdpdC1maWxlIiwgImdpdC1kaXIiXSwKICAgICAgICAgICAgImZlYXR1cmVzIjogW10KICAgICAgICB9CiAgICB9LAogICAgewogICAgICAgICJuYW1lIjogInNvYXB1aS1leGVjdXRvciIsCiAgICAgICAgImV4ZWN1dG9yIjogewogICAgICAgICAgICAiZXhlY3V0b3JfdHlwZSI6ICJqb2IiLAogICAgICAgICAgICAiaW1hZ2UiOiAia3ViZXNob3AvdGVzdGt1YmUtc29hcHVpLWV4ZWN1dG9yOjAuMS4wIiwKICAgICAgICAgICAgInR5cGVzIjpbInNvYXB1aS94bWwiXSwKICAgICAgICAgICAgImNvbnRlbnRfdHlwZXMiOiBbInN0cmluZyIsICJmaWxlLXVyaSIsICJnaXQtZmlsZSJdLAogICAgICAgICAgICAiZmVhdHVyZXMiOiBbImFydGlmYWN0cyJdCiAgICAgICAgfQogICAgfSwKICAgIHsKICAgICAgICAibmFtZSI6ICJrNi1leGVjdXRvciIsCiAgICAgICAgImV4ZWN1dG9yIjogewogICAgICAgICAgICAiZXhlY3V0b3JfdHlwZSI6ICJqb2IiLAogICAgICAgICAgICAiaW1hZ2UiOiAia3ViZXNob3AvdGVzdGt1YmUtazYtZXhlY3V0b3I6MC4wLjYiLAogICAgICAgICAgICAidHlwZXMiOlsiazYvc2NyaXB0Il0sCiAgICAgICAgICAgICJjb250ZW50X3R5cGVzIjogWyJzdHJpbmciLCAiZmlsZS11cmkiLCAiZ2l0LWZpbGUiXSwKICAgICAgICAgICAgImZlYXR1cmVzIjogW10KICAgICAgICB9CiAgICB9LAogICAgewogICAgICAgICJuYW1lIjogImN5cHJlc3MtZXhlY3V0b3IiLAogICAgICAgICJleGVjdXRvciI6IHsKICAgICAgICAgICAgImV4ZWN1dG9yX3R5cGUiOiAiam9iIiwKICAgICAgICAgICAgImltYWdlIjogImt1YmVzaG9wL3Rlc3RrdWJlLWN5cHJlc3MtZXhlY3V0b3I6MS4xLjEiLAogICAgICAgICAgICAidHlwZXMiOlsiY3lwcmVzcy9wcm9qZWN0Il0sCiAgICAgICAgICAgICJjb250ZW50X3R5cGVzIjogWyJnaXQtZGlyIl0sCiAgICAgICAgICAgICJmZWF0dXJlcyI6IFsiYXJ0aWZhY3RzIiwgImp1bml0LXJlcG9ydCJdCiAgICAgICAgfQogICAgfSwKICAgIHsKICAgICAgICAibmFtZSI6ICJjdXJsLWV4ZWN1dG9yIiwKICAgICAgICAiZXhlY3V0b3IiOiB7CiAgICAgICAgICAgICJleGVjdXRvcl90eXBlIjogImpvYiIsCiAgICAgICAgICAgICJpbWFnZSI6ICJrdWJlc2hvcC90ZXN0a3ViZS1jdXJsLWV4ZWN1dG9yOjEuMC4wIiwKICAgICAgICAgICAgInR5cGVzIjpbImN1cmwvdGVzdCJdLAogICAgICAgICAgICAiY29udGVudF90eXBlcyI6IFsic3RyaW5nIiwgImZpbGUtdXJpIiwgImdpdC1maWxlIl0sCiAgICAgICAgICAgICJmZWF0dXJlcyI6IFtdCiAgICAgICAgfQogICAgfSwKICAgIHsKICAgICAgICAibmFtZSI6ICJwb3N0bWFuLWV4ZWN1dG9yIiwKICAgICAgICAiZXhlY3V0b3IiOiB7CiAgICAgICAgICAgICJleGVjdXRvcl90eXBlIjogImpvYiIsCiAgICAgICAgICAgICJpbWFnZSI6ICJrdWJlc2hvcC90ZXN0a3ViZS1wb3N0bWFuLWV4ZWN1dG9yOjEuMC4wIiwKICAgICAgICAgICAgInR5cGVzIjpbInBvc3RtYW4vY29sbGVjdGlvbiJdLAogICAgICAgICAgICAiY29udGVudF90eXBlcyI6IFsic3RyaW5nIiwgImZpbGUtdXJpIiwgImdpdC1maWxlIl0sCiAgICAgICAgICAgICJmZWF0dXJlcyI6IFtdCiAgICAgICAgfQogICAgfSwKICAgIHsKICAgICAgICAibmFtZSI6ICJhcnRpbGxlcnktZXhlY3V0b3IiLAogICAgICAgICJleGVjdXRvciI6IHsKICAgICAgICAgICAgImV4ZWN1dG9yX3R5cGUiOiAiam9iIiwKICAgICAgICAgICAgImltYWdlIjogImt1YmVzaG9wL3Rlc3RrdWJlLWFydGlsbGVyeS1leGVjdXRvcjowLjAuNSIsCiAgICAgICAgICAgICJ0eXBlcyI6WyJhcnRpbGxlcnkvdGVzdCJdLAogICAgICAgICAgICAiY29udGVudF90eXBlcyI6IFsic3RyaW5nIiwgImZpbGUtdXJpIiwgImdpdC1maWxlIiwgImdpdC1kaXIiXSwKICAgICAgICAgICAgImZlYXR1cmVzIjogW10KICAgICAgICB9CiAgICB9LAogICAgewogICAgICAgICJuYW1lIjogImV4ZWN1dG9yLWluaXQiLAogICAgICAgICJleGVjdXRvciI6IHsKICAgICAgICAgICAgImV4ZWN1dG9yX3R5cGUiOiAiaW5pdCIsCiAgICAgICAgICAgICJpbWFnZSI6ICJrdWJlc2hvcC90ZXN0a3ViZS1leGVjdXRvci1pbml0OjAuNy44IiwKICAgICAgICAgICAgInR5cGVzIjpbXQogICAgICAgIH0KICAgIH0gICAgCl0K
ANALYTICS_TRACKING_ID=
ANALYTICS_API_KEY=
SLACK_BOT_CLIENT_ID=
SLACK_BOT_CLIENT_SECRET=
TESTKUBE_TEMPLATE_CRONJOB=YXBpVmVyc2lvbjogYmF0Y2gvdjEKa2luZDogQ3JvbkpvYgptZXRhZGF0YToKICBuYW1lOiB7eyAuTmFtZSB9fQogIG5hbWVzcGFjZToge3sgLk5hbWVzcGFjZSB9fQogIGxhYmVsczoKICAgIHRlc3RrdWJlOiB7eyAuUmVzb3VyY2UgfX0Kc3BlYzoKICBzY2hlZHVsZTogInt7IC5TY2hlZHVsZSB9fSIKICBjb25jdXJyZW5jeVBvbGljeTogRm9yYmlkCiAgam9iVGVtcGxhdGU6CiAgICBzcGVjOgogICAgICB0ZW1wbGF0ZToKICAgICAgICBzcGVjOgogICAgICAgICAgY29udGFpbmVyczoKICAgICAgICAgIC0gbmFtZTogY3VybGltYWdlCiAgICAgICAgICAgIGltYWdlOiBjdXJsaW1hZ2VzL2N1cmwKICAgICAgICAgICAgaW1hZ2VQdWxsUG9saWN5OiBBbHdheXMKICAgICAgICAgICAgY29tbWFuZDoKICAgICAgICAgICAgLSBzaAogICAgICAgICAgICAtIC1jCiAgICAgICAgICAgIGFyZ3M6CiAgICAgICAgICAgIC0gJ2N1cmwgLVggUE9TVCAtSCAiQ29udGVudC1UeXBlOiBhcHBsaWNhdGlvbi9qc29uIiAtZCAnJ3t7IC5EYXRhIH19JycgImh0dHA6Ly97eyAuU2VydmljZU5hbWUgfX06e3sgLlNlcnZpY2VQb3J0fX0vdjEve3sgLlJlc291cmNlIH19L3t7IC5JZCB9fS9leGVjdXRpb25zP2NhbGxiYWNrPXRydWUiJwogICAgICAgICAgcmVzdGFydFBvbGljeTogTmV2ZXIKICAgICAgYmFja29mZkxpbWl0OiAwCiAgICAgIHR0bFNlY29uZHNBZnRlckZpbmlzaGVkOiAxODAK
APISERVER_FULLNAME=localhost
TESTKUBE_READONLY_EXECUTORS=true
16 changes: 14 additions & 2 deletions internal/app/api/v1/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,15 @@ func NewTestkubeAPI(
Namespace: namespace,
}

initImage, err := s.loadDefaultExecutors(s.Namespace, os.Getenv("TESTKUBE_DEFAULT_EXECUTORS"))
readOnlyExecutors := false
if value, ok := os.LookupEnv("TESTKUBE_READONLY_EXECUTORS"); ok {
readOnlyExecutors, err = strconv.ParseBool(value)
if err != nil {
s.Log.Warnf("parse bool env %w", err)
}
}

initImage, err := s.loadDefaultExecutors(s.Namespace, os.Getenv("TESTKUBE_DEFAULT_EXECUTORS"), readOnlyExecutors)
if err != nil {
s.Log.Warnf("load default executors %w", err)
}
Expand Down Expand Up @@ -364,7 +372,7 @@ func getFilterFromRequest(c *fiber.Ctx) result.Filter {
}

// loadDefaultExecutors loads default executors
func (s TestkubeAPI) loadDefaultExecutors(namespace, data string) (initImage string, err error) {
func (s TestkubeAPI) loadDefaultExecutors(namespace, data string, readOnlyExecutors bool) (initImage string, err error) {
var executors []testkube.ExecutorDetails

if data == "" {
Expand All @@ -390,6 +398,10 @@ func (s TestkubeAPI) loadDefaultExecutors(namespace, data string) (initImage str
continue
}

if readOnlyExecutors {
continue
}

obj := &executorv1.Executor{
ObjectMeta: metav1.ObjectMeta{
Name: executor.Name,
Expand Down

0 comments on commit b6d796a

Please sign in to comment.