Absa Go package library
package controller extends sigs.k8s.io/controller-runtime os.Getenv.
Package contains ReconcileResult
which provides abstraction over reconciliation loop management.
const reconcileSeconds = 10
result := utils.NewReconcileResult(time.Duration(reconcileSeconds) * time.Second)
...
func (r *MyReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
...
if finish {
// sucesfuly stop reconciliation loop
return result.Stop()
}
if err := doSomething(); err != nil {
// requeue loop immediately with error
return result.RequeueError(err)
}
// requeue loop after reconcileSeconds
return result.Requeue()
}
DNS contains helper functions related to DNS.
Package currently contains Dig function retrieving slice of tuples <IP address, A record > for specific FQDN.
edgeDNSServer := "8.8.8.8"
fqdn := "google.com"
result, err := Dig(edgeDNSServer, fqdn)
Environment variable helper extending standard os.Getenv.
Package contains several functions which returns the typed env variable for the given key and falls back to the default value if not set.
noProxy := env.GetEnvAsStringOrFallback("NO_PROXY", "*.foo.bar.com")
runOnStart := env.GetEnvAsStringOrFallback("RUN_ON_START", true)
Package k8s provides extensions for k8s apimachinery/pkg/apis
Package contains following functions:
MergeAnnotations(target *metav1.ObjectMeta, source *metav1.ObjectMeta)
adds or updates annotations from defaultSource to defaultTargetContainsAnnotations(target *metav1.ObjectMeta, source *metav1.ObjectMeta) bool
checks if defaultTarget contains all annotations of defaultSource Any kubernetes resource having ObjectMeta can be passed.
if !k8s.ContainsAnnotations(currentIngress.ObjectMeta, expectedIngress.ObjectMeta) {
MergeAnnotations(currentIngress.ObjectMeta, expectedIngress.ObjectMeta)
}
Shell command runner
Package shell is used for running executables and returns command output for further processing. It is a synchronized wrapper around the standard Go command package, which allows you to define environment variables in a native way and returns the output as a return value.
cmd := shell.Command{
Command: "sh",
Args: []string{"-c", "terraform apply -auto-approve tfplan"},
Env: map[string]string{"name":"test"},
}
o, _ = shell.Execute(cmd)
Package string provide helper functions related to string
Package string contains extensions of standard strings and formatting functions:
ToString(v interface{}) string
ToString converts type to formatted string. If value is struct, function returns formatted JSON.
log.Debug().Msgf("current config: %s",utils.ToString(config))