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

Add openshift/4.8.0-exp that produces MachineConfigs by default #212

Merged
merged 6 commits into from
Mar 19, 2021
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
1 change: 1 addition & 0 deletions config/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ type TranslateOptions struct {
type TranslateBytesOptions struct {
TranslateOptions
Pretty bool
Raw bool // encode only the Ignition config, not any wrapper
Strict bool
}
3 changes: 3 additions & 0 deletions config/common/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,7 @@ var (
// boot device
ErrUnknownBootDeviceLayout = errors.New("layout must be one of: aarch64, ppc64le, x86_64")
ErrTooFewMirrorDevices = errors.New("mirroring requires at least two devices")

// MachineConfigs
ErrNameRequired = errors.New("metadata.name is required")
)
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
fcos1_2 "github.com/coreos/fcct/config/fcos/v1_2"
fcos1_3 "github.com/coreos/fcct/config/fcos/v1_3"
fcos1_4_exp "github.com/coreos/fcct/config/fcos/v1_4_exp"
openshift4_8_exp "github.com/coreos/fcct/config/openshift/v4_8_exp"
rhcos0_1 "github.com/coreos/fcct/config/rhcos/v0_1"
rhcos0_2_exp "github.com/coreos/fcct/config/rhcos/v0_2_exp"

"github.com/coreos/go-semver/semver"
"github.com/coreos/vcontext/report"
Expand All @@ -47,8 +47,8 @@ func init() {
RegisterTranslator("fcos", "1.2.0", fcos1_2.ToIgn3_2Bytes)
RegisterTranslator("fcos", "1.3.0", fcos1_3.ToIgn3_2Bytes)
RegisterTranslator("fcos", "1.4.0-experimental", fcos1_4_exp.ToIgn3_3Bytes)
RegisterTranslator("openshift", "4.8.0-experimental", openshift4_8_exp.ToConfigBytes)
RegisterTranslator("rhcos", "0.1.0", rhcos0_1.ToIgn3_2Bytes)
RegisterTranslator("rhcos", "0.2.0-experimental", rhcos0_2_exp.ToIgn3_3Bytes)
}

/// RegisterTranslator registers a translator for the specified variant and
Expand Down
39 changes: 39 additions & 0 deletions config/openshift/v4_8_exp/result/schema.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2021 Red Hat, Inc
//
// 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 result

import (
"github.com/coreos/ignition/v2/config/v3_2/types"
)

// We round-trip through JSON because Ignition uses `json` struct tags,
// so all struct tags need to be `json` even though we're ultimately
// writing YAML.

type MachineConfig struct {
ApiVersion string `json:"apiVersion"`
Kind string `json:"kind"`
Metadata Metadata `json:"metadata"`
Spec Spec `json:"spec"`
}

type Metadata struct {
Name string `json:"name"`
Labels map[string]string `json:"labels,omitempty"`
}

type Spec struct {
Config types.Config `json:"config"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.)

package v0_2_exp
package v4_8_exp

import (
fcos "github.com/coreos/fcct/config/fcos/v1_4_exp"
fcos "github.com/coreos/fcct/config/fcos/v1_3"
)

type Config struct {
fcos.Config `yaml:",inline"`
Metadata Metadata `yaml:"metadata"`
}

type Metadata struct {
Name string `yaml:"name"`
Labels map[string]string `yaml:"labels,omitempty"`
}
106 changes: 106 additions & 0 deletions config/openshift/v4_8_exp/translate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright 2020 Red Hat, Inc
//
// 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 v4_8_exp

import (
"github.com/coreos/fcct/config/common"
"github.com/coreos/fcct/config/openshift/v4_8_exp/result"
cutil "github.com/coreos/fcct/config/util"
"github.com/coreos/fcct/translate"

"github.com/coreos/ignition/v2/config/v3_2/types"
"github.com/coreos/vcontext/path"
"github.com/coreos/vcontext/report"
)

// ToMachineConfig4_8Unvalidated translates the config to a MachineConfig. It also
// returns the set of translations it did so paths in the resultant config
// can be tracked back to their source in the source config. No config
// validation is performed on input or output.
func (c Config) ToMachineConfig4_8Unvalidated(options common.TranslateOptions) (result.MachineConfig, translate.TranslationSet, report.Report) {
cfg, ts, r := c.Config.ToIgn3_2Unvalidated(options)
if r.IsFatal() {
return result.MachineConfig{}, ts, r
}

// wrap
ts = ts.PrefixPaths(path.New("yaml"), path.New("json", "spec", "config"))
mc := result.MachineConfig{
ApiVersion: "machineconfiguration.openshift.io/v1",
Kind: "MachineConfig",
Metadata: result.Metadata{
Name: c.Metadata.Name,
Labels: make(map[string]string),
},
Spec: result.Spec{
Config: cfg,
},
}
ts.AddTranslation(path.New("yaml", "version"), path.New("json", "apiVersion"))
ts.AddTranslation(path.New("yaml", "version"), path.New("json", "kind"))
ts.AddTranslation(path.New("yaml", "metadata"), path.New("json", "metadata"))
ts.AddTranslation(path.New("yaml", "metadata", "name"), path.New("json", "metadata", "name"))
ts.AddTranslation(path.New("yaml", "version"), path.New("json", "spec"))
ts.AddTranslation(path.New("yaml"), path.New("json", "spec", "config"))
for k, v := range c.Metadata.Labels {
mc.Metadata.Labels[k] = v
ts.AddTranslation(path.New("yaml", "metadata", "labels", k), path.New("json", "metadata", "labels", k))
}
if len(mc.Metadata.Labels) > 0 {
ts.AddTranslation(path.New("yaml", "metadata", "labels"), path.New("json", "metadata", "labels"))
}

return mc, ts, r
}

// ToMachineConfig4_8 translates the config to a MachineConfig. It returns a
// report of any errors or warnings in the source and resultant config. If
// the report has fatal errors or it encounters other problems translating,
// an error is returned.
func (c Config) ToMachineConfig4_8(options common.TranslateOptions) (result.MachineConfig, report.Report, error) {
cfg, r, err := cutil.Translate(c, "ToMachineConfig4_8Unvalidated", options)
return cfg.(result.MachineConfig), r, err
}

// ToIgn3_2Unvalidated translates the config to an Ignition config. It also
// returns the set of translations it did so paths in the resultant config
// can be tracked back to their source in the source config. No config
// validation is performed on input or output.
func (c Config) ToIgn3_2Unvalidated(options common.TranslateOptions) (types.Config, translate.TranslationSet, report.Report) {
mc, ts, r := c.ToMachineConfig4_8Unvalidated(options)
cfg := mc.Spec.Config
ts = ts.Descend(path.New("json", "spec", "config"))
return cfg, ts, r
}

// ToIgn3_2 translates the config to an Ignition config. It returns a
// report of any errors or warnings in the source and resultant config. If
// the report has fatal errors or it encounters other problems translating,
// an error is returned.
func (c Config) ToIgn3_2(options common.TranslateOptions) (types.Config, report.Report, error) {
cfg, r, err := cutil.Translate(c, "ToIgn3_2Unvalidated", options)
return cfg.(types.Config), r, err
}

// ToConfigBytes translates from a v4.8 occ to a v4.8 MachineConfig or a v3.2.0 Ignition config. It returns a report of any errors or
// warnings in the source and resultant config. If the report has fatal errors or it encounters other problems
// translating, an error is returned.
func ToConfigBytes(input []byte, options common.TranslateBytesOptions) ([]byte, report.Report, error) {
if options.Raw {
return cutil.TranslateBytes(input, &Config{}, "ToIgn3_2", options)
} else {
return cutil.TranslateBytesYAML(input, &Config{}, "ToMachineConfig4_8", options)
}
}
29 changes: 29 additions & 0 deletions config/openshift/v4_8_exp/validate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2021 Red Hat, Inc
//
// 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 v4_8_exp

import (
"github.com/coreos/fcct/config/common"

"github.com/coreos/vcontext/path"
"github.com/coreos/vcontext/report"
)

func (m Metadata) Validate(c path.ContextPath) (r report.Report) {
if m.Name == "" {
r.AddOnError(c.Append("name"), common.ErrNameRequired)
}
return
}
Loading