-
Notifications
You must be signed in to change notification settings - Fork 198
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
MGMT-10209: Pass in icsp file to be used for 'oc adm release extract' #4115
Changes from all commits
b342025
caaf1b4
f71d515
8c90167
a5f7054
9618453
54e72f3
bea6a97
755e9b2
a0862e8
b21f7e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,10 +27,12 @@ import ( | |
"github.com/coreos/vcontext/report" | ||
"github.com/go-openapi/swag" | ||
bmh_v1alpha1 "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" | ||
operatorv1alpha1 "github.com/openshift/api/operator/v1alpha1" | ||
clusterPkg "github.com/openshift/assisted-service/internal/cluster" | ||
"github.com/openshift/assisted-service/internal/common" | ||
"github.com/openshift/assisted-service/internal/constants" | ||
"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" | ||
"github.com/openshift/assisted-service/internal/network" | ||
|
@@ -51,6 +53,7 @@ import ( | |
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
k8sjson "k8s.io/apimachinery/pkg/runtime/serializer/json" | ||
"k8s.io/client-go/kubernetes/scheme" | ||
k8syaml "sigs.k8s.io/yaml" | ||
) | ||
|
||
const ( | ||
|
@@ -288,15 +291,23 @@ func (g *installerGenerator) UploadToS3(ctx context.Context) error { | |
|
||
// Generate generates ignition files and applies modifications. | ||
func (g *installerGenerator) Generate(ctx context.Context, installConfig []byte, platformType models.PlatformType) error { | ||
var icspFile string | ||
log := logutil.FromContext(ctx, g.log) | ||
|
||
// In case we don't want to override image for extracting installer use release one | ||
if g.installerReleaseImageOverride == "" { | ||
g.installerReleaseImageOverride = g.releaseImage | ||
} | ||
|
||
// If ImageContentSources are defined, store in a file for the 'oc' command | ||
icspFile, err := getIcspFileFromInstallConfig(installConfig, log) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to create file with ImageContentSources") | ||
} | ||
defer removeIcspFile(icspFile) | ||
|
||
installerPath, err := installercache.Get(g.installerReleaseImageOverride, g.releaseImageMirror, g.installerDir, | ||
g.cluster.PullSecret, platformType, log) | ||
g.cluster.PullSecret, platformType, icspFile, log) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to get installer path") | ||
} | ||
|
@@ -1513,3 +1524,76 @@ func proxySettingsForIgnition(httpProxy, httpsProxy, noProxy string) (string, er | |
} | ||
return buf.String(), nil | ||
} | ||
|
||
func getIcspFileFromInstallConfig(cfg []byte, log logrus.FieldLogger) (string, error) { | ||
contents, err := getIcsp(cfg) | ||
if err != nil { | ||
return "", err | ||
} | ||
if contents == nil { | ||
log.Infof("No ImageContentSources in install-config to build ICSP file") | ||
return "", nil | ||
} | ||
|
||
icspFile, err := ioutil.TempFile("", "icsp-file") | ||
if err != nil { | ||
return "", err | ||
} | ||
log.Infof("Building ICSP file from install-config with contents %s", contents) | ||
if _, err := icspFile.Write(contents); err != nil { | ||
icspFile.Close() | ||
os.Remove(icspFile.Name()) | ||
zaneb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return "", err | ||
} | ||
icspFile.Close() | ||
zaneb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return icspFile.Name(), nil | ||
} | ||
|
||
func getIcsp(cfg []byte) ([]byte, error) { | ||
|
||
var installCfg installcfg.InstallerConfigBaremetal | ||
if err := yaml.Unmarshal(cfg, &installCfg); err != nil { | ||
return nil, err | ||
} | ||
|
||
if len(installCfg.ImageContentSources) == 0 { | ||
// No ImageContentSources were defined | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider logging here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added logging. |
||
return nil, nil | ||
} | ||
|
||
icsp := operatorv1alpha1.ImageContentSourcePolicy{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: operatorv1alpha1.SchemeGroupVersion.String(), | ||
Kind: "ImageContentSourcePolicy", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "image-policy", | ||
// not namespaced | ||
}, | ||
} | ||
|
||
icsp.Spec.RepositoryDigestMirrors = make([]operatorv1alpha1.RepositoryDigestMirrors, len(installCfg.ImageContentSources)) | ||
for i, imageSource := range installCfg.ImageContentSources { | ||
icsp.Spec.RepositoryDigestMirrors[i] = operatorv1alpha1.RepositoryDigestMirrors{Source: imageSource.Source, Mirrors: imageSource.Mirrors} | ||
|
||
} | ||
|
||
// Convert to json first so json tags are handled | ||
jsonData, err := json.Marshal(&icsp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
contents, err := k8syaml.JSONToYAML(jsonData) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return contents, nil | ||
} | ||
|
||
func removeIcspFile(filename string) { | ||
if filename != "" { | ||
os.Remove(filename) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add logging of the ICSP content.
It should allow us to debug issues in case something goes wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, added.