Skip to content
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

dnsprovider staticcheck #8233

Merged
merged 1 commit into from
Dec 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dnsprovider/pkg/dnsprovider/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func InitDnsProvider(name string, configFilePath string) (Interface, error) {
var config *os.File
config, err = os.Open(configFilePath)
if err != nil {
return nil, fmt.Errorf("Couldn't open DNS provider configuration %s: %#v", configFilePath, err)
return nil, fmt.Errorf("couldn't open DNS provider configuration %s: %#v", configFilePath, err)
}

defer config.Close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ func (r *Route53APIStub) ChangeResourceRecordSets(input *route53.ChangeResourceR
switch *change.Action {
case route53.ChangeActionCreate:
if _, found := recordSets[key]; found {
return nil, fmt.Errorf("Attempt to create duplicate rrset %s", key) // TODO: Return AWS errors with codes etc
return nil, fmt.Errorf("attempt to create duplicate rrset %s", key) // TODO: Return AWS errors with codes etc
}
recordSets[key] = append(recordSets[key], change.ResourceRecordSet)
case route53.ChangeActionDelete:
if _, found := recordSets[key]; !found {
return nil, fmt.Errorf("Attempt to delete non-existent rrset %s", key) // TODO: Check other fields too
return nil, fmt.Errorf("attempt to delete non-existent rrset %s", key) // TODO: Check other fields too
}
delete(recordSets, key)
case route53.ChangeActionUpsert:
Expand All @@ -110,7 +110,7 @@ func (r *Route53APIStub) CreateHostedZone(input *route53.CreateHostedZoneInput)
name := aws.StringValue(input.Name)
id := "/hostedzone/" + name
if _, ok := r.zones[id]; ok {
return nil, fmt.Errorf("Error creating hosted DNS zone: %s already exists", id)
return nil, fmt.Errorf("error creating hosted DNS zone: %s already exists", id)
}
r.zones[id] = &route53.HostedZone{
Id: aws.String(id),
Expand All @@ -121,10 +121,10 @@ func (r *Route53APIStub) CreateHostedZone(input *route53.CreateHostedZoneInput)

func (r *Route53APIStub) DeleteHostedZone(input *route53.DeleteHostedZoneInput) (*route53.DeleteHostedZoneOutput, error) {
if _, ok := r.zones[*input.Id]; !ok {
return nil, fmt.Errorf("Error deleting hosted DNS zone: %s does not exist", *input.Id)
return nil, fmt.Errorf("error deleting hosted DNS zone: %s does not exist", *input.Id)
}
if len(r.recordSets[*input.Id]) > 0 {
return nil, fmt.Errorf("Error deleting hosted DNS zone: %s has resource records", *input.Id)
return nil, fmt.Errorf("error deleting hosted DNS zone: %s has resource records", *input.Id)
}
delete(r.zones, *input.Id)
return &route53.DeleteHostedZoneOutput{}, nil
Expand Down
4 changes: 2 additions & 2 deletions dnsprovider/pkg/dnsprovider/providers/coredns/coredns.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func newCoreDNSProviderInterface(config io.Reader) (*Interface, error) {
klog.Infof("Using CoreDNS DNS provider")

if dnsZones == "" {
return nil, fmt.Errorf("Need to provide at least one DNS Zone")
return nil, fmt.Errorf("need to provide at least one DNS Zone")
}

etcdCfg := etcdc.Config{
Expand All @@ -78,7 +78,7 @@ func newCoreDNSProviderInterface(config io.Reader) (*Interface, error) {

c, err := etcdc.New(etcdCfg)
if err != nil {
return nil, fmt.Errorf("Create etcd client from the config failed")
return nil, fmt.Errorf("create etcd client from the config failed")
}
etcdKeysAPI := etcdc.NewKeysAPI(c)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (c *ResourceRecordChangeset) Apply() error {
if checkNotExists {
response, err := c.zone.zones.intf.etcdKeysAPI.Get(ctx, dnsmsg.Path(recordKey, etcdPathPrefix), getOpts)
if err == nil && response != nil {
return fmt.Errorf("Key already exist, key: %v", recordKey)
return fmt.Errorf("key already exist, key: %v", recordKey)
}
}

Expand Down
4 changes: 2 additions & 2 deletions dnsprovider/pkg/dnsprovider/providers/coredns/rrsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (rrsets ResourceRecordSets) Get(name string) ([]dnsprovider.ResourceRecordS
klog.V(2).Infof("Subdomain %q does not exist", name)
return nil, nil
}
return nil, fmt.Errorf("Failed to get service from etcd, err: %v", err)
return nil, fmt.Errorf("failed to get service from etcd, err: %v", err)
}
if emptyResponse(response) {
klog.V(2).Infof("Subdomain %q does not exist in etcd", name)
Expand All @@ -65,7 +65,7 @@ func (rrsets ResourceRecordSets) Get(name string) ([]dnsprovider.ResourceRecordS
service := dnsmsg.Service{}
err = json.Unmarshal([]byte(node.Value), &service)
if err != nil {
return nil, fmt.Errorf("Failed to unmarshall json data, err: %v", err)
return nil, fmt.Errorf("failed to unmarshall json data, err: %v", err)
}

rrset := ResourceRecordSet{name: name, rrdatas: []string{}, rrsets: &rrsets}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ func (c ChangesCreateCall) Do(opts ...googleapi.CallOption) (interfaces.Change,
}
for _, del := range c.Change.Deletions() {
if _, found := rrsets[hashKey(del)]; !found {
return nil, fmt.Errorf("Attempt to delete non-existent rrset %v", del)
return nil, fmt.Errorf("attempt to delete non-existent rrset %v", del)
}
delete(rrsets, hashKey(del))
}
for _, add := range c.Change.Additions() {
if _, found := rrsets[hashKey(add)]; found {
return nil, fmt.Errorf("Attempt to insert duplicate rrset %v", add)
return nil, fmt.Errorf("attempt to insert duplicate rrset %v", add)
}
rrsets[hashKey(add)] = add.(ResourceRecordSet)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (call ManagedZonesCreateCall) Do(opts ...googleapi.CallOption) (interfaces.
return nil, *call.Error
}
if call.Service.Impl[call.Project][call.ManagedZone.DnsName()] != nil {
return nil, fmt.Errorf("Error - attempt to create duplicate zone %s in project %s.",
return nil, fmt.Errorf("error - attempt to create duplicate zone %s in project %s",
call.ManagedZone.DnsName(), call.Project)
}
if call.Service.Impl == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (call ManagedZonesDeleteCall) Do(opts ...googleapi.CallOption) error {
delete(project, zone.Name())
return nil
}
return fmt.Errorf("Failed to find zone %s in project %s to delete it", call.ZoneName, call.Project)
return fmt.Errorf("failed to find zone %s in project %s to delete it", call.ZoneName, call.Project)
}
return fmt.Errorf("Failed to find project %s to delete zone %s from it", call.Project, call.ZoneName)
return fmt.Errorf("failed to find project %s to delete zone %s from it", call.Project, call.ZoneName)
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (call *ManagedZonesListCall) Do(opts ...googleapi.CallOption) (interfaces.M
}
proj, projectFound := call.Service.Impl[call.Project]
if !projectFound {
return nil, fmt.Errorf("Project %s not found.", call.Project)
return nil, fmt.Errorf("project %s not found", call.Project)
}
if call.DnsName_ != "" {
return &ManagedZonesListResponse{[]interfaces.ManagedZone{proj[call.DnsName_]}}, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s ResourceRecordSetsService) managedZone(project, managedZone string) (*Ma
}
z := s.Service.ManagedZones_.Impl[project][managedZone]
if z == nil {
return nil, fmt.Errorf("Zone %s not found in project %s", managedZone, project)
return nil, fmt.Errorf("zone %s not found in project %s", managedZone, project)
}
return z.(*ManagedZone), nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ func (c *ResourceRecordChangeset) Apply() error {
}
newAdditions := newChange.Additions()
if len(newAdditions) != len(additions) {
return fmt.Errorf("Internal error when adding resource record set. Call succeeded but number of records returned is incorrect. Records sent=%d, records returned=%d, additions:%v", len(additions), len(newAdditions), c.additions)
return fmt.Errorf("internal error when adding resource record set. Call succeeded but number of records returned is incorrect. Records sent=%d, records returned=%d, additions:%v", len(additions), len(newAdditions), c.additions)
}
newDeletions := newChange.Deletions()
if len(newDeletions) != len(deletions) {
return fmt.Errorf("Internal error when deleting resource record set. Call succeeded but number of records returned is incorrect. Records sent=%d, records returned=%d, deletions:%v", len(deletions), len(newDeletions), c.removals)
return fmt.Errorf("internal error when deleting resource record set. Call succeeded but number of records returned is incorrect. Records sent=%d, records returned=%d, deletions:%v", len(deletions), len(newDeletions), c.removals)
}

return nil
Expand Down