Skip to content

Conversation

@pcanilho
Copy link
Contributor

@pcanilho pcanilho commented Aug 21, 2024

Proposal[WIP]: Optional ref struct field tag allowing JIT lookup of values from Kubernetes object references

Important

This system will be automatically deactivated if a connection with an existing Kubernetes cluster cannot be established.

The ref tag is designed to be made available in an optional format to provider instances. When an instance struct field has been annotated with the ref tag, the system will attempt to execute the following steps during boot:

  1. Parse the ref tag value. Its format is expected to be <objectRefName>:<dataKey>.
  2. Attempt to fetch the parsed objectRefName by querying the currently connected Kubernetes cluster for an object which its name reference matches.
  3. Upon finding an existing valid object, the dataKey is then used to extract the sub-value from the objects data field.
  4. If the existing struct field value has been left unset or is equal to Go's Zero value, its value is replaced by the one found in the step above.

Note

The ref tag lookup mechanism currently only supports fetching data values from ConfigMaps but support for other
objects has been left open.

Goals

  • Backwards compatible.
  • Added per-struct field support to fetch runtime inputs from kubernetes object references when left unset.
  • Tests TODO(@pcanilho)

A simple example

type TCP struct {
	Name    string        `mapstructure:"name" ref:"tcpRef:name"`
	Host    string        `mapstructure:"host" ref:"tcpRef:host"`
	Port    int           `mapstructure:"port" default:"80"`
	Closed  bool          `mapstructure:"closed" default:"false"`
	Timeout time.Duration `mapstructure:"timeout" default:"1s"`
}

Note the usage of the ref tag.

Tests

TODO(@pcanilho)

…eld tag allowing JIT Kubernetes object lookup
@pcanilho pcanilho force-pushed the feature/ref-struct-field-tag branch from 30afc85 to 7cdd9b5 Compare August 22, 2024 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant