Skip to content

Commit

Permalink
add deployment strategy auto-injection
Browse files Browse the repository at this point in the history
  • Loading branch information
jackspirou committed Dec 17, 2024
1 parent 4ae5123 commit e92ce4f
Show file tree
Hide file tree
Showing 7 changed files with 1,038 additions and 14 deletions.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- Creates missing values in values files with their default values
- Preserves existing values, structure, and data types in your values files
- Provides line number and source file tracking for each reference
- Automatically injects and manages Kubernetes deployment strategies
- Uses atomic file operations to prevent data corruption
- Provides robust error handling with detailed messages

Expand Down Expand Up @@ -125,6 +126,48 @@ path: "/"
port: 80
```

### Deployment Strategy Example

For Kubernetes deployment manifests, `shcv` automatically injects deployment strategy configuration. Given a template file `templates/deployment.yaml`:
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Values.name }}
spec:
selector:
matchLabels:
app: {{ .Values.name }}
template:
metadata:
labels:
app: {{ .Values.name }}
spec:
containers:
- name: {{ .Values.name }}
image: {{ .Values.image }}
```

Running `shcv .` will add deployment strategy configuration to `values.yaml`:
```yaml
deployment:
strategy:
type: "RollingUpdate"
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
```

And update the deployment template with strategy configuration:
```yaml
spec:
strategy:
type: {{ .Values.deployment.strategy.type }}
rollingUpdate:
maxSurge: {{ .Values.deployment.strategy.rollingUpdate.maxSurge }}
maxUnavailable: {{ .Values.deployment.strategy.rollingUpdate.maxUnavailable }}
```

## Requirements

- Go 1.21 or later
Expand Down
22 changes: 11 additions & 11 deletions pkg/shcv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const Version = "1.0.6"
```

<a name="Chart"></a>
## type [Chart](<https://github.com/agentstation/shcv/blob/master/pkg/shcv/pkg/shcv/shcv.go#L45-L56>)
## type [Chart](<https://github.com/agentstation/shcv/blob/master/pkg/shcv/pkg/shcv/shcv.go#L46-L57>)

Chart represents a Helm chart structure and manages its values and templates. It provides functionality to scan templates for value references and ensure all referenced values are properly defined in values.yaml.

Expand All @@ -120,7 +120,7 @@ type Chart struct {
```

<a name="NewChart"></a>
### func [NewChart](<https://github.com/agentstation/shcv/blob/master/pkg/shcv/pkg/shcv/shcv.go#L59>)
### func [NewChart](<https://github.com/agentstation/shcv/blob/master/pkg/shcv/pkg/shcv/shcv.go#L60>)

```go
func NewChart(dir string, opts ...Option) (*Chart, error)
Expand Down Expand Up @@ -156,7 +156,7 @@ func (c *Chart) ParseTemplates() error
ParseTemplates scans all discovered templates for .Values references. It identifies both simple references and those with default values. The references are stored in the Chart's References slice.

<a name="Chart.ProcessReferences"></a>
### func \(\*Chart\) [ProcessReferences](<https://github.com/agentstation/shcv/blob/master/pkg/shcv/pkg/shcv/shcv.go#L196>)
### func \(\*Chart\) [ProcessReferences](<https://github.com/agentstation/shcv/blob/master/pkg/shcv/pkg/shcv/shcv.go#L205>)

```go
func (c *Chart) ProcessReferences()
Expand All @@ -165,7 +165,7 @@ func (c *Chart) ProcessReferences()
ProcessReferences ensures all referenced values exist in values.yaml.

<a name="Chart.UpdateValueFiles"></a>
### func \(\*Chart\) [UpdateValueFiles](<https://github.com/agentstation/shcv/blob/master/pkg/shcv/pkg/shcv/shcv.go#L239>)
### func \(\*Chart\) [UpdateValueFiles](<https://github.com/agentstation/shcv/blob/master/pkg/shcv/pkg/shcv/shcv.go#L421>)

