Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
update version and make sure index out of range error does not happen
Browse files Browse the repository at this point in the history
  • Loading branch information
Skarlso committed Dec 1, 2023
1 parent 987c015 commit ca00295
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
26 changes: 16 additions & 10 deletions internal/componentsgen/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ func (o *Controller) GenerateManifests(ctx context.Context, tmpDir string) error
}

if o.Name == env.ReplicationControllerName {
if err := o.enableMpasForReplicationController(); err != nil {
var err error
content, err = o.enableMpasForReplicationController(content)
if err != nil {
return fmt.Errorf("failed to update replication controller: %w", err)
}

fmt.Println("content: ", string(content))
}

o.Path = filepath.Join(o.Name, "install.yaml")
Expand All @@ -83,6 +87,10 @@ func (o *Controller) GenerateLocalizationFromTemplate(tmpl, loc string) (string,
func (o *Controller) GenerateImages() (map[string][]string, error) {
var images = make(map[string][]string)
index := strings.Index(o.Content, fmt.Sprintf("%s/%s", o.Registry, o.Name))
if index < 0 {
return nil, fmt.Errorf("failed to find registry and name in content")
}

var image string
for i := index; i < len(o.Content); i++ {
v := string((o.Content)[i])
Expand Down Expand Up @@ -110,28 +118,26 @@ func (o *Controller) GetPath() string {
return o.Path
}

func (o *Controller) enableMpasForReplicationController() (err error) {
func (o *Controller) enableMpasForReplicationController(content []byte) ([]byte, error) {
fs := filesys.MakeFsInMemory()
if err := fs.WriteFile("kustomization.yaml", replicationControllerPatch); err != nil {
return fmt.Errorf("failed to create kustomization file: %w", err)
return nil, fmt.Errorf("failed to create kustomization file: %w", err)
}

if err := fs.WriteFile("install.yaml", []byte(o.Content)); err != nil {
return fmt.Errorf("failed to create install file: %w", err)
if err := fs.WriteFile("install.yaml", content); err != nil {
return nil, fmt.Errorf("failed to create install file: %w", err)
}

kustomizer := krusty.MakeKustomizer(krusty.MakeDefaultOptions())
result, err := kustomizer.Run(fs, ".")
if err != nil {
return fmt.Errorf("failed to run kustomize for controller %s: %w", o.Name, err)
return nil, fmt.Errorf("failed to run kustomize for controller %s: %w", o.Name, err)
}

asYaml, err := result.AsYaml()
if err != nil {
return fmt.Errorf("failed to create yaml from kustomize result: %w", err)
return nil, fmt.Errorf("failed to create yaml from kustomize result: %w", err)
}

o.Content = string(asYaml)

return nil
return asYaml, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ patchesStrategicMerge:
- |-
apiVersion: apps/v1
kind: Deployment
metadata:
metadata:
name: replication-controller
namespace: ocm-system
spec:
template:
spec:
containers:
- name: manager
image: ghcr.io/open-component-model/replication-controller:latest
args:
- --mpas-enabled
- --leader-elect
Expand Down
2 changes: 1 addition & 1 deletion internal/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
// DefaultGitControllerVer is the default version of the git-controller component.
DefaultGitControllerVer = "v0.10.1"
// DefaultReplicationVer is the default version of the replication-controller component.
DefaultReplicationVer = "v0.10.0"
DefaultReplicationVer = "v0.11.0"
// DefaultMpasProductControllerVer is the default version of the mpas-product-controller component.
DefaultMpasProductControllerVer = "v0.8.0"
// DefaultMpasProjectControllerVer is the default version of the mpas-project-controller component.
Expand Down

0 comments on commit ca00295

Please sign in to comment.