Skip to content
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
68 changes: 3 additions & 65 deletions internal/ignition/installmanifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,18 @@ import (
"os/exec"
"path/filepath"
"sort"
"strconv"
"strings"

config_latest_types "github.com/coreos/ignition/v2/config/v3_2/types"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
"github.com/google/uuid"
bmh_v1alpha1 "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1"
v1 "github.com/openshift/api/config/v1"
"github.com/openshift/api/features"
"github.com/openshift/assisted-service/internal/common"
ignitioncommon "github.com/openshift/assisted-service/internal/common/ignition"
"github.com/openshift/assisted-service/internal/constants"
eventsapi "github.com/openshift/assisted-service/internal/events/api"
"github.com/openshift/assisted-service/internal/host/hostutil"
"github.com/openshift/assisted-service/internal/installcfg"
"github.com/openshift/assisted-service/internal/installercache"
"github.com/openshift/assisted-service/internal/manifests"
manifestsapi "github.com/openshift/assisted-service/internal/manifests/api"
Expand Down Expand Up @@ -103,7 +99,6 @@ type installerGenerator struct {
nodeIpAllocations map[strfmt.UUID]*network.NodeIpAllocation
manifestApi manifestsapi.ManifestsAPI
iriPatcher internalReleaseImagePatcher
rawInstallConfig []byte
}

var fileNames = [...]string{
Expand Down Expand Up @@ -146,10 +141,6 @@ func (g *installerGenerator) UploadToS3(ctx context.Context) error {
}

func (g *installerGenerator) patchInternalReleaseManifests(ctx context.Context, manifestFiles []s3wrapper.ObjectInfo) error {
if !g.isFeatureGateEnabled(features.FeatureGateNoRegistryClusterInstall) {
return nil
}

if err := g.iriPatcher.PatchManifests(ctx, manifestFiles); err != nil {
g.log.WithError(err).Errorf("failed to process manifests for cluster %s", g.cluster.ID)
return err
Expand All @@ -172,8 +163,6 @@ func (g *installerGenerator) allocateNodeIpsIfNeeded(log logrus.FieldLogger) {
func (g *installerGenerator) Generate(ctx context.Context, installConfig []byte, forceInsecurePolicyJson bool) error {
var err error
log := logutil.FromContext(ctx, g.log)
g.rawInstallConfig = installConfig

defer func() {
if err != nil {
os.Remove(filepath.Join(g.workDir, "manifests"))
Expand Down Expand Up @@ -777,11 +766,9 @@ func (g *installerGenerator) updateBootstrap(ctx context.Context, bootstrapPath
setNMConfigration(config)
}

if g.isFeatureGateEnabled(features.FeatureGateNoRegistryClusterInstall) {
err = g.iriPatcher.UpdateBootstrap(config)
if err != nil {
return err
}
err = g.iriPatcher.UpdateBootstrap(config)
if err != nil {
return err
}

err = ignitioncommon.WriteIgnitionFile(bootstrapPath, config)
Expand Down Expand Up @@ -1310,55 +1297,6 @@ func (g *installerGenerator) downloadManifest(ctx context.Context, manifest stri
return nil
}

func (g *installerGenerator) isFeatureGateEnabled(feature v1.FeatureGateName) bool {
var installConfig installcfg.InstallerConfigBaremetal

if err := json.Unmarshal(g.rawInstallConfig, &installConfig); err != nil {
g.log.Errorf("cannot convert install config data while checking feature gate %s: %v", string(feature), err)
return false
}

featureEnabled := false
switch installConfig.FeatureSet {
case v1.CustomNoUpgrade:
for _, fg := range installConfig.FeatureGates {
// Parse feature gate
featureParts := strings.Split(fg, "=")
if len(featureParts) != 2 {
g.log.Debugf("Cannot parse feature gate %s, skipping", fg)
continue
}
name := featureParts[0]
enabled, err := strconv.ParseBool(featureParts[1])
if err != nil {
g.log.Debugf("Unsupported feature value %s, skipping", fg)
continue
}

if name == string(feature) && enabled {
featureEnabled = true
break
}
}
default:
feats, err := features.FeatureSets(features.SelfManaged, installConfig.FeatureSet)
if err != nil {
g.log.Errorf("error while retrieving features definition: %v", err)
break
}

for _, f := range feats.Enabled {
if f.FeatureGateAttributes.Name == feature {
featureEnabled = true
break
}
}
}

g.log.Infof("Feature gate %s enabled: %v", string(feature), featureEnabled)
return featureEnabled
}

// UploadToS3 uploads the generated files to S3
func uploadToS3(ctx context.Context, workDir string, cluster *common.Cluster, s3Client s3wrapper.API, log logrus.FieldLogger) error {
toUpload := fileNames[:]
Expand Down
47 changes: 0 additions & 47 deletions internal/ignition/installmanifests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
v1 "github.com/openshift/api/config/v1"
"github.com/openshift/api/features"
"github.com/openshift/assisted-service/internal/common"
"github.com/openshift/assisted-service/internal/common/ignition"
"github.com/openshift/assisted-service/internal/constants"
eventsapi "github.com/openshift/assisted-service/internal/events/api"
"github.com/openshift/assisted-service/internal/host/hostutil"
"github.com/openshift/assisted-service/internal/installcfg"
"github.com/openshift/assisted-service/internal/installercache"
manifestsapi "github.com/openshift/assisted-service/internal/manifests/api"
"github.com/openshift/assisted-service/internal/metrics"
Expand Down Expand Up @@ -56,50 +53,6 @@ func testCluster() *common.Cluster {
}
}

var _ = Describe("Feature gates check", func() {
var newInstallGenerator = func(featureSet v1.FeatureSet, featureGateWithState string) *installerGenerator {
installConfig := installcfg.InstallerConfigBaremetal{
FeatureSet: featureSet,
}
if featureGateWithState != "" {
installConfig.FeatureGates = []string{featureGateWithState}
}
bytes, err := json.Marshal(&installConfig)
Expect(err).NotTo(HaveOccurred())

return &installerGenerator{
log: logrus.New(),
rawInstallConfig: bytes,
}
}

Context("Verify NoRegistryClusterInstall feature", func() {
It("Is not enabled by default", func() {
ig := newInstallGenerator(v1.Default, "")
Expect(ig.isFeatureGateEnabled(features.FeatureGateNoRegistryClusterInstall)).To(BeFalse())
})

It("Is enabled for TP and DP", func() {
ig := newInstallGenerator(v1.TechPreviewNoUpgrade, "")
Expect(ig.isFeatureGateEnabled(features.FeatureGateNoRegistryClusterInstall)).To(BeTrue())

ig = newInstallGenerator(v1.DevPreviewNoUpgrade, "")
Expect(ig.isFeatureGateEnabled(features.FeatureGateNoRegistryClusterInstall)).To(BeTrue())
})

It("CustomNoUpgrade check", func() {
ig := newInstallGenerator(v1.CustomNoUpgrade, "")
Expect(ig.isFeatureGateEnabled(features.FeatureGateNoRegistryClusterInstall)).To(BeFalse())

ig = newInstallGenerator(v1.CustomNoUpgrade, string(features.FeatureGateNoRegistryClusterInstall)+"=false")
Expect(ig.isFeatureGateEnabled(features.FeatureGateNoRegistryClusterInstall)).To(BeFalse())

ig = newInstallGenerator(v1.CustomNoUpgrade, string(features.FeatureGateNoRegistryClusterInstall)+"=true")
Expect(ig.isFeatureGateEnabled(features.FeatureGateNoRegistryClusterInstall)).To(BeTrue())
})
})
})

var _ = Describe("Bootstrap Ignition Update", func() {
const bootstrap1 = `{
"ignition": {
Expand Down
24 changes: 13 additions & 11 deletions internal/ignition/internalreleaseimage_patcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
config_latest_types "github.com/coreos/ignition/v2/config/v3_2/types"
"github.com/go-openapi/swag"
configv1 "github.com/openshift/api/config/v1"
mcfgv1alpha1 "github.com/openshift/api/machineconfiguration/v1alpha1"
"github.com/openshift/assisted-service/internal/common"
manifestsapi "github.com/openshift/assisted-service/internal/manifests/api"
"github.com/openshift/assisted-service/models"
Expand All @@ -26,7 +25,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/yaml"
k8syaml "sigs.k8s.io/yaml"
)

const (
Expand All @@ -49,7 +47,7 @@ type internalReleaseImagePatcher struct {
s3Client s3wrapper.API
manifestApi manifestsapi.ManifestsAPI
iriRegistryDomain string
iri *mcfgv1alpha1.InternalReleaseImage
iriFound bool
}

// NewInternalReleaseImagePatcher creates a new internalReleaseImagePatcher instance.
Expand All @@ -60,7 +58,6 @@ func NewInternalReleaseImagePatcher(cluster *common.Cluster, s3Client s3wrapper.
manifestApi: manifestApi,
log: log,
iriRegistryDomain: fmt.Sprintf("api-int.%s.%s", cluster.Name, cluster.BaseDNSDomain),
iri: nil,
}
}

Expand Down Expand Up @@ -97,7 +94,7 @@ func (i *internalReleaseImagePatcher) uploadManifests(ctx context.Context, key s
fileName := path.Base(key)
i.log.Infof("Updating resource %s as %s", key, fileName)

data, err := k8syaml.Marshal(obj)
data, err := yaml.Marshal(obj)
if err != nil {
return err
}
Expand Down Expand Up @@ -153,15 +150,20 @@ func (i *internalReleaseImagePatcher) getInternalReleaseImageManifest(ctx contex
if err != nil {
return err
}
obj := &mcfgv1alpha1.InternalReleaseImage{}
err = yaml.Unmarshal(content, obj)
var meta struct {
Kind string `json:"kind"`
Metadata struct {
Name string `json:"name"`
} `json:"metadata"`
}
err = yaml.Unmarshal(content, &meta)
if err != nil {
i.log.Debugf("Cannot decode manifest %s, skipping", f.Path)
continue
}

if obj.Kind == iriKind && obj.Name == iriInstanceName {
i.iri = obj.DeepCopy()
if meta.Kind == iriKind && meta.Metadata.Name == iriInstanceName {
i.iriFound = true
break
}
}
Expand All @@ -181,7 +183,7 @@ func (i *internalReleaseImagePatcher) PatchManifests(ctx context.Context, manife
return err
}
// Skip if InternalReleaseImage manifest wasn't found.
if i.iri == nil {
if !i.iriFound {
return nil
}
i.log.Infof("Patching InternalReleaseImage mirror resources")
Expand Down Expand Up @@ -327,7 +329,7 @@ func (i *internalReleaseImagePatcher) getRegistriesConfFromIgn(bootstrapConfig *

func (i *internalReleaseImagePatcher) UpdateBootstrap(bootstrapConfig *config_latest_types.Config) error {
// Skip if InternalReleaseImage manifest wasn't found.
if i.iri == nil {
if !i.iriFound {
return nil
}
i.log.Infof("Updating bootstrap.ign registries.conf for InternalReleaseImage")
Expand Down
5 changes: 2 additions & 3 deletions internal/ignition/internalreleaseimage_patcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
configv1 "github.com/openshift/api/config/v1"
mcfgv1alpha1 "github.com/openshift/api/machineconfiguration/v1alpha1"
"github.com/openshift/assisted-service/internal/common"
manifestsapi "github.com/openshift/assisted-service/internal/manifests/api"
"github.com/openshift/assisted-service/pkg/s3wrapper"
Expand Down Expand Up @@ -95,7 +94,7 @@ var _ = Describe("InternalReleaseImage resources patching", func() {

Context("when IRI resource was found", func() {
It("add IRI mirrors to bootstrap.ign/registries.conf", func() {
iriPatcher.iri = &mcfgv1alpha1.InternalReleaseImage{}
iriPatcher.iriFound = true
bootstrapIgnition := iriBootstrapIgnition()

err := iriPatcher.UpdateBootstrap(bootstrapIgnition)
Expand Down Expand Up @@ -153,7 +152,7 @@ var _ = Describe("InternalReleaseImage resources patching", func() {

Context("when IRI wasn't found", func() {
It("do not update bootstrap.ign", func() {
iriPatcher.iri = nil
iriPatcher.iriFound = false
bootstrapIgnition := iriBootstrapIgnition()

err := iriPatcher.UpdateBootstrap(bootstrapIgnition)
Expand Down
Loading