forked from openshift/machine-api-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add vsphere-component annotation to CredentialsRequest CR (story #39) #4
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
splatypus-bot
wants to merge
2
commits into
master
Choose a base branch
from
story-39-vsphere-component-annotation
base: master
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.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| package manifest_test | ||
|
|
||
| import ( | ||
| "os" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "gopkg.in/yaml.v3" | ||
| ) | ||
|
|
||
| const vsphereComponentAnnotation = "cloudcredential.openshift.io/vsphere-component" | ||
|
|
||
| type credentialsRequest struct { | ||
| Kind string `yaml:"kind"` | ||
| Metadata struct { | ||
| Name string `yaml:"name"` | ||
| Annotations map[string]string `yaml:"annotations"` | ||
| } `yaml:"metadata"` | ||
| } | ||
|
|
||
| func parseCredentialsRequests(t *testing.T, path string) []credentialsRequest { | ||
| t.Helper() | ||
| data, err := os.ReadFile(path) | ||
| if err != nil { | ||
| t.Fatalf("read %s: %v", path, err) | ||
| } | ||
| var out []credentialsRequest | ||
| for _, doc := range strings.Split(string(data), "\n---") { | ||
| doc = strings.TrimSpace(doc) | ||
| if doc == "" { | ||
| continue | ||
| } | ||
| var cr credentialsRequest | ||
| if err := yaml.Unmarshal([]byte(doc), &cr); err != nil { | ||
| t.Fatalf("unmarshal %s: %v", path, err) | ||
| } | ||
| if cr.Kind == "CredentialsRequest" { | ||
| out = append(out, cr) | ||
| } | ||
| } | ||
| return out | ||
| } | ||
|
|
||
| func findCR(crs []credentialsRequest, name string) (credentialsRequest, bool) { | ||
| for _, cr := range crs { | ||
| if cr.Metadata.Name == name { | ||
| return cr, true | ||
| } | ||
| } | ||
| return credentialsRequest{}, false | ||
| } | ||
|
|
||
| func TestMAOVSphereCredentialsRequestAnnotation(t *testing.T) { | ||
| path := "../../install/0000_30_machine-api-operator_00_credentials-request.yaml" | ||
| crs := parseCredentialsRequests(t, path) | ||
|
|
||
| cr, ok := findCR(crs, "openshift-machine-api-vsphere") | ||
| if !ok { | ||
| t.Fatal("CredentialsRequest 'openshift-machine-api-vsphere' not found in manifest") | ||
| } | ||
|
|
||
| got, present := cr.Metadata.Annotations[vsphereComponentAnnotation] | ||
| if !present { | ||
| t.Fatalf("annotation %q missing from openshift-machine-api-vsphere", vsphereComponentAnnotation) | ||
| } | ||
| if got != "machineAPI" { | ||
| t.Errorf("annotation value: got %q, want %q", got, "machineAPI") | ||
| } | ||
| } | ||
|
|
||
| func TestNonVSphereCredentialsRequestsUnmodified(t *testing.T) { | ||
| path := "../../install/0000_30_machine-api-operator_00_credentials-request.yaml" | ||
| crs := parseCredentialsRequests(t, path) | ||
|
|
||
| nonVSphere := []string{ | ||
| "openshift-machine-api-aws", | ||
| "openshift-machine-api-azure", | ||
| "openshift-machine-api-gcp", | ||
| "openshift-machine-api-openstack", | ||
| } | ||
| for _, name := range nonVSphere { | ||
| cr, ok := findCR(crs, name) | ||
| if !ok { | ||
| t.Fatalf("expected non-vsphere CredentialsRequest %q not found in manifest; file may have been renamed or removed", name) | ||
| } | ||
| if _, present := cr.Metadata.Annotations[vsphereComponentAnnotation]; present { | ||
| t.Errorf("non-vsphere CR %q must NOT carry %s", name, vsphereComponentAnnotation) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestAnnotationValueIsNotEmpty(t *testing.T) { | ||
| path := "../../install/0000_30_machine-api-operator_00_credentials-request.yaml" | ||
| crs := parseCredentialsRequests(t, path) | ||
|
|
||
| cr, ok := findCR(crs, "openshift-machine-api-vsphere") | ||
| if !ok { | ||
| t.Fatal("CredentialsRequest 'openshift-machine-api-vsphere' not found in manifest") | ||
| } | ||
| val := cr.Metadata.Annotations[vsphereComponentAnnotation] | ||
| if strings.TrimSpace(val) == "" { | ||
| t.Errorf("annotation %q must not be empty", vsphereComponentAnnotation) | ||
| } | ||
| } | ||
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.