-
Notifications
You must be signed in to change notification settings - Fork 296
azure: read custom data from ovf-env.xml #2321
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
Open
peytonr18
wants to merge
4
commits into
coreos:main
Choose a base branch
from
peytonr18:probertson-ovf-customdata
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+171
−13
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5141651
azure: read custom data from ovf-env.xml
peytonr18 4188235
azure: drop CustomData.bin in favor of ovf-env.xml
peytonr18 2617473
Merge remote-tracking branch 'origin/main' into probertson-ovf-custom…
peytonr18 39e8249
providers/azure: separate import groups
peytonr18 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,116 @@ | ||
| // Copyright 2026 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 azure | ||
|
|
||
| import ( | ||
| "encoding/base64" | ||
| "errors" | ||
| "fmt" | ||
| "testing" | ||
| ) | ||
|
|
||
| // ovfEnvWithCustomData returns an Azure ovf-env.xml with the given CustomData | ||
| // element (which may be empty) spliced into the provisioning section. | ||
| func ovfEnvWithCustomData(customDataElement string) string { | ||
| return fmt.Sprintf(`<?xml version="1.0" encoding="utf-8"?> | ||
| <ns0:Environment xmlns:ns0="http://schemas.dmtf.org/ovf/environment/1" | ||
| xmlns:ns1="http://schemas.microsoft.com/windowsazure" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
| <ns1:ProvisioningSection> | ||
| <ns1:Version>1.0</ns1:Version> | ||
| <ns1:LinuxProvisioningConfigurationSet> | ||
| <ns1:ConfigurationSetType>LinuxProvisioningConfiguration</ns1:ConfigurationSetType> | ||
| <ns1:HostName>host</ns1:HostName> | ||
| <ns1:UserName>core</ns1:UserName> | ||
| %s | ||
| <ns1:DisableSshPasswordAuthentication>true</ns1:DisableSshPasswordAuthentication> | ||
| </ns1:LinuxProvisioningConfigurationSet> | ||
| </ns1:ProvisioningSection> | ||
| <ns1:PlatformSettingsSection> | ||
| <ns1:Version>1.0</ns1:Version> | ||
| <ns1:PlatformSettings> | ||
| <ns1:ProvisionGuestAgent>true</ns1:ProvisionGuestAgent> | ||
| </ns1:PlatformSettings> | ||
| </ns1:PlatformSettingsSection> | ||
| </ns0:Environment>`, customDataElement) | ||
| } | ||
|
|
||
| func TestCustomDataFromOvfEnv(t *testing.T) { | ||
| config := `{"ignition":{"version":"3.4.0"}}` | ||
| encoded := base64.StdEncoding.EncodeToString([]byte(config)) | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| xml string | ||
| out string | ||
| nilOut bool | ||
| wantErr error | ||
| }{ | ||
| { | ||
| name: "custom data present", | ||
| xml: ovfEnvWithCustomData(fmt.Sprintf("<ns1:CustomData>%s</ns1:CustomData>", encoded)), | ||
| out: config, | ||
| }, | ||
| { | ||
| name: "custom data split across lines", | ||
| xml: ovfEnvWithCustomData(fmt.Sprintf("<ns1:CustomData>%s\n %s</ns1:CustomData>", encoded[:8], encoded[8:])), | ||
| out: config, | ||
| }, | ||
| { | ||
| name: "no custom data element", | ||
| xml: ovfEnvWithCustomData(""), | ||
| nilOut: true, | ||
| }, | ||
| { | ||
| name: "empty custom data element", | ||
| xml: ovfEnvWithCustomData("<ns1:CustomData></ns1:CustomData>"), | ||
| nilOut: true, | ||
| }, | ||
| { | ||
| name: "malformed xml", | ||
| xml: "<ns0:Environment>not closed", | ||
| wantErr: errParseOvfEnv, | ||
| }, | ||
| { | ||
| name: "invalid base64", | ||
| xml: ovfEnvWithCustomData("<ns1:CustomData>!!! not base64 !!!</ns1:CustomData>"), | ||
| wantErr: errDecodeCustomData, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got, err := customDataFromOvfEnv([]byte(tt.xml)) | ||
| if tt.wantErr != nil { | ||
| if !errors.Is(err, tt.wantErr) { | ||
| t.Fatalf("expected error %v, got %v", tt.wantErr, err) | ||
| } | ||
| return | ||
| } | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| if tt.nilOut { | ||
| if got != nil { | ||
| t.Fatalf("expected nil, got %q", got) | ||
| } | ||
| return | ||
| } | ||
| if string(got) != tt.out { | ||
| t.Fatalf("expected %q, got %q", tt.out, got) | ||
| } | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why are we dropping
CustomData.binforovf-env.xml, rather than checking for both ?Would there ever be cases where the old
/CustomData.binis populated and the correct place from which to read?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 question!
To make a long answer short, there's really never a scenario where /CustomData.bin is populated and the
ovfisn't.Azure almost exclusively uses the OVF at this point, and all of the custom data that's exposed to the guest is already available in
ovf-env.xml.That's also backed up by the fact that
/CustomData.binwas broken for CVMs for a bit and nobody noticed until it came up in the Fedora thread!That said, I'm not strongly opposed to keeping
/CustomData.binas a fallback if it makes people more comfortable. I just haven't found an Azure scenario where it would buy us anything, since the same data should already be available inovf-env.xml.