-
Notifications
You must be signed in to change notification settings - Fork 259
Add Azure platform detection to the translator #2183
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
Merged
+2,383
−164
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dde56e0
feat(translator): add Azure VM + AKS platform detection
movence 70758bd
fix(translator): Windows token path, Azure resource_id guard, retry c…
movence 5171ebb
fix(translator): wire oidctoken->sigv4 web identity, EC2-scope resour…
movence 9e9745d
refactor(translator): single-source oidctoken path, require role_arn …
movence 1b32146
refactor(translator): address review — fix gosec lint, simplify azure…
movence db7fe3e
Merge branch 'main' into feature/azure-detection
movence 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,91 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package context | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
|
|
||
| "github.com/aws/amazon-cloudwatch-agent/translator/config" | ||
| ) | ||
|
|
||
| func TestSetMode_Azure(t *testing.T) { | ||
| ResetContext() | ||
| ctx := CurrentContext() | ||
|
|
||
| ctx.SetMode(config.ModeAzureVM) | ||
| assert.Equal(t, config.ModeAzureVM, ctx.Mode()) | ||
| assert.Equal(t, config.ShortModeAzureVM, ctx.ShortMode()) | ||
| } | ||
|
|
||
| func TestSetMode_ExistingModesUnchanged(t *testing.T) { | ||
| cases := map[string]struct { | ||
| mode string | ||
| wantShort string | ||
| }{ | ||
| "EC2": {config.ModeEC2, config.ShortModeEC2}, | ||
| "OnPrem": {config.ModeOnPrem, config.ShortModeOnPrem}, | ||
| "WithIRSA": {config.ModeWithIRSA, config.ShortModeWithIRSA}, | ||
| } | ||
| for name, tc := range cases { | ||
| t.Run(name, func(t *testing.T) { | ||
| ResetContext() | ||
| ctx := CurrentContext() | ||
| ctx.SetMode(tc.mode) | ||
| assert.Equal(t, tc.mode, ctx.Mode()) | ||
| assert.Equal(t, tc.wantShort, ctx.ShortMode()) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestSetKubernetesMode_AKS(t *testing.T) { | ||
| ResetContext() | ||
| ctx := CurrentContext() | ||
|
|
||
| ctx.SetKubernetesMode(config.ModeAKS) | ||
| assert.Equal(t, config.ModeAKS, ctx.KubernetesMode()) | ||
| assert.Equal(t, config.ShortModeAKS, ctx.ShortMode()) | ||
| } | ||
|
|
||
| func TestSetKubernetesMode_ExistingModesUnchanged(t *testing.T) { | ||
| cases := map[string]struct { | ||
| mode string | ||
| wantShort string | ||
| }{ | ||
| "EKS": {config.ModeEKS, config.ShortModeEKS}, | ||
| "K8sEC2": {config.ModeK8sEC2, config.ShortModeK8sEC2}, | ||
| "K8sOnPrem": {config.ModeK8sOnPrem, config.ShortModeK8sOnPrem}, | ||
| } | ||
| for name, tc := range cases { | ||
| t.Run(name, func(t *testing.T) { | ||
| ResetContext() | ||
| ctx := CurrentContext() | ||
| ctx.SetKubernetesMode(tc.mode) | ||
| assert.Equal(t, tc.mode, ctx.KubernetesMode()) | ||
| assert.Equal(t, tc.wantShort, ctx.ShortMode()) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestSetKubernetesMode_UnknownClears(t *testing.T) { | ||
| ResetContext() | ||
| ctx := CurrentContext() | ||
| // A previously-set valid kubernetes mode is cleared by an unknown one. | ||
| ctx.SetKubernetesMode(config.ModeAKS) | ||
| ctx.SetKubernetesMode("not-a-real-mode") | ||
| assert.Equal(t, "", ctx.KubernetesMode()) | ||
| // The default branch intentionally keeps shortMode (SetMode sets it first); with no host mode set it retains the last k8s shortMode. | ||
| assert.Equal(t, config.ShortModeAKS, ctx.ShortMode()) | ||
| } | ||
|
|
||
| func TestSetKubernetesMode_EmptyPreservesHostShortMode(t *testing.T) { | ||
| ResetContext() | ||
| ctx := CurrentContext() | ||
| // Real startup ordering: host mode first, then empty (non-Kubernetes) mode; the host shortMode must survive. | ||
| ctx.SetMode(config.ModeAzureVM) | ||
| ctx.SetKubernetesMode("") | ||
| assert.Equal(t, "", ctx.KubernetesMode()) | ||
| assert.Equal(t, config.ShortModeAzureVM, ctx.ShortMode()) | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.