-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): support
system extensions
config file
Signed-off-by: budimanjojo <budimanjojo@gmail.com>
- Loading branch information
1 parent
45865fa
commit 4b1e836
Showing
5 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package talos | ||
|
||
import ( | ||
"github.com/budimanjojo/talhelper/pkg/config" | ||
"github.com/siderolabs/talos/pkg/machinery/config/types/runtime/extensions" | ||
) | ||
|
||
func GenerateExtensionServicesConfigBytes(esCfgs []*config.ExtensionService) ([]byte, error) { | ||
var result [][]byte | ||
|
||
exts, err := GenerateNodeExtensionServiceConfig(esCfgs) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, ext := range exts { | ||
extByte, err := marshalYaml(ext) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
result = append(result, extByte) | ||
} | ||
|
||
return CombineYamlBytes(result), nil | ||
} | ||
|
||
func GenerateNodeExtensionServiceConfig(esCfgs []*config.ExtensionService) ([]*extensions.ServiceConfigV1Alpha1, error) { | ||
var result []*extensions.ServiceConfigV1Alpha1 | ||
|
||
for _, v := range esCfgs { | ||
esc := extensions.NewServicesConfigV1Alpha1() | ||
esc.ServiceName = v.Name | ||
esc.ServiceConfigFiles = v.ConfigFiles | ||
esc.ServiceEnvironment = v.Environment | ||
|
||
if _, err := esc.Validate(nil); err != nil { | ||
return nil, err | ||
} | ||
|
||
result = append(result, esc) | ||
} | ||
|
||
return result, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package talos | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/budimanjojo/talhelper/pkg/config" | ||
"github.com/siderolabs/talos/pkg/machinery/config/types/runtime/extensions" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
func TestGenerateNodeExtensionServiceConfig(t *testing.T) { | ||
data := []byte(`nodes: | ||
- hostname: node1 | ||
extensionServices: | ||
- name: nut-client | ||
configFiles: | ||
- content: MONITOR ${upsmonHost} 1 remote pass password | ||
mountPath: /usr/local/etc/nut/upsmon.conf | ||
environment: | ||
- UPS_NAME=ups | ||
- name: nut-client2 | ||
configFiles: | ||
- content: hello | ||
mountPath: /etc/hello | ||
- content: hello2 | ||
mountPath: /etc/hello2`) | ||
|
||
var m config.TalhelperConfig | ||
if err := yaml.Unmarshal(data, &m); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
expectedExtension1Name := "nut-client" | ||
expectedExtension1ConfigFiles := []extensions.ConfigFile{ | ||
{ | ||
ConfigFileContent: "MONITOR ${upsmonHost} 1 remote pass password", | ||
ConfigFileMountPath: "/usr/local/etc/nut/upsmon.conf", | ||
}, | ||
} | ||
expectedExtension1Environment := []string{"UPS_NAME=ups"} | ||
expectedExtension2Name := "nut-client2" | ||
expectedExtension2ConfigFiles := []extensions.ConfigFile{ | ||
{ | ||
ConfigFileContent: "hello", | ||
ConfigFileMountPath: "/etc/hello", | ||
}, | ||
{ | ||
ConfigFileContent: "hello2", | ||
ConfigFileMountPath: "/etc/hello2", | ||
}, | ||
} | ||
|
||
result, err := GenerateNodeExtensionServiceConfig(m.Nodes[0].ExtensionServices) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
compare(result[0].Name(), expectedExtension1Name, t) | ||
compare(result[0].ServiceConfigFiles, expectedExtension1ConfigFiles, t) | ||
compare(result[0].Environment(), expectedExtension1Environment, t) | ||
compare(result[1].Name(), expectedExtension2Name, t) | ||
compare(result[1].ServiceConfigFiles, expectedExtension2ConfigFiles, t) | ||
} |