generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 71
Logging Cleanup - Part 2 #413
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
2 commits
Select commit
Hold shift + click to select a range
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
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,64 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "encoding/gob" | ||
| "flag" | ||
| "fmt" | ||
| "os" | ||
| "path" | ||
| "reflect" | ||
|
|
||
| "github.com/golang/mock/mockgen/model" | ||
|
|
||
| pkg_ "github.com/aws/aws-application-networking-k8s/pkg/aws" | ||
| ) | ||
|
|
||
| var output = flag.String("output", "", "The output file name, or empty to use stdout.") | ||
|
|
||
| func main() { | ||
| flag.Parse() | ||
|
|
||
| its := []struct { | ||
| sym string | ||
| typ reflect.Type | ||
| }{ | ||
|
|
||
| {"Cloud", reflect.TypeOf((*pkg_.Cloud)(nil)).Elem()}, | ||
| } | ||
| pkg := &model.Package{ | ||
| // NOTE: This behaves contrary to documented behaviour if the | ||
| // package name is not the final component of the import path. | ||
| // The reflect package doesn't expose the package name, though. | ||
| Name: path.Base("github.com/aws/aws-application-networking-k8s/pkg/aws"), | ||
| } | ||
|
|
||
| for _, it := range its { | ||
| intf, err := model.InterfaceFromInterfaceType(it.typ) | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Reflection: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
| intf.Name = it.sym | ||
| pkg.Interfaces = append(pkg.Interfaces, intf) | ||
| } | ||
|
|
||
| outfile := os.Stdout | ||
| if len(*output) != 0 { | ||
| var err error | ||
| outfile, err = os.Create(*output) | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "failed to open output file %q", *output) | ||
| } | ||
| defer func() { | ||
| if err := outfile.Close(); err != nil { | ||
| fmt.Fprintf(os.Stderr, "failed to close output file %q", *output) | ||
| os.Exit(1) | ||
| } | ||
| }() | ||
| } | ||
|
|
||
| if err := gob.NewEncoder(outfile).Encode(pkg); err != nil { | ||
| fmt.Fprintf(os.Stderr, "gob encode: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
| } |
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,64 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "encoding/gob" | ||
| "flag" | ||
| "fmt" | ||
| "os" | ||
| "path" | ||
| "reflect" | ||
|
|
||
| "github.com/golang/mock/mockgen/model" | ||
|
|
||
| pkg_ "github.com/aws/aws-application-networking-k8s/pkg/aws" | ||
| ) | ||
|
|
||
| var output = flag.String("output", "", "The output file name, or empty to use stdout.") | ||
|
|
||
| func main() { | ||
| flag.Parse() | ||
|
|
||
| its := []struct { | ||
| sym string | ||
| typ reflect.Type | ||
| }{ | ||
|
|
||
| {"Cloud", reflect.TypeOf((*pkg_.Cloud)(nil)).Elem()}, | ||
| } | ||
| pkg := &model.Package{ | ||
| // NOTE: This behaves contrary to documented behaviour if the | ||
| // package name is not the final component of the import path. | ||
| // The reflect package doesn't expose the package name, though. | ||
| Name: path.Base("github.com/aws/aws-application-networking-k8s/pkg/aws"), | ||
| } | ||
|
|
||
| for _, it := range its { | ||
| intf, err := model.InterfaceFromInterfaceType(it.typ) | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Reflection: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
| intf.Name = it.sym | ||
| pkg.Interfaces = append(pkg.Interfaces, intf) | ||
| } | ||
|
|
||
| outfile := os.Stdout | ||
| if len(*output) != 0 { | ||
| var err error | ||
| outfile, err = os.Create(*output) | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "failed to open output file %q", *output) | ||
| } | ||
| defer func() { | ||
| if err := outfile.Close(); err != nil { | ||
| fmt.Fprintf(os.Stderr, "failed to close output file %q", *output) | ||
| os.Exit(1) | ||
| } | ||
| }() | ||
| } | ||
|
|
||
| if err := gob.NewEncoder(outfile).Encode(pkg); err != nil { | ||
| fmt.Fprintf(os.Stderr, "gob encode: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
| } |
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 |
|---|---|---|
|
|
@@ -4,28 +4,31 @@ import ( | |
| "context" | ||
| "reflect" | ||
|
|
||
| "github.com/aws/aws-application-networking-k8s/pkg/model/core" | ||
| latticemodel "github.com/aws/aws-application-networking-k8s/pkg/model/lattice" | ||
| "github.com/golang/glog" | ||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
| "k8s.io/apimachinery/pkg/api/meta" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
| "sigs.k8s.io/external-dns/endpoint" | ||
|
|
||
| "github.com/aws/aws-application-networking-k8s/pkg/model/core" | ||
| latticemodel "github.com/aws/aws-application-networking-k8s/pkg/model/lattice" | ||
| "github.com/aws/aws-application-networking-k8s/pkg/utils/gwlog" | ||
| ) | ||
|
|
||
| type DnsEndpointManager interface { | ||
| Create(ctx context.Context, service *latticemodel.Service) error | ||
| } | ||
|
|
||
| type defaultDnsEndpointManager struct { | ||
| log gwlog.Logger | ||
| k8sClient client.Client | ||
| } | ||
|
|
||
| func NewDnsEndpointManager(k8sClient client.Client) *defaultDnsEndpointManager { | ||
| func NewDnsEndpointManager(log gwlog.Logger, k8sClient client.Client) *defaultDnsEndpointManager { | ||
| return &defaultDnsEndpointManager{ | ||
| log: log, | ||
| k8sClient: k8sClient, | ||
| } | ||
| } | ||
|
|
@@ -36,11 +39,11 @@ func (s *defaultDnsEndpointManager) Create(ctx context.Context, service *lattice | |
| Name: service.Spec.Name + "-dns", | ||
| } | ||
| if service.Spec.CustomerDomainName == "" { | ||
| glog.V(2).Infof("Skipping creation of %s: detected no custom domain", namespacedName.String()) | ||
| s.log.Debugf("Skipping creation of %s: detected no custom domain", namespacedName.String()) | ||
|
Contributor
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. %s will use Stringer interface and call String(), no need to explicitly call String()
Member
Author
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. Thanks, will include this in part 3! |
||
| return nil | ||
| } | ||
| if service.Status == nil || service.Status.Dns == "" { | ||
| glog.V(2).Infof("Skipping creation of %s: DNS target not ready in svc status", namespacedName.String()) | ||
| s.log.Debugf("Skipping creation of %s: DNS target not ready in svc status", namespacedName.String()) | ||
| return nil | ||
| } | ||
|
|
||
|
|
@@ -58,14 +61,14 @@ func (s *defaultDnsEndpointManager) Create(ctx context.Context, service *lattice | |
| route, err = core.GetHTTPRoute(ctx, s.k8sClient, routeNamespacedName) | ||
| } | ||
| if err != nil { | ||
| glog.V(2).Infof("Skipping creation of %s: Could not find corresponding route", namespacedName.String()) | ||
| s.log.Debugf("Skipping creation of %s: Could not find corresponding route", namespacedName.String()) | ||
| return nil | ||
| } | ||
|
|
||
| ep := &endpoint.DNSEndpoint{} | ||
| if err := s.k8sClient.Get(ctx, namespacedName, ep); err != nil { | ||
| if apierrors.IsNotFound(err) { | ||
| glog.V(2).Infof("Attempting creation of DNSEndpoint for %s - %s -> %s", | ||
| s.log.Debugf("Attempting creation of DNSEndpoint for %s - %s -> %s", | ||
| namespacedName.String(), service.Spec.CustomerDomainName, service.Status.Dns) | ||
| ep = &endpoint.DNSEndpoint{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
|
|
@@ -87,18 +90,16 @@ func (s *defaultDnsEndpointManager) Create(ctx context.Context, service *lattice | |
| } | ||
| controllerutil.SetControllerReference(route.K8sObject(), ep, s.k8sClient.Scheme()) | ||
| if err = s.k8sClient.Create(ctx, ep); err != nil { | ||
| glog.V(2).Infof("Failed creating DNSEndpoint: %s", err.Error()) | ||
| return err | ||
| } | ||
| } else if meta.IsNoMatchError(err) { | ||
| glog.V(2).Infof("DNSEndpoint CRD not supported, skipping") | ||
| s.log.Debugf("DNSEndpoint CRD not supported, skipping") | ||
| return nil | ||
| } else { | ||
| glog.V(2).Infof("Failed lookup of DNSEndpoint: %s", err.Error()) | ||
| return err | ||
| } | ||
| } else { | ||
| glog.V(2).Infof("Attempting update of DNSEndpoint for %s - %s -> %s", | ||
| s.log.Debugf("Attempting update of DNSEndpoint for %s - %s -> %s", | ||
| namespacedName.String(), service.Spec.CustomerDomainName, service.Status.Dns) | ||
| old := ep.DeepCopy() | ||
| ep.Spec.Endpoints = []*endpoint.Endpoint{ | ||
|
|
@@ -113,7 +114,6 @@ func (s *defaultDnsEndpointManager) Create(ctx context.Context, service *lattice | |
| } | ||
| if !reflect.DeepEqual(ep.Spec.Endpoints, old.Spec.Endpoints) { | ||
| if err = s.k8sClient.Patch(ctx, ep, client.MergeFrom(old)); err != nil { | ||
| glog.V(2).Infof("Failed updating DNSEndpoint: %s", err.Error()) | ||
| return err | ||
| } | ||
| } | ||
|
|
||
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
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.
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.
Not entirely sure what generated these files, are we meant to add them to .gitignore?
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.
it seems code generation was interrupted and left temp files, you need to remove them