-
Notifications
You must be signed in to change notification settings - Fork 1.5k
MCO-2200: Add day-0 dual streams support for ABI install flow #10481
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
base: main
Are you sure you want to change the base?
Changes from all commits
e2aedd3
c1a889a
537d719
ac9df48
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 |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ import ( | |
| "github.com/openshift/assisted-service/models" | ||
| hivev1 "github.com/openshift/hive/apis/hive/v1" | ||
| "github.com/openshift/installer/pkg/asset" | ||
| "github.com/openshift/installer/pkg/asset/manifests" | ||
| ) | ||
|
|
||
| func TestAgentManifests_Generate(t *testing.T) { | ||
|
|
@@ -59,6 +60,7 @@ func TestAgentManifests_Generate(t *testing.T) { | |
| &AgentClusterInstall{Config: fakeAgentClusterInstall}, | ||
| &ClusterDeployment{Config: fakeClusterDeployment}, | ||
| &ClusterImageSet{Config: fakeClusterImageSet}, | ||
| &manifests.OSImageStream{}, | ||
|
Contributor
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. As mentioned before, very likely this will not be required |
||
| }, | ||
| ExpectedPullSecret: fakeSecret, | ||
| ExpectedInfraEnv: fakeInfraEnv, | ||
|
|
@@ -93,6 +95,7 @@ func TestAgentManifests_Generate(t *testing.T) { | |
| &AgentClusterInstall{}, | ||
| &ClusterDeployment{}, | ||
| &ClusterImageSet{}, | ||
| &manifests.OSImageStream{}, | ||
| }, | ||
| ExpectedError: "invalid agent configuration: spec.nmStateConfigLabelSelector.matchLabels: Required value: infraEnv and fake-nmState NMState Config labels do not match. Expected: map[missing-label:missing-label] Found: map[]", | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -131,6 +131,8 @@ type agentClusterInstallInstallConfigOverrides struct { | |
| FeatureSet configv1.FeatureSet `json:"featureSet,omitempty"` | ||
| // Allow override of FeatureGates | ||
| FeatureGates []string `json:"featureGates,omitempty"` | ||
| // OSImageStream is the OS Image Stream to be used for all machines in the cluster | ||
| OSImageStream types.OSImageStream `json:"osImageStream,omitempty"` | ||
| } | ||
|
|
||
| var _ asset.WritableAsset = (*AgentClusterInstall)(nil) | ||
|
|
@@ -262,6 +264,11 @@ func (a *AgentClusterInstall) Generate(_ context.Context, dependencies asset.Par | |
| icOverrides.FeatureGates = installConfig.Config.FeatureGates | ||
| } | ||
|
|
||
| if installConfig.Config.OSImageStream != "" { | ||
| icOverridden = true | ||
| icOverrides.OSImageStream = installConfig.Config.OSImageStream | ||
|
Member
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. 👍 |
||
| } | ||
|
|
||
| if installConfig.Config.Proxy != nil { | ||
| rendezvousIP := "" | ||
| if agentConfig.Config != nil { | ||
|
|
||
|
Contributor
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. The name of this asset file should be
Contributor
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. It'd be nice also to have a dedicated test file for this new asset |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| package manifests | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
|
|
||
| "github.com/sirupsen/logrus" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
|
||
| hiveext "github.com/openshift/assisted-service/api/hiveextension/v1beta1" | ||
| mcfgclient "github.com/openshift/client-go/machineconfiguration/clientset/versioned" | ||
| "github.com/openshift/installer/pkg/asset" | ||
| "github.com/openshift/installer/pkg/asset/agent/joiner" | ||
| "github.com/openshift/installer/pkg/asset/agent/workflow" | ||
| "github.com/openshift/installer/pkg/rhcos" | ||
| "github.com/openshift/installer/pkg/types" | ||
| ) | ||
|
|
||
| // installConfigOverridesData is used to parse the installConfigOverrides annotation. | ||
| type installConfigOverridesData struct { | ||
| OSImageStream types.OSImageStream `json:"osImageStream,omitempty"` | ||
| } | ||
|
|
||
| // AgentOSImageStream exposes the OS image stream value for Agent workflows. | ||
| // This is a pure data asset that does not generate any files. | ||
| type AgentOSImageStream struct { | ||
| Stream types.OSImageStream | ||
| } | ||
|
|
||
| var _ asset.Asset = (*AgentOSImageStream)(nil) | ||
|
|
||
| // Name returns the human-friendly name of the asset. | ||
| func (*AgentOSImageStream) Name() string { | ||
| return "Agent OS Image Stream" | ||
| } | ||
|
|
||
| // Dependencies returns all of the dependencies directly needed to generate | ||
| // the asset. | ||
| func (*AgentOSImageStream) Dependencies() []asset.Asset { | ||
| return []asset.Asset{ | ||
| &workflow.AgentWorkflow{}, | ||
| &joiner.ClusterInfo{}, | ||
| &AgentManifests{}, | ||
|
Contributor
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. This works, but since the current asset requires only AgentClusterInstall it should be sufficient to have, as a dependency, just |
||
| } | ||
| } | ||
|
|
||
| // Generate extracts the OS image stream value from available sources. | ||
| func (a *AgentOSImageStream) Generate(ctx context.Context, dependencies asset.Parents) error { | ||
| agentWorkflow := &workflow.AgentWorkflow{} | ||
| clusterInfo := &joiner.ClusterInfo{} | ||
| agentManifests := &AgentManifests{} | ||
| dependencies.Get(agentWorkflow, clusterInfo, agentManifests) | ||
|
|
||
| var stream types.OSImageStream | ||
|
|
||
| switch agentWorkflow.Workflow { | ||
|
Contributor
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. This is a slightly unusual pattern, since usually this kind of logic (discriminating between the Install and AddNodes workflow) is applied directly into the assets that need to consume the dependencies values. |
||
| case workflow.AgentWorkflowTypeInstall: | ||
| // For install workflow, read from AgentClusterInstall manifest (Layer 2) | ||
| if agentManifests.AgentClusterInstall != nil { | ||
| stream = a.getStreamFromAgentClusterInstall(agentManifests.AgentClusterInstall) | ||
| } | ||
|
|
||
| case workflow.AgentWorkflowTypeAddNodes: | ||
| // For add-nodes workflow, query the cluster's OSImageStream CR | ||
| if clusterInfo.OpenshiftMachineConfigClient != nil { | ||
| var err error | ||
| stream, err = a.getStreamFromCluster(ctx, clusterInfo.OpenshiftMachineConfigClient) | ||
| if err != nil { | ||
| // Log but don't fail - fall back to default | ||
| logrus.Warnf("Failed to query cluster OSImageStream: %v", err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Default | ||
| if stream == "" { | ||
| stream = rhcos.DefaultOSImageStream | ||
| } | ||
|
|
||
| a.Stream = stream | ||
| return nil | ||
| } | ||
|
|
||
| // getStreamFromAgentClusterInstall extracts the osImageStream from the | ||
| // AgentClusterInstall installConfigOverrides annotation. | ||
| func (a *AgentOSImageStream) getStreamFromAgentClusterInstall(aci *hiveext.AgentClusterInstall) types.OSImageStream { | ||
| if aci.Annotations == nil { | ||
| return "" | ||
| } | ||
|
|
||
| overridesJSON, ok := aci.Annotations[installConfigOverrides] | ||
| if !ok { | ||
| return "" | ||
| } | ||
|
|
||
| var overrides installConfigOverridesData | ||
| if err := json.Unmarshal([]byte(overridesJSON), &overrides); err != nil { | ||
| logrus.Debugf("Failed to parse installConfigOverrides: %v", err) | ||
| return "" | ||
| } | ||
|
|
||
| return overrides.OSImageStream | ||
| } | ||
|
|
||
| // getStreamFromCluster queries the cluster's OSImageStream CR to determine | ||
| // the default stream. | ||
| func (a *AgentOSImageStream) getStreamFromCluster(ctx context.Context, client mcfgclient.Interface) (types.OSImageStream, error) { | ||
| osImageStream, err := client.MachineconfigurationV1alpha1().OSImageStreams().Get(ctx, "cluster", metav1.GetOptions{}) | ||
|
Contributor
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. This does not look correct, since it's a |
||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| if osImageStream.Spec == nil { | ||
| return "", nil | ||
| } | ||
|
|
||
| return types.OSImageStream(osImageStream.Spec.DefaultStream), nil | ||
| } | ||
|
Contributor
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. Given the new specific agen asset |
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.
nit: for readability, rather than an empty string a more speaking constant could be better