-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add AppConfiguration, Deploy, and Job models (#451)
- Loading branch information
Showing
24 changed files
with
959 additions
and
30 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,41 @@ | ||
# Reference from: | ||
# https://github.com/c-bata/go-prompt/blob/master/.github/workflows/test.yml | ||
name: Constraints | ||
on: | ||
pull_request: | ||
types: [opened, edited, synchronize, reopened] | ||
jobs: | ||
# Lints Pull Request commits with commitlint. | ||
# | ||
# Rules can be referenced: | ||
# https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional | ||
CommitLint: | ||
name: Commit Lint | ||
runs-on: ubuntu-latest | ||
if: contains(fromJSON('["pull_request"]'), github.event_name) | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- uses: wagoid/commitlint-github-action@v5 | ||
|
||
# Lints Pull Request title, because the title will be used as the | ||
# commit message in branch main. | ||
# | ||
# Configuration detail can be referenced: | ||
# https://github.com/marketplace/actions/pull-request-title-rules | ||
PullRequestTitleLint: | ||
name: Pull Request Title Lint | ||
runs-on: ubuntu-latest | ||
if: contains(fromJSON('["pull_request"]'), github.event_name) | ||
steps: | ||
- uses: deepakputhraya/action-pr-title@master | ||
with: | ||
allowed_prefixes: 'build,chore,ci,docs,feat,fix,perf,refactor,revert,style,test' # title should start with the given prefix | ||
disallowed_prefixes: 'WIP,[WIP]' # title should not start with the given prefix | ||
prefix_case_sensitive: false # title prefix are case insensitive | ||
min_length: 5 # Min length of the title | ||
max_length: 80 # Max length of the title | ||
github_token: ${{ github.token }} # Default: ${{ github.token }} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright The Karbour Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
// This file is the configuration file of [commitlint](https://commitlint.js.org/#/). | ||
// | ||
// Rules can be referenced: | ||
// https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional | ||
module.exports = {extends: ['@commitlint/config-conventional']} |
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
33 changes: 33 additions & 0 deletions
33
pkg/generator/appconfiguration/app_configuration_generator.go
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,33 @@ | ||
package appconfiguration | ||
|
||
import ( | ||
"kusionstack.io/kusion/pkg/generator" | ||
"kusionstack.io/kusion/pkg/generator/appconfiguration/generators" | ||
"kusionstack.io/kusion/pkg/models" | ||
"kusionstack.io/kusion/pkg/models/appconfiguration" | ||
"kusionstack.io/kusion/pkg/projectstack" | ||
) | ||
|
||
type Generator struct { | ||
*appconfiguration.AppConfiguration | ||
} | ||
|
||
func (acg *Generator) GenerateSpec( | ||
o *generator.Options, | ||
project *projectstack.Project, | ||
stack *projectstack.Stack, | ||
) (*models.Spec, error) { | ||
spec := &models.Spec{ | ||
Resources: []models.Resource{}, | ||
} | ||
|
||
g, err := generators.NewAppConfigurationGenerator(project.Name, acg.AppConfiguration) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if err = g.Generate(spec); err != nil { | ||
return nil, err | ||
} | ||
|
||
return spec, nil | ||
} |
45 changes: 45 additions & 0 deletions
45
pkg/generator/appconfiguration/generators/app_configuration_generator.go
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,45 @@ | ||
package generators | ||
|
||
import ( | ||
"fmt" | ||
|
||
"kusionstack.io/kusion/pkg/models" | ||
"kusionstack.io/kusion/pkg/models/appconfiguration" | ||
) | ||
|
||
type appConfigurationGenerator struct { | ||
projectName string | ||
ac *appconfiguration.AppConfiguration | ||
} | ||
|
||
func NewAppConfigurationGenerator(projectName string, ac *appconfiguration.AppConfiguration) (Generator, error) { | ||
if len(projectName) == 0 { | ||
return nil, fmt.Errorf("project name must not be empty") | ||
} | ||
|
||
if ac == nil { | ||
return nil, fmt.Errorf("can not find app configuration when generating the Spec") | ||
} | ||
|
||
return &appConfigurationGenerator{ | ||
projectName: projectName, | ||
ac: ac, | ||
}, nil | ||
} | ||
|
||
func (g *appConfigurationGenerator) Generate(spec *models.Spec) error { | ||
if spec.Resources == nil { | ||
spec.Resources = make(models.Resources, 0) | ||
} | ||
|
||
gfs := []NewGeneratorFunc{ | ||
NewNamespaceGeneratorFunc(g.projectName), | ||
NewComponentsGeneratorFunc(g.projectName, g.ac.Components), | ||
} | ||
|
||
if err := callGenerators(spec, gfs...); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
55 changes: 55 additions & 0 deletions
55
pkg/generator/appconfiguration/generators/components_generator.go
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,55 @@ | ||
package generators | ||
|
||
import ( | ||
"fmt" | ||
|
||
"kusionstack.io/kusion/pkg/models" | ||
"kusionstack.io/kusion/pkg/models/appconfiguration/component" | ||
) | ||
|
||
type componentsGenerator struct { | ||
projectName string | ||
components map[string]component.Component | ||
} | ||
|
||
func NewComponentsGenerator(projectName string, components map[string]component.Component) (Generator, error) { | ||
if len(projectName) == 0 { | ||
return nil, fmt.Errorf("project name must not be empty") | ||
} | ||
|
||
return &componentsGenerator{ | ||
projectName: projectName, | ||
components: components, | ||
}, nil | ||
} | ||
|
||
func NewComponentsGeneratorFunc(projectName string, components map[string]component.Component) NewGeneratorFunc { | ||
return func() (Generator, error) { | ||
return NewComponentsGenerator(projectName, components) | ||
} | ||
} | ||
|
||
func (g *componentsGenerator) Generate(spec *models.Spec) error { | ||
if spec.Resources == nil { | ||
spec.Resources = make(models.Resources, 0) | ||
} | ||
|
||
if g.components != nil { | ||
if err := foreachOrderedComponents(g.components, func(compName string, comp component.Component) error { | ||
gfs := []NewGeneratorFunc{ | ||
NewDeploymentGeneratorFunc(g.projectName, compName, &comp), | ||
NewJobGeneratorFunc(g.projectName, compName, &comp), | ||
} | ||
|
||
if err := callGenerators(spec, gfs...); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.