-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Allow for normalizing any fields of desired endpoint #1849
Changes from all commits
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 |
---|---|---|
|
@@ -19,6 +19,7 @@ package endpoint | |
import ( | ||
"fmt" | ||
"sort" | ||
"strconv" | ||
"strings" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
@@ -191,10 +192,52 @@ func (e *Endpoint) GetProviderSpecificProperty(key string) (ProviderSpecificProp | |
return ProviderSpecificProperty{}, false | ||
} | ||
|
||
type NormalizeProviderSpecificConfig map[string]func(string) string | ||
|
||
// Selects and normalizes fields specified by config | ||
func (e *Endpoint) NormalizeProviderSpecific(config NormalizeProviderSpecificConfig) { | ||
normalized := ProviderSpecific{} | ||
Comment on lines
+197
to
+199
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. I don't understand the naming decision: "normalize" doesn't really tell me much of what is happening. Also, "Normalization" is a super overloaded world in IT, so I would try to use something that specifies the actual thing that we are doing. 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. Could you suggest something? 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. btw. this is normalizing, an idempotent action of taking config and returning standard version of it (e.g. setting defaults and converting boolean properties to normalized form) |
||
|
||
for name, normalize := range config { | ||
if property, ok := e.GetProviderSpecificProperty(name); ok { | ||
normalized = append(normalized, ProviderSpecificProperty{ | ||
Name: name, | ||
Value: normalize(property.Value), | ||
}) | ||
} else { | ||
normalized = append(normalized, ProviderSpecificProperty{ | ||
Name: name, | ||
Value: normalize(""), | ||
}) | ||
} | ||
} | ||
|
||
e.ProviderSpecific = normalized | ||
} | ||
|
||
func (e *Endpoint) String() string { | ||
return fmt.Sprintf("%s %d IN %s %s %s %s", e.DNSName, e.RecordTTL, e.RecordType, e.SetIdentifier, e.Targets, e.ProviderSpecific) | ||
} | ||
|
||
// Normalizes boolean value of custom property | ||
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. Same observation as above on code comment. |
||
func NormalizeBoolean(value string, defaultValue bool) string { | ||
val, err := strconv.ParseBool(value) | ||
|
||
if err != nil { | ||
if defaultValue { | ||
return "true" | ||
} else { | ||
return "false" | ||
} | ||
} | ||
|
||
if val { | ||
return "true" | ||
} | ||
|
||
return "false" | ||
} | ||
|
||
Comment on lines
+222
to
+240
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. Why do we need this to be part of 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. where would you put it? 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. Custom annotations have format map[string]string. Result type must be string, it's the point of this function :) |
||
// DNSEndpointSpec defines the desired state of DNSEndpoint | ||
type DNSEndpointSpec struct { | ||
Endpoints []*Endpoint `json:"endpoints,omitempty"` | ||
|
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.
Please always try to respect the godoc convention. This should start with
NormalizeProviderSpecific
and describe what the method is actually doing.