@@ -18,7 +18,6 @@ package agentpools
1818
1919import (
2020 "context"
21- "fmt"
2221
2322 "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2020-02-01/containerservice"
2423 "github.com/google/go-cmp/cmp"
@@ -42,16 +41,24 @@ type Spec struct {
4241func (s * Service ) Get (ctx context.Context , spec interface {}) (interface {}, error ) {
4342 agentPoolSpec , ok := spec .(* Spec )
4443 if ! ok {
45- return containerservice.AgentPool {}, errors .New ("expected agent pool specification" )
44+ return containerservice.AgentPool {}, errors .New ("invalid agent pool specification" )
4645 }
47- return s .Client .Get (ctx , agentPoolSpec .ResourceGroup , agentPoolSpec .Cluster , agentPoolSpec .Name )
46+
47+ agentPool , err := s .Client .Get (ctx , agentPoolSpec .ResourceGroup , agentPoolSpec .Cluster , agentPoolSpec .Name )
48+ if err != nil && azure .ResourceNotFound (err ) {
49+ return containerservice.AgentPool {}, errors .Wrapf (err , "agent pool %s not found" , agentPoolSpec .Name )
50+ } else if err != nil {
51+ return agentPool , err
52+ }
53+
54+ return agentPool , nil
4855}
4956
5057// Reconcile idempotently creates or updates a agent pool, if possible.
5158func (s * Service ) Reconcile (ctx context.Context , spec interface {}) error {
5259 agentPoolSpec , ok := spec .(* Spec )
5360 if ! ok {
54- return errors .New ("expected agent pool specification" )
61+ return errors .New ("invalid agent pool specification" )
5562 }
5663
5764 profile := containerservice.AgentPool {
@@ -77,7 +84,7 @@ func (s *Service) Reconcile(ctx context.Context, spec interface{}) error {
7784 if isCreate {
7885 err = s .Client .CreateOrUpdate (ctx , agentPoolSpec .ResourceGroup , agentPoolSpec .Cluster , agentPoolSpec .Name , profile )
7986 if err != nil {
80- return fmt . Errorf ( "failed to create or update agent pool, %#+v" , err )
87+ return errors . Wrap ( err , "failed to create or update agent pool" )
8188 }
8289 } else {
8390 existingPool , ok := existingSpec .(containerservice.AgentPool )
@@ -107,7 +114,7 @@ func (s *Service) Reconcile(ctx context.Context, spec interface{}) error {
107114 klog .V (2 ).Infof ("Update required (+new -old):\n %s" , diff )
108115 err = s .Client .CreateOrUpdate (ctx , agentPoolSpec .ResourceGroup , agentPoolSpec .Cluster , agentPoolSpec .Name , profile )
109116 if err != nil {
110- return fmt . Errorf ( "failed to create or update agent pool, %#+v" , err . Error () )
117+ return errors . Wrap ( err , "failed to create or update agent pool" )
111118 }
112119 } else {
113120 klog .V (2 ).Infof ("Normalized and desired agent pool matched, no update needed" )
@@ -121,7 +128,7 @@ func (s *Service) Reconcile(ctx context.Context, spec interface{}) error {
121128func (s * Service ) Delete (ctx context.Context , spec interface {}) error {
122129 agentPoolSpec , ok := spec .(* Spec )
123130 if ! ok {
124- return errors .New ("expected agent pool specification" )
131+ return errors .New ("invalid agent pool specification" )
125132 }
126133
127134 klog .V (2 ).Infof ("deleting agent pool %s " , agentPoolSpec .Name )
0 commit comments