Created
March 9, 2021 19:09
-
-
Save iamkirkbater/be03f592e62748d2f11c9e65c3be0c7b to your computer and use it in GitHub Desktop.
This file contains 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
type ReconcileAccount struct { | |
Client kubeclient.Client | |
scheme *runtime.Scheme | |
OperatorAWSClient awsclient.Client | |
AccountAWSClient awsclient.Client | |
Account awsv1alpha1.Account | |
LinkedAccountClaim awsv1alpha1.AccountClaim | |
Logger LogInterface | |
} | |
func (r *ReconcileAccount) getAccountClaim() (awsv1alpha1.AccountClaim, error) { | |
emptyAccountClaim := &awsv1alpha1.AccountClaim{} | |
if r.AccountClaim == emptyAccountClaim { | |
err := r.Client.Get(context.TODO(), request.NamespacedName, r.AccountClaim) | |
} | |
return r.AccountClaim | |
} | |
func (r *ReconcileAccount) Reconcile(request reconcile.Request) (reconcile.Result, error) { | |
r.Logger := log.WithValues("Controller", controllerName, "Request.Namespace", request.Namespace, "Request.Name", request.Name) | |
r.Account := &awsv1alpha1.Account{} | |
err := r.Client.Get(context.TODO(), request.NamespacedName, r.Account) | |
// so on and so forth | |
// eventually get to a point where you need the accountClaim (because there's no point in greedy | |
// filling all the data and requesting everything at the beginning, we still only request it where needed | |
accountClaim, err := r.getAccountClaim() | |
// do something with accountClaim | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After testing this quickly, this will not work as intended. The
ReconcileAccount
struct will persist through reconciles, and whatever values you added will be added there and mess with subsequent objects being reconciled.