Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Env var support #52

Merged
merged 2 commits into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@

public class CamelKSteps {

private static final int MAX_ATTEMPTS = 150;
private static final long DELAY_BETWEEN_ATTEMPTS = 2000;
private static final int MAX_ATTEMPTS = System.getenv("YAKS_CAMELK_MAX_ATTEMPTS") != null ? Integer.valueOf(System.getenv("YAKS_CAMELK_MAX_ATTEMPTS")) : 150;
private static final long DELAY_BETWEEN_ATTEMPTS = System.getenv("YAKS_CAMELK_DELAY_BETWEEN_ATTEMPTS") != null ? Long.valueOf(System.getenv("YAKS_CAMELK_DELAY_BETWEEN_ATTEMPTS")) : 2000;

private KubernetesClient client;
private ObjectMapper obj = new ObjectMapper();

/** Logger */
private static final Logger LOG = LoggerFactory.getLogger(CamelKSteps.class);
private static final Logger LOG = LoggerFactory.getLogger(CamelKSteps.class);

@Given("^new integration with name ([a-z0-9_]+\\.[a-z0-9_]+) with configuration:$")
public void createNewIntegration(String name, Map<String, String> configuration) throws IOException {
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/yaks/v1alpha1/test_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type TestSpec struct {

Source SourceSpec `json:"source,omitempty"`
Settings SettingsSpec `json:"config,omitempty"`
Env []string `json:"env,omitempty"`
}

// SourceSpec--
Expand Down
7 changes: 6 additions & 1 deletion pkg/apis/yaks/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pkg/cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func newCmdTest(rootCmdOptions *RootCmdOptions) *cobra.Command {

cmd.Flags().StringVarP(&options.dependencies, "dependencies", "d", "", "Adds runtime dependencies that get automatically loaded before the test is executed.")
cmd.Flags().StringVarP(&options.settings, "settings", "s", "", "Path to runtime settings file. File content is added to the test runtime and can hold runtime dependency information for instance.")
cmd.Flags().StringArrayVarP(&options.env, "env", "e", nil, "Set an environment variable in the integration container. E.g \"-e MY_VAR=my-value\"")

return &cmd
}
Expand All @@ -66,6 +67,7 @@ type testCmdOptions struct {
*RootCmdOptions
dependencies string
settings string
env []string
}

func (o *testCmdOptions) validateArgs(_ *cobra.Command, args []string) error {
Expand Down Expand Up @@ -133,6 +135,10 @@ func (o *testCmdOptions) createTest(c client.Client, sources []string) (*v1alpha
}
}

if o.env != nil {
test.Spec.Env = o.env
}

existed := false
err = c.Create(o.Context, &test)
if err != nil && k8serrors.IsAlreadyExists(err) {
Expand Down
16 changes: 16 additions & 0 deletions pkg/controller/test/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package test

import (
"context"
"strings"

"github.com/jboss-fuse/yaks/pkg/apis/yaks/v1alpha1"
"github.com/jboss-fuse/yaks/pkg/config"
Expand Down Expand Up @@ -147,6 +148,21 @@ func (action *startAction) newTestingPod(ctx context.Context, test *v1alpha1.Tes
},
}

for _, value := range test.Spec.Env {
pair := strings.SplitN(value, "=", 2)
if len(pair) == 2 {
k := strings.TrimSpace(pair[0])
v := strings.TrimSpace(pair[1])

if len(k) > 0 && len(v) > 0 {
pod.Spec.Containers[0].Env = append(pod.Spec.Containers[0].Env, v1.EnvVar{
Name: k,
Value: v,
})
}
}
}

if test.Spec.Settings.Name != "" {
pod.Spec.Containers[0].Env = append(pod.Spec.Containers[0].Env, v1.EnvVar{
Name: "YAKS_SETTINGS_FILE",
Expand Down