Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,3 @@ jobs:
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
37 changes: 27 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,26 @@ CustomResourceDefinitions, or from JSON Schema.
### Docker

```bash
docker pull ghcr.io/jsonnet-libs/k8s:<version>
docker pull ghcr.io/thisisibrahimd/k8s-gen:<version>
```

### Binary release

Download pre-built binaries from [GitHub Releases](https://github.com/jsonnet-libs/k8s/releases):
Download pre-built binaries from [GitHub Releases](https://github.com/thisisibrahimd/k8s/releases):

```bash
curl -sL https://github.com/jsonnet-libs/k8s/releases/latest/download/k8s-gen_linux_x86_64.tar.gz | tar xz
curl -sL https://github.com/thisisibrahimd/k8s/releases/latest/download/k8s-gen_linux_x86_64.tar.gz | tar xz
sudo mv k8s-gen /usr/local/bin/
```

### From source

```bash
go install github.com/jsonnet-libs/k8s@latest
go install github.com/thisisibrahimd/k8s@latest
```

Note: this installs the binary as `k8s` (module path name). Rename or symlink it to `k8s-gen`, or substitute `k8s` in the commands below.

## Usage

### Create a self-managed lib
Expand Down Expand Up @@ -137,7 +139,7 @@ If you prefer to manually define versions and CRD URLs, omit `specGenerator` and
}
```

Note: When using manual specs, add a per-spec `prefix` if the CRD group cannot be inferred from the URLs alone.
Note: When using manual specs, set a per-spec `prefix` (regex) to filter which API groups are included; without a prefix, all groups found in the specs are included. Each spec must set either `crds` (a list of CRDs) or `openapi` (a single OpenAPI v2/Swagger spec) — they are mutually exclusive, and both accept URLs or local file paths.

| Feature | Auto-Discovery | Manual |
|---------|---------------|--------|
Expand All @@ -147,6 +149,7 @@ Note: When using manual specs, add a per-spec `prefix` if the CRD group cannot b
| `versionLimit` | Default `10` (mutually exclusive with `versions`) | Not applicable |
| `versions` | Optional exact list of clean versions (without prefix) | Not applicable |
| `versionPrefix` | Default `"v"` (prepended to `versions` for the Git ref) | Not applicable |
| `includeVersions` | Default `^v?\d+\.\d+\.\d+$` (regex filter on discovered tag names) | Not applicable |
| `dedupeCrds` | Default `true` (skips duplicate CRD versions; ignored when `versions` is set) | Not applicable |
| Maintenance | Automatic on new releases | Manual updates required |

Expand Down Expand Up @@ -175,18 +178,32 @@ Create a `config.json` in the new folder. This example renders a lib from CRDs:
}
```

Build the binary first (the Makefile expects `./k8s-gen` in the repo root):

```bash
go build -o k8s-gen .
```

Generate the library:

```bash
$ make libs/<name>
```

Pass `VERSIONS` to regenerate only specific versions:

```bash
$ make libs/<name> VERSIONS="1.27.0"
```

Or run the binary directly:

```bash
$ k8s-gen generate k8s --config libs/<name>/config.json
```

Append version outputs as positional arguments to regenerate only specific versions, e.g. `k8s-gen generate k8s --config libs/<name>/config.json 1.27.0`. Use the global `--debug` flag for verbose logging.

### Generate Jsonnet from JSON Schema

You can also generate a Jsonnet library directly from a JSON Schema file. This is useful for configuration files such as `.golangci.yml`, `package.json`, or any other schema-backed document.
Expand Down Expand Up @@ -270,7 +287,7 @@ For that, there are two methods for extending:

### `custom` patches

The [`custom/`](https://github.com/jsonnet-libs/k8s/tree/master/libs/k8s/custom)
The [`custom/`](https://github.com/thisisibrahimd/k8s/tree/master/libs/k8s/custom)
directory contains a set of `.libsonnet` files, that are _automatically merged_
with the generated result in `main.libsonnet`, so they become part of the
exported API.
Expand All @@ -283,10 +300,10 @@ libs/k8s/
├── config.json # Config to generate the k8s jsonnet libraries
└── custom
└── core
├── apps.libsonnet # Constructors for `core/v1`, ported from `ksonnet-gen` and `kausal.libsonnet`
├── autoscaling.libsonnet # Extends `autoscaling/v2beta2`
├── batch.libsonnet # Constructors for `batch/v1beta1`, `batch/v2alpha1`, ported from `kausal.libsonnet`
├── core.libsonnet # Constructors for `apps/v1`, `apps/v1beta1`, ported from `ksonnet-gen` and `kausal.libsonnet`
├── apps.libsonnet # Constructors for `apps/v1` (daemonSet, deployment, statefulSet), ported from `ksonnet-gen` and `kausal.libsonnet`
├── autoscaling.libsonnet # Extends `autoscaling/v1` and `autoscaling/v2`
├── batch.libsonnet # Constructors for `batch/v1` (cronJob), ported from `kausal.libsonnet`
├── core.libsonnet # Constructors for `core/v1`, ported from `ksonnet-gen` and `kausal.libsonnet`
├── list.libsonnet # Adds `core.v1.List`
├── mapContainers.libsonnet # Adds `mapContainers` functions for fields that support them
├── rbac.libsonnet # Adds helper functions to rbac objects
Expand Down
14 changes: 7 additions & 7 deletions cmd/k8s-gen/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
"path/filepath"

"github.com/google/go-jsonnet/formatter"
"github.com/jsonnet-libs/k8s/pkg/complier/jsonschemacomplier"
"github.com/jsonnet-libs/k8s/pkg/config"
"github.com/jsonnet-libs/k8s/pkg/model"
"github.com/jsonnet-libs/k8s/pkg/swagger"
"github.com/jsonnet-libs/k8s/pkg/targetgenerator"
"github.com/jsonnet-libs/k8s/pkg/util"
"github.com/jsonnet-libs/k8s/pkg/writer"
"github.com/thisisibrahimd/k8s/pkg/complier/jsonschemacomplier"
"github.com/thisisibrahimd/k8s/pkg/config"
"github.com/thisisibrahimd/k8s/pkg/model"
"github.com/thisisibrahimd/k8s/pkg/swagger"
"github.com/thisisibrahimd/k8s/pkg/targetgenerator"
"github.com/thisisibrahimd/k8s/pkg/util"
"github.com/thisisibrahimd/k8s/pkg/writer"
"github.com/mdobak/go-xerrors"
"github.com/santhosh-tekuri/jsonschema/v6"
"github.com/urfave/cli/v3"
Expand Down
2 changes: 1 addition & 1 deletion cmd/k8s-gen/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log/slog"
"os"

"github.com/jsonnet-libs/k8s/pkg/telemetry"
"github.com/thisisibrahimd/k8s/pkg/telemetry"
"github.com/urfave/cli/v3"
)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/jsonnet-libs/k8s
module github.com/thisisibrahimd/k8s

go 1.26.6

Expand Down
2 changes: 1 addition & 1 deletion goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ dockers_v2:
- id: k8s-gen
dockerfile: "Containerfile"
images:
- "ghcr.io/{{ .Env.OWNER }}/k8s-gen"
- "ghcr.io/thisisibrahimd/k8s-gen"
extra_files:
- LICENSE
labels:
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log/slog"
"os"

cmd "github.com/jsonnet-libs/k8s/cmd/k8s-gen"
cmd "github.com/thisisibrahimd/k8s/cmd/k8s-gen"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/builder/docsonnet/docsonnet.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package docsonnet

import (
j "github.com/jsonnet-libs/k8s/pkg/builder"
j "github.com/thisisibrahimd/k8s/pkg/builder"
)

const dPkg = "doc-util/main.libsonnet"
Expand Down
4 changes: 2 additions & 2 deletions pkg/complier/jsonschemacomplier/jsonschemacomplier.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package jsonschemacomplier
import (
"fmt"

"github.com/jsonnet-libs/k8s/pkg/builder"
"github.com/jsonnet-libs/k8s/pkg/render"
"github.com/thisisibrahimd/k8s/pkg/builder"
"github.com/thisisibrahimd/k8s/pkg/render"
"github.com/santhosh-tekuri/jsonschema/v6"
"github.com/stoewer/go-strcase"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/complier/jsonschemacomplier/jsonschemacomplier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"

"github.com/google/go-jsonnet/formatter"
"github.com/jsonnet-libs/k8s/pkg/complier/jsonschemacomplier"
"github.com/thisisibrahimd/k8s/pkg/complier/jsonschemacomplier"
"github.com/santhosh-tekuri/jsonschema/v6"
"github.com/sebdah/goldie/v2"
)
Expand Down
1 change: 0 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ type TargetGenerator struct {
Prefix string `json:"prefix" validate:"required"`
VersionLimit *int `json:"versionLimit" validate:"omitempty,min=1,excluded_with=Versions"`
IncludeVersions string `json:"includeVersions" default:"^v?\\d+\\.\\d+\\.\\d+$"`
ExcludeVersions string `json:"excludeVersions"`
DedupeCrds *bool `json:"dedupeCrds" default:"true"`
Versions []string `json:"versions" validate:"excluded_with=VersionLimit"`
VersionPrefix *string `json:"versionPrefix" default:"v"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/gvk.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"regexp"
"strings"

"github.com/jsonnet-libs/k8s/pkg/swagger"
"github.com/thisisibrahimd/k8s/pkg/swagger"
)

// Groups represents a list of group
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"regexp"

"github.com/jsonnet-libs/k8s/pkg/swagger"
"github.com/thisisibrahimd/k8s/pkg/swagger"
)

var expr = regexp.MustCompile(`(?mU)(?P<domain>.+)\.((?P<group>\w*)\.)?(?P<version>\w*)\.(?P<kind>\w*)$`)
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/modifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"

"github.com/fatih/camelcase"
"github.com/jsonnet-libs/k8s/pkg/swagger"
"github.com/thisisibrahimd/k8s/pkg/swagger"
)

type excludeType string
Expand Down
8 changes: 4 additions & 4 deletions pkg/render/modifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"fmt"
"strings"

j "github.com/jsonnet-libs/k8s/pkg/builder"
d "github.com/jsonnet-libs/k8s/pkg/builder/docsonnet"
"github.com/jsonnet-libs/k8s/pkg/model"
"github.com/jsonnet-libs/k8s/pkg/swagger"
j "github.com/thisisibrahimd/k8s/pkg/builder"
d "github.com/thisisibrahimd/k8s/pkg/builder/docsonnet"
"github.com/thisisibrahimd/k8s/pkg/model"
"github.com/thisisibrahimd/k8s/pkg/swagger"
)

const (
Expand Down
6 changes: 3 additions & 3 deletions pkg/render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"path"
"path/filepath"

j "github.com/jsonnet-libs/k8s/pkg/builder"
d "github.com/jsonnet-libs/k8s/pkg/builder/docsonnet"
"github.com/jsonnet-libs/k8s/pkg/model"
j "github.com/thisisibrahimd/k8s/pkg/builder"
d "github.com/thisisibrahimd/k8s/pkg/builder/docsonnet"
"github.com/thisisibrahimd/k8s/pkg/model"
)

// Common set of directory structure / file extensions
Expand Down
2 changes: 1 addition & 1 deletion pkg/render/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"sort"
"strings"

j "github.com/jsonnet-libs/k8s/pkg/builder"
j "github.com/thisisibrahimd/k8s/pkg/builder"
)

// SortFields sorts Jsonnet fields
Expand Down
2 changes: 1 addition & 1 deletion pkg/render/sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package render
import (
"testing"

j "github.com/jsonnet-libs/k8s/pkg/builder"
j "github.com/thisisibrahimd/k8s/pkg/builder"
"github.com/stretchr/testify/assert"
)

Expand Down
4 changes: 2 additions & 2 deletions pkg/targetgenerator/githubtargetgenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"regexp"
"strings"

"github.com/jsonnet-libs/k8s/pkg/config"
"github.com/jsonnet-libs/k8s/pkg/telemetry"
"github.com/thisisibrahimd/k8s/pkg/config"
"github.com/thisisibrahimd/k8s/pkg/telemetry"
"github.com/mdobak/go-xerrors"
"resty.dev/v3"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/targetgenerator/targetgenerator.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package targetgenerator

import (
"github.com/jsonnet-libs/k8s/pkg/config"
"github.com/thisisibrahimd/k8s/pkg/config"
"github.com/mdobak/go-xerrors"
)

Expand Down
6 changes: 3 additions & 3 deletions pkg/writer/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"path/filepath"

"github.com/google/go-jsonnet/formatter"
"github.com/jsonnet-libs/k8s/pkg/config"
"github.com/jsonnet-libs/k8s/pkg/model"
"github.com/jsonnet-libs/k8s/pkg/render"
"github.com/thisisibrahimd/k8s/pkg/config"
"github.com/thisisibrahimd/k8s/pkg/model"
"github.com/thisisibrahimd/k8s/pkg/render"
"github.com/mdobak/go-xerrors"
)

Expand Down
4 changes: 2 additions & 2 deletions pkg/writer/writer.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package writer

import (
"github.com/jsonnet-libs/k8s/pkg/config"
"github.com/jsonnet-libs/k8s/pkg/model"
"github.com/thisisibrahimd/k8s/pkg/config"
"github.com/thisisibrahimd/k8s/pkg/model"
)

type Writer interface {
Expand Down