Skip to content

Commit 8ab8325

Browse files
authored
Support flatcar in aws (#745)
* add flatcar cloud-init support Signed-off-by: Moath Qasim <[email protected]> Signed-off-by: Moath Qasim <[email protected]> * add flatcar as an os support for aws cloud provider Signed-off-by: Moath Qasim <[email protected]> Signed-off-by: Moath Qasim <[email protected]> * add flatcar unit tests Signed-off-by: Moath Qasim <[email protected]> Signed-off-by: Moath Qasim <[email protected]> * exclude flatcar os from all e2e tests but aws Signed-off-by: Moath Qasim <[email protected]> Signed-off-by: Moath Qasim <[email protected]>
1 parent d18ce77 commit 8ab8325

22 files changed

+5378
-20
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ IMAGE_TAG = \
3333
$(shell echo $$(git rev-parse HEAD && if [[ -n $$(git status --porcelain) ]]; then echo '-dirty'; fi)|tr -d ' ')
3434
IMAGE_NAME = $(REGISTRY)/$(REGISTRY_NAMESPACE)/machine-controller:$(IMAGE_TAG)
3535

36-
OS = centos coreos ubuntu sles rhel
36+
OS = centos coreos ubuntu sles rhel flatcar
3737
USERDATA_BIN = $(patsubst %, machine-controller-userdata-%, $(OS))
3838

3939
.PHONY: all

cmd/userdata/flatcar/main.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
Copyright 2019 The Machine Controller Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
//
18+
// UserData plugin for flatcar.
19+
//
20+
21+
package main
22+
23+
import (
24+
"flag"
25+
26+
"k8s.io/klog"
27+
28+
"github.com/kubermatic/machine-controller/pkg/userdata/convert"
29+
"github.com/kubermatic/machine-controller/pkg/userdata/flatcar"
30+
userdataplugin "github.com/kubermatic/machine-controller/pkg/userdata/plugin"
31+
)
32+
33+
func main() {
34+
// Parse flags.
35+
var debug bool
36+
37+
flag.BoolVar(&debug, "debug", false, "Switch for enabling the plugin debugging")
38+
flag.Parse()
39+
40+
// Instantiate provider and start plugin.
41+
var provider = &flatcar.Provider{}
42+
var p = userdataplugin.New(convert.NewIgnition(provider), debug)
43+
44+
if err := p.Run(); err != nil {
45+
klog.Fatalf("error running flatcar plugin: %v", err)
46+
}
47+
}

pkg/cloudprovider/provider/aws/provider.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ var (
119119
// The AWS marketplace ID from RedHat
120120
owner: "309956199498",
121121
},
122+
providerconfigtypes.OperatingSystemFlatcar: {
123+
// Be as precise as possible - otherwise we might get a nightly dev build
124+
description: "Flatcar Container Linux stable 2345.3.1 (HVM)",
125+
// The AWS marketplace ID from AWS
126+
owner: "075585003325",
127+
},
122128
}
123129

124130
// cacheLock protects concurrent cache misses against a single key. This usually happens when multiple machines get created simultaneously
@@ -237,6 +243,8 @@ func getDefaultRootDevicePath(os providerconfigtypes.OperatingSystem) (string, e
237243
return rootDevicePathCoreOSSLES, nil
238244
case providerconfigtypes.OperatingSystemRHEL:
239245
return rootDevicePathUbuntuCentOSRHEL, nil
246+
case providerconfigtypes.OperatingSystemFlatcar:
247+
return rootDevicePathCoreOSSLES, nil
240248
}
241249

242250
return "", fmt.Errorf("no default root path found for %s operating system", os)
@@ -489,8 +497,9 @@ func (p *provider) Create(machine *v1alpha1.Machine, data *cloudprovidertypes.Pr
489497
}
490498
}
491499

492-
if pc.OperatingSystem != providerconfigtypes.OperatingSystemCoreos {
493-
// Gzip the userdata in case we don't use CoreOS.
500+
if pc.OperatingSystem != providerconfigtypes.OperatingSystemCoreos &&
501+
pc.OperatingSystem != providerconfigtypes.OperatingSystemFlatcar {
502+
// Gzip the userdata in case we don't use CoreOS and Flatcar
494503
userdata, err = convert.GzipString(userdata)
495504
if err != nil {
496505
return nil, fmt.Errorf("failed to gzip the userdata")

pkg/providerconfig/types/types.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ import (
3333
type OperatingSystem string
3434

3535
const (
36-
OperatingSystemCoreos OperatingSystem = "coreos"
37-
OperatingSystemUbuntu OperatingSystem = "ubuntu"
38-
OperatingSystemCentOS OperatingSystem = "centos"
39-
OperatingSystemSLES OperatingSystem = "sles"
40-
OperatingSystemRHEL OperatingSystem = "rhel"
36+
OperatingSystemCoreos OperatingSystem = "coreos"
37+
OperatingSystemUbuntu OperatingSystem = "ubuntu"
38+
OperatingSystemCentOS OperatingSystem = "centos"
39+
OperatingSystemSLES OperatingSystem = "sles"
40+
OperatingSystemRHEL OperatingSystem = "rhel"
41+
OperatingSystemFlatcar OperatingSystem = "flatcar"
4142
)
4243

4344
type CloudProvider string
@@ -67,6 +68,7 @@ var (
6768
OperatingSystemCentOS,
6869
OperatingSystemSLES,
6970
OperatingSystemRHEL,
71+
OperatingSystemFlatcar,
7072
}
7173

7274
// AllCloudProviders is a slice containing all supported cloud providers.

pkg/userdata/flatcar/flatcar.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
Copyright 2019 The Machine Controller Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package flatcar
18+
19+
import (
20+
"encoding/json"
21+
22+
"k8s.io/apimachinery/pkg/runtime"
23+
)
24+
25+
// Config contains specific configuration for Flatcar.
26+
type Config struct {
27+
DisableAutoUpdate bool `json:"disableAutoUpdate"`
28+
DisableLocksmithD bool `json:"disableLocksmithD"`
29+
DisableUpdateEngine bool `json:"disableUpdateEngine"`
30+
}
31+
32+
// LoadConfig retrieves the Flatcar configuration from raw data.
33+
func LoadConfig(r runtime.RawExtension) (*Config, error) {
34+
cfg := Config{}
35+
if len(r.Raw) == 0 {
36+
return &cfg, nil
37+
}
38+
if err := json.Unmarshal(r.Raw, &cfg); err != nil {
39+
return nil, err
40+
}
41+
return &cfg, nil
42+
}
43+
44+
// Spec return the configuration as raw data.
45+
func (cfg *Config) Spec() (*runtime.RawExtension, error) {
46+
ext := &runtime.RawExtension{}
47+
b, err := json.Marshal(cfg)
48+
if err != nil {
49+
return nil, err
50+
}
51+
52+
ext.Raw = b
53+
return ext, nil
54+
}

0 commit comments

Comments
 (0)