You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2023/02/03 15:16:25 UTC

[camel-k] 01/04: feat(cli): enable service account for Integration

This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit ca4dcbc2ff245b387d8485a9264bb29fd80ccb33
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Fri Feb 3 11:12:50 2023 +0100

    feat(cli): enable service account for Integration
---
 pkg/cmd/run.go      |  6 ++++++
 pkg/cmd/run_test.go | 17 +++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 72624c28c..2199275a0 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -122,6 +122,7 @@ func newCmdRun(rootCmdOptions *RootCmdOptions) (*cobra.Command, *runCmdOptions)
 	cmd.Flags().StringArray("label", nil, "Add a label to the integration. E.g. \"--label my.company=hello\"")
 	cmd.Flags().StringArray("source", nil, "Add source file to your integration, this is added to the list of files listed as arguments of the command")
 	cmd.Flags().String("pod-template", "", "The path of the YAML file containing a PodSpec template to be used for the Integration pods")
+	cmd.Flags().String("service-account", "", "The SA to use to run this Integration")
 	cmd.Flags().Bool("force", false, "Force creation of integration regardless of potential misconfiguration.")
 
 	cmd.Flags().Bool("save", false, "Save the run parameters into the default kamel configuration file (kamel-config.yaml)")
@@ -147,6 +148,7 @@ type runCmdOptions struct {
 	OperatorID      string   `mapstructure:"operator-id" yaml:",omitempty"`
 	OutputFormat    string   `mapstructure:"output" yaml:",omitempty"`
 	PodTemplate     string   `mapstructure:"pod-template" yaml:",omitempty"`
+	ServiceAccount  string   `mapstructure:"service-account" yaml:",omitempty"`
 	Connects        []string `mapstructure:"connects" yaml:",omitempty"`
 	Resources       []string `mapstructure:"resources" yaml:",omitempty"`
 	OpenAPIs        []string `mapstructure:"open-apis" yaml:",omitempty"`
@@ -551,6 +553,10 @@ func (o *runCmdOptions) createOrUpdateIntegration(cmd *cobra.Command, c client.C
 		}
 	}
 
+	if o.ServiceAccount != "" {
+		integration.Spec.ServiceAccountName = o.ServiceAccount
+	}
+
 	if o.OutputFormat != "" {
 		return nil, showIntegrationOutput(cmd, integration, o.OutputFormat, c.GetScheme())
 	}
diff --git a/pkg/cmd/run_test.go b/pkg/cmd/run_test.go
index 070ae1038..80598d77b 100644
--- a/pkg/cmd/run_test.go
+++ b/pkg/cmd/run_test.go
@@ -693,3 +693,20 @@ func TestResolveJsonPodTemplateWithSupplementalGroups(t *testing.T) {
 	assert.Equal(t, 1, len(integrationSpec.PodTemplate.Spec.SecurityContext.SupplementalGroups))
 	assert.Contains(t, integrationSpec.PodTemplate.Spec.SecurityContext.SupplementalGroups, int64(666))
 }
+
+func TestIntegrationServiceAccountName(t *testing.T) {
+	var tmpFile *os.File
+	var err error
+	if tmpFile, err = ioutil.TempFile("", "camel-k-"); err != nil {
+		t.Error(err)
+	}
+
+	assert.Nil(t, tmpFile.Close())
+	assert.Nil(t, ioutil.WriteFile(tmpFile.Name(), []byte(TestSrcContent), 0o400))
+
+	_, runCmd, _ := initializeRunCmdOptionsWithOutput(t)
+	output, err := test.ExecuteCommand(runCmd, cmdRun, tmpFile.Name(), "-o", "yaml", "--service-account", "my-service-account")
+
+	assert.Nil(t, err)
+	assert.Contains(t, output, "serviceAccountName: my-service-account")
+}