Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Application versions #240

Merged
merged 9 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions assets/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -5013,6 +5013,32 @@
}
}
},
"repositoryApplicationVersions": {
"type": "object",
"properties": {
"appVersion": {
"type": "string",
"title": "Application version presented by single value"
},
"dependencies": {
"$ref": "#/definitions/repositoryDependencies"
}
}
},
"repositoryDependencies": {
"type": "object",
"properties": {
"deps": {
"type": "string"
},
"lock": {
"type": "string"
},
"requirements": {
"type": "string"
}
}
},
"repositoryDirectoryAppSpec": {
"type": "object",
"title": "DirectoryAppSpec contains directory"
Expand Down Expand Up @@ -5113,6 +5139,9 @@
"repositoryManifestResponse": {
"type": "object",
"properties": {
"applicationVersions": {
"$ref": "#/definitions/repositoryApplicationVersions"
},
"commitAuthor": {
"type": "string"
},
Expand Down
3 changes: 3 additions & 0 deletions controller/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ func (m *appStateManager) getRepoObjs(app *v1alpha1.Application, sources []v1alp

ts.AddCheckpoint("version_ms")
log.Debugf("Generating Manifest for source %s revision %s", source, revisions[i])

// versionConfig :=
andrii-codefresh marked this conversation as resolved.
Show resolved Hide resolved
manifestInfo, err := repoClient.GenerateManifest(context.Background(), &apiclient.ManifestRequest{
Repo: repo,
Repos: permittedHelmRepos,
Expand All @@ -200,6 +202,7 @@ func (m *appStateManager) getRepoObjs(app *v1alpha1.Application, sources []v1alp
HelmOptions: helmOptions,
HasMultipleSources: app.Spec.HasMultipleSources(),
RefSources: refSources,
VersionConfig: apiclient.GetVersionConfig(),
})
if err != nil {
return nil, nil, fmt.Errorf("failed to generate manifest for source %d of %d: %w", i+1, len(sources), err)
Expand Down
721 changes: 659 additions & 62 deletions pkg/apiclient/events/events.pb.go

Large diffs are not rendered by default.

81 changes: 81 additions & 0 deletions pkg/version_config_manager/version_config_manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package version_config_manager

import (
"errors"
log "github.com/sirupsen/logrus"
)

type VersionConfig struct {
ProductLabel string `json:"productLabel"`
JsonPath string `json:"jsonPath"`
ResourceName string `json:"resourceName"`
}

type ConfigProvider interface {
GetConfig() (*VersionConfig, error)
}

type CodereshAPIConfigProvider struct {
CodereshAPIEndpoint string
}

type ConfigMapProvider struct {
ConfigMapPath string
}

func (CodereshAPI *CodereshAPIConfigProvider) GetConfig() (*VersionConfig, error) {
andrii-codefresh marked this conversation as resolved.
Show resolved Hide resolved
// Implement logic to fetch config from the CodereshAPI here.
// For this example, we'll just return a mock config.
return &VersionConfig{
ProductLabel: "ProductLabelName=ProductName",
JsonPath: "{.appVersion}",
ResourceName: "Chart.yaml",
}, nil
}

func (cm *ConfigMapProvider) GetConfig() (*VersionConfig, error) {
// Implement logic to fetch config from the config map here.
// For this example, we'll just return a mock config.
return &VersionConfig{
ProductLabel: "ProductLabelName=ProductName",
JsonPath: "{.appVersion}",
ResourceName: "Chart.yaml",
}, nil
}

type VersionConfigManager struct {
provider ConfigProvider
}

func NewVersionConfigManager(providerType string, source string) (*VersionConfigManager, error) {
var provider ConfigProvider
switch providerType {
case "CodereshAPI":
andrii-codefresh marked this conversation as resolved.
Show resolved Hide resolved
provider = &CodereshAPIConfigProvider{CodereshAPIEndpoint: source}
case "ConfigMap":
provider = &ConfigMapProvider{ConfigMapPath: source}
default:
return nil, errors.New("Invalid provider type")
}
return &VersionConfigManager{provider: provider}, nil
}

func (v *VersionConfigManager) ObtainConfig() (*VersionConfig, error) {
return v.provider.GetConfig()
}

func GetVersionConfig() *VersionConfig {
versionConfigManager, err := NewVersionConfigManager("ConfigMap", "some-product-cm")
if err != nil {
log.Printf("ERROR: Failed to create VersionConfigManager: %v", err)
andrii-codefresh marked this conversation as resolved.
Show resolved Hide resolved
return nil
}

versionConfig, err := versionConfigManager.ObtainConfig()
if err != nil {
log.Printf("ERROR: Failed to obtain config: %v", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, please also remove Error:

return nil
}

return versionConfig
}
Loading
Loading