-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move main into a cmd/operator package * Add elemental-installer * Adding installer unit tests * Update Makefile * Update .github/workflows/unit-tests.yaml * Adapat Dockerfile and golreleaser to keep releasing and building elemental-operator as they used to Signed-off-by: David Cassany <[email protected]> Co-authored-by: Itxaka <[email protected]>
- Loading branch information
1 parent
211ad46
commit 1d97f14
Showing
25 changed files
with
2,064 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Unit tests | ||
on: | ||
push: | ||
concurrency: | ||
group: tests-${{ github.head_ref || github.ref }}-${{ github.repository }} | ||
cancel-in-progress: true | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Install Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: '^1.16' | ||
- name: Get dependencies | ||
run: | | ||
# Needed for github.com/google/go-tspi/tspi | ||
# in opensuse this is trousers-devel | ||
sudo apt-get install libtspi-dev | ||
make unit-tests-deps | ||
- name: Run tests | ||
run: | | ||
make unit-tests | ||
- name: Codecov | ||
uses: codecov/codecov-action@v2 | ||
with: | ||
file: ./coverage.out |
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,59 @@ | ||
/* | ||
Copyright © 2022 SUSE LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"os" | ||
|
||
"github.com/rancher/elemental-operator/pkg/config" | ||
"github.com/rancher/elemental-operator/pkg/install" | ||
"github.com/sirupsen/logrus" | ||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
var ( | ||
automatic = flag.Bool("automatic", false, "Check for and run automatic installation") | ||
printConfig = flag.Bool("print-config", false, "Print effective configuration and exit") | ||
configFile = flag.String("config-file", "/oem/userdata", "Config file to use, local file or http/tftp URL") | ||
powerOff = flag.Bool("power-off", false, "Power off after installation") | ||
reboot = flag.Bool("reboot", false, "Reboot after installation") | ||
noRebootAutomatic = flag.Bool("no-reboot-automatic", false, "Dont reboot after installation (only for automatic installation which defaults to reboot after install)") | ||
yes = flag.Bool("y", false, "Do not prompt for questions") | ||
ejectCD = flag.Bool("eject-cd", false, "Ejects the CD on system reboot") | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
if *printConfig { | ||
cfg, err := config.ReadConfig(context.Background(), *configFile, *automatic) | ||
if err != nil { | ||
logrus.Fatal(err) | ||
} | ||
data, err := yaml.Marshal(cfg) | ||
if err != nil { | ||
logrus.Fatal(err) | ||
} | ||
os.Stdout.Write(data) | ||
return | ||
} | ||
|
||
if err := install.Run(*automatic, *configFile, *powerOff, *reboot, *noRebootAutomatic, *yes, *ejectCD); err != nil { | ||
logrus.Fatal(err) | ||
} | ||
} |
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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,102 @@ | ||
/* | ||
Copyright © 2022 SUSE LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package config | ||
|
||
import ( | ||
"github.com/rancher/wrangler/pkg/data" | ||
"github.com/rancher/wrangler/pkg/data/convert" | ||
schemas2 "github.com/rancher/wrangler/pkg/schemas" | ||
"github.com/rancher/wrangler/pkg/schemas/mappers" | ||
) | ||
|
||
type Converter func(val interface{}) interface{} | ||
|
||
type fieldConverter struct { | ||
mappers.DefaultMapper | ||
fieldName string | ||
converter Converter | ||
} | ||
|
||
func (f fieldConverter) ToInternal(data data.Object) error { | ||
val, ok := data[f.fieldName] | ||
if !ok { | ||
return nil | ||
} | ||
data[f.fieldName] = f.converter(val) | ||
return nil | ||
} | ||
|
||
type typeConverter struct { | ||
mappers.DefaultMapper | ||
converter Converter | ||
fieldType string | ||
mappers schemas2.Mappers | ||
} | ||
|
||
func (t *typeConverter) ToInternal(data data.Object) error { | ||
return t.mappers.ToInternal(data) | ||
} | ||
|
||
func (t *typeConverter) ModifySchema(schema *schemas2.Schema, schemas *schemas2.Schemas) error { | ||
for name, field := range schema.ResourceFields { | ||
if field.Type == t.fieldType { | ||
t.mappers = append(t.mappers, fieldConverter{ | ||
fieldName: name, | ||
converter: t.converter, | ||
}) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func NewTypeConverter(fieldType string, converter Converter) schemas2.Mapper { | ||
return &typeConverter{ | ||
fieldType: fieldType, | ||
converter: converter, | ||
} | ||
} | ||
|
||
func NewToMap() schemas2.Mapper { | ||
return NewTypeConverter("map[string]", func(val interface{}) interface{} { | ||
if m, ok := val.(map[string]interface{}); ok { | ||
obj := make(map[string]string, len(m)) | ||
for k, v := range m { | ||
obj[k] = convert.ToString(v) | ||
} | ||
return obj | ||
} | ||
return val | ||
}) | ||
} | ||
|
||
func NewToSlice() schemas2.Mapper { | ||
return NewTypeConverter("array[string]", func(val interface{}) interface{} { | ||
if str, ok := val.(string); ok { | ||
return []string{str} | ||
} | ||
return val | ||
}) | ||
} | ||
|
||
func NewToBool() schemas2.Mapper { | ||
return NewTypeConverter("boolean", func(val interface{}) interface{} { | ||
if str, ok := val.(string); ok { | ||
return str == "true" //nolint:goconst | ||
} | ||
return val | ||
}) | ||
} |
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,69 @@ | ||
/* | ||
Copyright © 2022 SUSE LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package config | ||
|
||
type RancherOS struct { | ||
Install Install `json:"install,omitempty"` | ||
} | ||
|
||
type Install struct { | ||
Automatic bool `json:"automatic,omitempty"` | ||
Firmware string `json:"firmware,omitempty"` | ||
Device string `json:"device,omitempty"` | ||
ConfigURL string `json:"configUrl,omitempty"` | ||
ISOURL string `json:"isoUrl,omitempty"` | ||
ContainerImage string `json:"containerImage,omitempty"` | ||
PowerOff bool `json:"powerOff,omitempty"` | ||
Reboot bool `json:"reboot,omitempty"` | ||
NoFormat bool `json:"noFormat,omitempty"` | ||
Debug bool `json:"debug,omitempty"` | ||
TTY string `json:"tty,omitempty"` | ||
ServerURL string `json:"-"` | ||
Token string `json:"-"` | ||
Role string `json:"-"` | ||
Password string `json:"password,omitempty"` | ||
RegistrationURL string `json:"registrationUrl,omitempty"` | ||
RegistrationCACert string `json:"registrationCaCert,omitempty"` | ||
EjectCD bool `json:"ejectCD,omitempty"` | ||
} | ||
|
||
type Config struct { | ||
SSHAuthorizedKeys []string `json:"ssh_authorized_keys,omitempty"` | ||
RancherOS RancherOS `json:"rancheros,omitempty"` | ||
Data map[string]interface{} `json:"-"` | ||
} | ||
|
||
type YipConfig struct { | ||
Stages map[string][]Stage `json:"stages,omitempty"` | ||
Rancherd Rancherd `json:"rancherd,omitempty"` | ||
} | ||
|
||
type Stage struct { | ||
Users map[string]User `json:"users,omitempty"` | ||
} | ||
|
||
type Rancherd struct { | ||
Server string `json:"server,omitempty"` | ||
Role string `json:"role,omitempty"` | ||
Token string `json:"token,omitempty"` | ||
} | ||
|
||
type User struct { | ||
Name string `json:"name,omitempty"` | ||
PasswordHash string `json:"passwd,omitempty"` | ||
SSHAuthorizedKeys []string `json:"ssh_authorized_keys,omitempty"` | ||
} |
Oops, something went wrong.