-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Support multiple provider in separate containers. (#606)
Support dynamic selection of multiple providers in separate containers. closes #599 Summary by package: - /addon - add support for addons to fetch the _Addon_ using the binding through the addon (adapter) package. - add environment variables injector. replaces $(var) with values. - /api - addon - support changes in addon and extension CRs. - included (new) extensions in _Addon_ resource. - task - removed unused fields: variant, purged. - support new addon and extensions fields. - resolve k8s resources referenced by task: addon, extension, task, priority for validation and default priority. - taskgroup - support changes in task. - delegate CRUD (including cancel) to the task manager. This ensure: - tasks in flight are not updated by multiple threads. - delegates complexities on what can be updated when to the task manger. - /binding - add support for reading Get, List addons. - generated/crd - result of: (make generate && make manifests) - /k8s/api - - addon - updated to support dynamic addon selection. - task - added to support dynamic addon selection. - extension - added to support extensions with dynamic selection. - /migration/v13 - core.go updated. - Task.kind added. - Task.Extensions added. - Task.Attached added to support attached pod definition and container logs. - Task.Policy structured _TaskPolicy_. which includes preemption policies. Structured improved the api. - /model - ref migration v13. - /reaper - reap files attached to tasks. - report released event. - /settings - add hub setting for location of /shared (emptydir). - /task - support: - converted task models to use json serializer (while adding other json fields). - multi-container task pods which ensured extension container termination. - both static and dynamic addon seletion. - both static and dynamic extension selection. - task (kinds) - priority escalation based on _task-kind_ dependencies. Prevents priority inversions. - task preemption based on priority. - enhanced ordering based on _task-kind_ dependency. adds task Postponed rule. - attach pod.yaml (including events) and container logs to the task on pod completion. - support resource quota. - add environment variable injection _(mainly to support automatic port assignment for providers)._ - add ${seq:<pool>} macro _(mainly to support automatic port assignment for providers)._ - add task event reporting. - refactored the manager: - task state simplified: pending state removed (reported by event). - consolidate errors into error.go and add _soft_ error concept. - Manager.runReady() into separate methods for better decomposition. each loop through and acts on the list. - Manager.updateRunning() into separate methods for better functional decomposition. - fetch all k8s resources at once instead of hammering the api-server. --- json serialization: added a custom json (model) serializer. This was needed because we need the serializer to handle the map[any]any problem with binding yaml. Removed api/base.go/strMap() and moved it to the new serializer. Only being used by tasks. --- Added/Updated CRDs: - Addon (updated) - Extension - Task --------- Signed-off-by: Jeff Ortel <jortel@redhat.com>
- Loading branch information
Showing
44 changed files
with
6,992 additions
and
727 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package addon | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"regexp" | ||
"strings" | ||
|
||
"github.com/konveyor/tackle2-hub/api" | ||
"github.com/konveyor/tackle2-hub/task" | ||
) | ||
|
||
var ( | ||
EnvRegex = regexp.MustCompile(`(\$\()([^)]+)(\))`) | ||
) | ||
|
||
// EnvInjector inject key into extension metadata. | ||
type EnvInjector struct { | ||
env map[string]string | ||
dict map[string]string | ||
} | ||
|
||
// Inject inject into extension metadata. | ||
func (r *EnvInjector) Inject(extension *api.Extension) { | ||
r.buildEnv(extension) | ||
mp := make(map[string]any) | ||
b, _ := json.Marshal(extension.Metadata) | ||
_ = json.Unmarshal(b, &mp) | ||
mp = r.inject(mp).(map[string]any) | ||
extension.Metadata = mp | ||
} | ||
|
||
// buildEnv builds the extension `env`. | ||
func (r *EnvInjector) buildEnv(extension *api.Extension) { | ||
r.env = make(map[string]string) | ||
for _, env := range extension.Container.Env { | ||
key := task.ExtEnv(extension.Name, env.Name) | ||
r.env[env.Name] = os.Getenv(key) | ||
} | ||
} | ||
|
||
// inject replaces both `dict` keys and `env` environment | ||
// variables referenced in metadata. | ||
func (r *EnvInjector) inject(in any) (out any) { | ||
switch node := in.(type) { | ||
case map[string]any: | ||
for k, v := range node { | ||
node[k] = r.inject(v) | ||
} | ||
out = node | ||
case []any: | ||
var injected []any | ||
for _, n := range node { | ||
injected = append( | ||
injected, | ||
r.inject(n)) | ||
} | ||
out = injected | ||
case string: | ||
for { | ||
match := EnvRegex.FindStringSubmatch(node) | ||
if len(match) < 3 { | ||
break | ||
} | ||
node = strings.Replace( | ||
node, | ||
match[0], | ||
r.env[match[2]], | ||
-1) | ||
} | ||
out = node | ||
default: | ||
out = node | ||
} | ||
return | ||
} |
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
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
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
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
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
Oops, something went wrong.