-
Notifications
You must be signed in to change notification settings - Fork 191
Set Defaults functionality #1654
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
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
892e3e2
Add internal API defaulting code
mjudeikis 12b750c
Update putOrPatch test
mjudeikis 3eac2b0
drop systemdata
mjudeikis 780e76b
fix e2e tests
mjudeikis c1020b8
generate
mjudeikis 170730b
Swagger review
mjudeikis c1ff486
gen client
mjudeikis 351955b
ListAdminKubeconfig -> ListAdminCredentials
mjudeikis 0b81d66
generate
mjudeikis 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| d2e11a7924d0cbb70672fb0dd6b1a387ccaec8b97a6968adf5a1516d325374eb swagger/redhatopenshift/resource-manager/Microsoft.RedHatOpenShift/stable/2020-04-30/redhatopenshift.json | ||
| 87f91bafd1bbebd4e348bb754e197bd0bdf4c0b06debdb47c78e46eb8ddede5f swagger/redhatopenshift/resource-manager/Microsoft.RedHatOpenShift/preview/2021-09-01-preview/redhatopenshift.json | ||
| 749f87c84f68049c9da77f339e5aaae0e6ec86831992a31f6d6a5f997cced3ef swagger/redhatopenshift/resource-manager/Microsoft.RedHatOpenShift/preview/2021-09-01-preview/redhatopenshift.json |
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,29 @@ | ||
| package api | ||
|
|
||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the Apache License 2.0. | ||
|
|
||
| // SetDefaults sets the default values for older api version | ||
| // when interacting with newer api versions. This together with | ||
| // database migration will make sure we have right values in the cluster documents | ||
| // when moving between old and new versions | ||
| func SetDefaults(doc *OpenShiftClusterDocument) { | ||
| if doc.OpenShiftCluster != nil { | ||
| // SDNProvider was introduced in 2021-09-01-preview | ||
| if doc.OpenShiftCluster.Properties.NetworkProfile.SDNProvider == "" { | ||
| doc.OpenShiftCluster.Properties.NetworkProfile.SDNProvider = SDNProviderOpenShiftSDN | ||
| } | ||
|
|
||
| // EncryptionAtHost was introduced in 2021-09-01-preview. | ||
| // It can't be changed post cluster creation | ||
| if doc.OpenShiftCluster.Properties.MasterProfile.EncryptionAtHost == "" { | ||
| doc.OpenShiftCluster.Properties.MasterProfile.EncryptionAtHost = EncryptionAtHostDisabled | ||
| } | ||
|
|
||
| for i, wp := range doc.OpenShiftCluster.Properties.WorkerProfiles { | ||
| if wp.EncryptionAtHost == "" { | ||
| doc.OpenShiftCluster.Properties.WorkerProfiles[i].EncryptionAtHost = EncryptionAtHostDisabled | ||
| } | ||
| } | ||
| } | ||
| } |
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,100 @@ | ||
| package api | ||
|
|
||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the Apache License 2.0. | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "reflect" | ||
| "testing" | ||
| ) | ||
|
|
||
| func validOpenShiftClusterDocument() *OpenShiftClusterDocument { | ||
| doc := OpenShiftClusterDocument{ | ||
| OpenShiftCluster: &OpenShiftCluster{ | ||
| Properties: OpenShiftClusterProperties{ | ||
| NetworkProfile: NetworkProfile{ | ||
| SDNProvider: SDNProviderOpenShiftSDN, | ||
| }, | ||
| MasterProfile: MasterProfile{ | ||
| EncryptionAtHost: EncryptionAtHostDisabled, | ||
| }, | ||
| WorkerProfiles: []WorkerProfile{ | ||
| { | ||
| EncryptionAtHost: EncryptionAtHostDisabled, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| return &doc | ||
| } | ||
| func TestSetDefaults(t *testing.T) { | ||
| for _, tt := range []struct { | ||
| name string | ||
| want func() *OpenShiftClusterDocument | ||
| input func(doc *OpenShiftClusterDocument) | ||
| }{ | ||
| { | ||
| name: "no defaults needed", | ||
| want: func() *OpenShiftClusterDocument { | ||
| return validOpenShiftClusterDocument() | ||
| }, | ||
| }, | ||
| { | ||
| name: "default SDN", | ||
| want: func() *OpenShiftClusterDocument { | ||
| return validOpenShiftClusterDocument() | ||
| }, | ||
| input: func(base *OpenShiftClusterDocument) { | ||
| base.OpenShiftCluster.Properties.NetworkProfile.SDNProvider = "" | ||
| }, | ||
| }, | ||
| { | ||
| name: "preserve SDN", | ||
| want: func() *OpenShiftClusterDocument { | ||
| doc := validOpenShiftClusterDocument() | ||
| doc.OpenShiftCluster.Properties.NetworkProfile.SDNProvider = SDNProviderOVNKubernetes | ||
| return doc | ||
| }, | ||
| input: func(base *OpenShiftClusterDocument) { | ||
| base.OpenShiftCluster.Properties.NetworkProfile.SDNProvider = SDNProviderOVNKubernetes | ||
| }, | ||
| }, | ||
| { | ||
| name: "default encryption at host", | ||
| want: func() *OpenShiftClusterDocument { | ||
| return validOpenShiftClusterDocument() | ||
| }, | ||
| input: func(base *OpenShiftClusterDocument) { | ||
| base.OpenShiftCluster.Properties.MasterProfile.EncryptionAtHost = "" | ||
| }, | ||
| }, | ||
| { | ||
| name: "preserve encryption at host", | ||
| want: func() *OpenShiftClusterDocument { | ||
| doc := validOpenShiftClusterDocument() | ||
| doc.OpenShiftCluster.Properties.MasterProfile.EncryptionAtHost = EncryptionAtHostEnabled | ||
| return doc | ||
| }, | ||
| input: func(base *OpenShiftClusterDocument) { | ||
| base.OpenShiftCluster.Properties.MasterProfile.EncryptionAtHost = EncryptionAtHostEnabled | ||
| }, | ||
| }, | ||
| } { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| doc := validOpenShiftClusterDocument() | ||
| want := tt.want() | ||
| if tt.input != nil { | ||
| tt.input(doc) | ||
| } | ||
|
|
||
| SetDefaults(doc) | ||
|
|
||
| if !reflect.DeepEqual(&doc, &want) { | ||
| t.Error(fmt.Errorf("\n%+v\n !=\n%+v", doc, want)) // can't use cmp due to cycle imports | ||
| } | ||
| }) | ||
| } | ||
| } |
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
3 changes: 3 additions & 0 deletions
3
pkg/client/services/redhatopenshift/mgmt/2020-04-30/redhatopenshift/openshiftclusters.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
35 changes: 19 additions & 16 deletions
35
...ent/services/redhatopenshift/mgmt/2021-09-01-preview/redhatopenshift/openshiftclusters.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
.../redhatopenshift/mgmt/2021-09-01-preview/redhatopenshift/redhatopenshiftapi/interfaces.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package cluster | ||
|
|
||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the Apache License 2.0. | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/Azure/ARO-RP/pkg/api" | ||
| ) | ||
|
|
||
| // ensureDefaults will ensure cluster documents has all default values | ||
| // for new api versions | ||
| func (m *manager) ensureDefaults(ctx context.Context) error { | ||
| var err error | ||
| m.doc, err = m.db.PatchWithLease(ctx, m.doc.Key, func(doc *api.OpenShiftClusterDocument) error { | ||
| api.SetDefaults(doc) | ||
| return nil | ||
| }) | ||
| if err != nil { | ||
| m.log.Print(err) | ||
| return err | ||
| } | ||
| return nil | ||
| } |
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.
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.