Skip to content

wantedly/resource-refresher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

resource-refresher

resource-refresher makes it easy to handle resources with parent-child relationships.

How to use

Let's consider the process of creating a child resource from a parent resource.

    // some process to create child resource 
    
	if _, err := controllerutil.CreateOrUpdate(context.TODO(), r.Client, copiedDeploy, func() error {
		copiedDeploy.Labels = child.labels
		copiedDeploy.Annotations = child.annotations
		copiedDeploy.Spec = child.spec

		// In order to support Update, set controller reference here
		return controllerutil.SetControllerReference(instance, copiedDeploy, r.Scheme)
	}); err != nil {
		return ctrl.Result{}, errors.WithStack(err)
	}

In this case, it is tedious to calculate the difference between the existing resources in Reconciler.

The resource-refresher will fill in the cluster and differences if you pass it the ideal resource state.

	ref := refresh.New(r.client, r.scheme)
    if err := ref.Refresh(ctx, &parent, &child); err != nil {
        return errors.WithStack(err)
    }
}

Read more about the architecture using resource-refresher: Go design theory learned from Kubernetes (in Japanese)

Installation

Run go get github.com/wantedly.com/resource-refresher and import like

import (
    refresh "github.com/wantedly/resource-refresher"
)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages