Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Ortel <[email protected]>
  • Loading branch information
jortel committed Mar 25, 2024
1 parent bda2a60 commit 34b808d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion addon/injector.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (e *UnknownInjector) Is(err error) (matched bool) {
return
}

// UnknownField used to report an unknown injector.
// UnknownField used to report an unknown resource field..
type UnknownField struct {
Kind string
Field string
Expand All @@ -48,10 +48,12 @@ func (e *UnknownField) Is(err error) (matched bool) {
return
}

// ResourceInjector supports hub resource injection.
type ResourceInjector struct {
dict map[string]string
}

// Build returns the built resource dictionary.
func (r *ResourceInjector) Build(task *Task, extension *api.Extension) (dict map[string]string, err error) {
richClient := task.richClient
r.dict = make(map[string]string)
Expand Down Expand Up @@ -84,6 +86,7 @@ func (r *ResourceInjector) Build(task *Task, extension *api.Extension) (dict map
return
}

// add the resource fields specified in the injector.
func (r *ResourceInjector) add(injector *crd.Injector, object any) (err error) {
objectMap := r.objectMap(object)
for _, f := range injector.Fields {
Expand All @@ -105,6 +108,7 @@ func (r *ResourceInjector) add(injector *crd.Injector, object any) (err error) {
return
}

// write a resource field value to a file.
func (r *ResourceInjector) write(path string, s string) (err error) {
f, err := os.Create(path)
if err == nil {
Expand All @@ -114,13 +118,15 @@ func (r *ResourceInjector) write(path string, s string) (err error) {
return
}

// string returns a string representation of a field value.
func (r *ResourceInjector) string(object any) (s string) {
if object != nil {
s = fmt.Sprintf("%v", object)
}
return
}

// objectMap returns a map for a resource object.
func (r *ResourceInjector) objectMap(object any) (mp map[string]any) {
b, _ := json.Marshal(object)
mp = make(map[string]any)
Expand All @@ -144,6 +150,9 @@ func (r *MetaInjector) Inject(extension *api.Extension) {
extension.Metadata = mp
}

// buildEnv builds the `env`.
// Maps EXTENSION_<extension>_<envar> found in the addon environment to its
// original unqualified name in the extension environment.
func (r *MetaInjector) buildEnv(extension *api.Extension) {
r.env = make(map[string]string)
for _, env := range extension.Container.Env {
Expand All @@ -158,6 +167,8 @@ func (r *MetaInjector) buildEnv(extension *api.Extension) {
}
}

// inject replaces both `dict` keys and `env` environment
// variables referenced in metadata.
func (r *MetaInjector) inject(in any) (out any) {
switch node := in.(type) {
case map[string]any:
Expand Down

0 comments on commit 34b808d

Please sign in to comment.