Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Add support for ignite configuration file #601

Merged
merged 6 commits into from
Jul 6, 2020

Conversation

darkowlzz
Copy link
Contributor

@darkowlzz darkowlzz commented May 31, 2020

This adds a new API type Configuration which is used to define the
default configurations of ignite. A Configuration object can be defined
in a config file as:

apiVersion: ignite.weave.works/v1alpha3
kind: Configuration
metadata:
  name: test-config
spec:
  runtime: containerd
  networkPlugin: cni
  vmDefaults:
    memory: "2GB"
    diskSize: "3GB"
    cpus: 2
    sandbox:
      oci: weaveworks/ignite:dev
    kernel:
      oci: weaveworks/ignite-kernel:4.19.47
    ssh: true

By default, ignite looks for the config file at /etc/ignite/config.yaml.
If this file is found, ignite uses it to configure the ignite defaults.
--ignite-config flag can be used to explicitly pass a configuration
file.

  • Changes the flag override behavior when using a VM config file. The flags are no longer ignored and override the VM configuration.
  • Debug log for the configuration used:
    Default config:
$ sudo bin/ignite run weaveworks/ignite-ubuntu --name my-vm --ssh --log-level=debug
DEBU[0000] Using ignite default configurations

With global config:

$ sudo bin/ignite run weaveworks/ignite-ubuntu --name my-vm --ssh --log-level=debug
DEBU[0000] Found default ignite configuration file /etc/ignite/config.yaml
DEBU[0000] Using ignite configuration file /etc/ignite/config.yaml
  • Adds e2e tests to verify the behavior.
  • Adds new document docs/ignite-configuration.md with examples of the ignite configuration.

Related to #315

@darkowlzz darkowlzz added the kind/feature Categorizes issue or PR as related to a new feature. label Jun 5, 2020
@darkowlzz darkowlzz force-pushed the componentconfig branch 3 times, most recently from d6d08d7 to b5ab200 Compare June 6, 2020 12:22
@luxas luxas mentioned this pull request Jun 11, 2020
@luxas
Copy link
Contributor

luxas commented Jun 11, 2020

I'd add this to a new v1alpha3 API version, in order to not break v1alpha2 compatibility. ref: #355

@darkowlzz darkowlzz added the do-not-merge/wip The PR is still work in progress label Jun 15, 2020
@darkowlzz darkowlzz force-pushed the componentconfig branch 2 times, most recently from 89cbaeb to c05c2cc Compare June 28, 2020 16:52
@darkowlzz
Copy link
Contributor Author

Rebased on v1alpha3 API.

@darkowlzz darkowlzz removed the do-not-merge/wip The PR is still work in progress label Jun 28, 2020
cmd/ignite/cmd/root.go Outdated Show resolved Hide resolved
Copy link
Contributor

@twelho twelho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 some structural change requests, but overall this is looking very good

cmd/ignite/cmd/root.go Show resolved Hide resolved
cmd/ignite/run/create.go Show resolved Hide resolved
cmd/ignite/run/create_test.go Show resolved Hide resolved
@@ -115,9 +153,27 @@ func addGlobalFlags(fs *pflag.FlagSet) {
logflag.LogLevelFlagVar(fs, &logLevel)
runtimeflag.RuntimeVar(fs, &providers.RuntimeName)
networkflag.NetworkPluginVar(fs, &providers.NetworkPluginName)
fs.StringVar(&configPath, "ignite-config", "", "Ignite configuration path")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More descriptive note on what this flag does

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a document about this in docs/ignite-configuration.md. I hope this will make it more clear.
Should this still be more descriptive?

pkg/apis/ignite/v1alpha3/types.go Outdated Show resolved Hide resolved
}
}

if configFilePath != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also handle the config for ignited?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe in a follow-up PR?

e2e/config_test.go Outdated Show resolved Hide resolved
This adds a new API type `Configuration` which is used to define the
default configurations of ignite. A Configuration object can be defined
in a config file as:

```yaml
apiVersion: ignite.weave.works/v1alpha3
kind: Configuration
metadata:
  name: test-config
spec:
  runtime: containerd
  networkPlugin: cni
  vmDefaults:
    memory: "2GB"
    diskSize: "3GB"
    cpus: 2
    sandbox:
      oci: weaveworks/ignite:dev
    kernel:
      oci: weaveworks/ignite-kernel:4.19.47
    ssh: true
```

By default, ignite looks for the config file at /etc/ignite/config.yaml.
If this file is found, ignite uses it to configure the ignite defaults.
`--ignite-config` flag can be used to explicitly pass a configuration
file.
- Flag overrides are applied on VM even if a VM config file is provided.
@darkowlzz darkowlzz force-pushed the componentconfig branch 2 times, most recently from c3fa727 to 96dc1f6 Compare July 6, 2020 11:16
err: true,
},
{
name: "with sandbox image",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already tested in e2e so it's fine to exclude it here (tricky to implement).

wantSSH: api.SSH{
Generate: true,
PublicKey: "some-pub-key",
},
},
{
name: "with no VM name and --require-name flag set",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

for _, rt := range tests {
t.Run(rt.name, func(t *testing.T) {
err := rt.createFlag.constructVMFromCLI(rt.args)
vm := rt.createFlag.VM
fs := flag.NewFlagSet("test", flag.ExitOnError)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not test flag validity since that would need the flag set to be populated (needs additional logic), but the flag handling will need to be refactored at some point anyway so this is fine.

if err != nil {
t.Fatalf("failed to create storage for ignite: %v", err)
}
defer os.RemoveAll(dir)
Copy link
Contributor

@twelho twelho Jul 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catch this error with util.DeferErr (or assert) (will be done in a separate PR)

}
defer os.RemoveAll(dir)

storage := cache.NewCache(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use Ignite's configured providers to have consistency between the tests and built binary, can be done in a separate PR.

make api-docs
Copy link
Contributor

@twelho twelho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 amazing work 💯

Copy link
Contributor

@stealthybox stealthybox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢 🚀

@stealthybox stealthybox merged commit 52a0fce into weaveworks:master Jul 6, 2020
@darkowlzz darkowlzz deleted the componentconfig branch July 6, 2020 16:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants