forked from openshift/machine-config-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch from using hardcoded extensions to reading extensions.json
Per issue 2445: openshift#2445 Added extensions.json parsing and propagated a few errors since now extension processing can fail. Added a test for extensions.json parsing and filtering. I don't know that I like this. If I understand the workflow right, this feels like something that should maybe be done as part of a validation step when extract the image so we only have to do it once and can check the extensions against the container labels. The package doesn't really "keep state" though (well, aside from the filesystem), it just extracts the image where it's told so this would require additional team conversations.
- Loading branch information
jkyros
committed
Mar 15, 2021
1 parent
82868e6
commit 3a85532
Showing
3 changed files
with
163 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package daemon | ||
|
||
import "io" | ||
import "io/ioutil" | ||
import "fmt" | ||
import "encoding/json" | ||
|
||
type SupportedExtensions struct { | ||
Extensions map[string]Extension `json:"extensions"` | ||
Repos []string `json:"repos"` | ||
} | ||
|
||
type Extension struct { | ||
Packages []string `json:"packages"` | ||
Architectures []string `json:"architectures,omitEmpty"` | ||
Kind string `json:"kind"` | ||
} | ||
|
||
func parseSupportedExtensions(extensionsFile io.Reader) (map[string][]string, error) { | ||
|
||
if rawExtensions, err := ioutil.ReadAll(extensionsFile); err != nil { | ||
return nil, fmt.Errorf("failed to read extensions file %s : %s", extensionsFile, err) | ||
} else { | ||
var supportedExtensions *SupportedExtensions | ||
|
||
|
||
if err := json.Unmarshal(rawExtensions, &supportedExtensions); err != nil { | ||
return nil, fmt.Errorf("failed to unmarshal extensions file %s : %s", extensionsFile, err) | ||
} | ||
|
||
//https://github.com/openshift/machine-config-operator/issues/2445 | ||
//mco should only pay attention to the the os-extension kind | ||
var extmap = make(map[string][]string) | ||
for extkey, ext := range supportedExtensions.Extensions { | ||
if ext.Kind == "os-extension" { | ||
extmap[extkey] = supportedExtensions.Extensions[extkey].Packages | ||
} | ||
} | ||
|
||
|
||
return extmap, nil | ||
} | ||
} | ||
|
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