```go
func (c *Chart) UpdateValueFiles() error
Expand All @@ -174,7 +174,7 @@ func (c *Chart) UpdateValueFiles() error
UpdateValueFiles ensures all referenced values exist in values.yaml. It adds missing values with appropriate defaults and updates the file. The operation is skipped if no changes are needed.

<a name="Option"></a>
## type [Option](<https://github.com/agentstation/shcv/blob/master/pkg/shcv/pkg/shcv/config.go#L25>)
## type [Option](<https://github.com/agentstation/shcv/blob/master/pkg/shcv/pkg/shcv/config.go#L39>)

Option is a functional option for configuring the Chart processing.

Expand All @@ -183,7 +183,7 @@ type Option func(*config)
```

<a name="WithTemplatesDir"></a>
### func [WithTemplatesDir](<https://github.com/agentstation/shcv/blob/master/pkg/shcv/pkg/shcv/config.go#L35>)
### func [WithTemplatesDir](<https://github.com/agentstation/shcv/blob/master/pkg/shcv/pkg/shcv/config.go#L49>)

```go
func WithTemplatesDir(dir string) Option
Expand All @@ -192,7 +192,7 @@ func WithTemplatesDir(dir string) Option
WithTemplatesDir sets the templates directory.

<a name="WithValuesFileNames"></a>
### func [WithValuesFileNames](<https://github.com/agentstation/shcv/blob/master/pkg/shcv/pkg/shcv/config.go#L28>)
### func [WithValuesFileNames](<https://github.com/agentstation/shcv/blob/master/pkg/shcv/pkg/shcv/config.go#L42>)

```go
func WithValuesFileNames(names []string) Option
Expand All @@ -201,7 +201,7 @@ func WithValuesFileNames(names []string) Option
WithValuesFileNames sets the values file names.

<a name="WithVerbose"></a>
### func [WithVerbose](<https://github.com/agentstation/shcv/blob/master/pkg/shcv/pkg/shcv/config.go#L42>)
### func [WithVerbose](<https://github.com/agentstation/shcv/blob/master/pkg/shcv/pkg/shcv/config.go#L56>)

```go
func WithVerbose(verbose bool) Option
Expand All @@ -210,7 +210,7 @@ func WithVerbose(verbose bool) Option
WithVerbose sets the verbose flag.

<a name="ValueFile"></a>
## type [ValueFile](<https://github.com/agentstation/shcv/blob/master/pkg/shcv/pkg/shcv/shcv.go#L33-L40>)
## type [ValueFile](<https://github.com/agentstation/shcv/blob/master/pkg/shcv/pkg/shcv/shcv.go#L34-L41>)

ValueFile represents a values file

Expand All @@ -226,7 +226,7 @@ type ValueFile struct {
```

<a name="ValueRef"></a>
## type [ValueRef](<https://github.com/agentstation/shcv/blob/master/pkg/shcv/pkg/shcv/shcv.go#L16-L25>)
## type [ValueRef](<https://github.com/agentstation/shcv/blob/master/pkg/shcv/pkg/shcv/shcv.go#L17-L26>)

ValueRef represents a Helm value reference found in templates. It tracks where values are used in templates and their default values if specified.

Expand All @@ -253,7 +253,7 @@ func ParseFile(content, templatePath string) []ValueRef
ParseFile parses a template file and returns all value references

<a name="ValueRef.ID"></a>
### func \(\*ValueRef\) [ID](<https://github.com/agentstation/shcv/blob/master/pkg/shcv/pkg/shcv/shcv.go#L28>)
### func \(\*ValueRef\) [ID](<https://github.com/agentstation/shcv/blob/master/pkg/shcv/pkg/shcv/shcv.go#L29>)

```go
func (v *ValueRef) ID() string
Expand Down
Loading

0 comments on commit e92ce4f

Please sign in to comment.