Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
9abe27b
Enhance GitHub actions CI
Adirio Mar 16, 2021
e3437d6
Merge pull request #2095 from Adirio/enhance-gh-actions
k8s-ci-robot Mar 23, 2021
d7bd9c7
Allow to modify the root's command description
Adirio Mar 24, 2021
2d0bae4
Merge pull request #2105 from Adirio/cli-description
k8s-ci-robot Mar 24, 2021
f5d2f6a
Split GH Actions jobs into separate workflows
Adirio Mar 25, 2021
825b347
Merge pull request #2107 from Adirio/split-GH-workflows
k8s-ci-robot Mar 25, 2021
beecada
:bug: do not generate the cert-manager directory by default.
camilamacedo86 Mar 25, 2021
b828d86
Merge pull request #2111 from camilamacedo86/fix-certmanager
k8s-ci-robot Mar 25, 2021
39ec8f8
Allow bundles to be used as input to other bundles
Adirio Mar 26, 2021
9d1fd06
:warning: move declarative plugin to golang domain
camilamacedo86 Mar 26, 2021
f65ddb2
Merge pull request #2114 from camilamacedo86/declarative-org
k8s-ci-robot Mar 26, 2021
84f357b
Merge pull request #2112 from Adirio/bundle-recursion
k8s-ci-robot Mar 27, 2021
9e816f5
:sparkles: add the common plugin(s) to allow it to be used by consumers
camilamacedo86 Apr 1, 2021
3da7f18
change scale example attribute
huiwq1990 Apr 7, 2021
3eb373c
Merge pull request #2127 from huiwq1990/fix-bookScaleExample
k8s-ci-robot Apr 7, 2021
d5e70a5
Merge pull request #2106 from camilamacedo86/config-base
k8s-ci-robot Apr 7, 2021
3eaa8c0
:seeding: fix lint issue on master for the release
camilamacedo86 Apr 7, 2021
72f7c2e
Merge pull request #2132 from camilamacedo86/fix-lint-master
k8s-ci-robot Apr 7, 2021
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
89 changes: 0 additions & 89 deletions .github/workflows/ci.yml

This file was deleted.

31 changes: 31 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Lint

# Trigger the workflow on pull requests and direct pushes to any branch
on:
push:
pull_request:

jobs:

lint:
name: golangci-lint
runs-on: ubuntu-latest
# Pull requests from the same repository won't trigger this checks as they were already triggered by the push
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- name: Clone the code
uses: actions/checkout@v2
- name: Run linter
uses: golangci/golangci-lint-action@v2
with:
version: v1.37 # Always uses the latest patch version.
only-new-issues: true # Show only new issues if it's a pull request
- name: Report failure
uses: nashmaniac/[email protected]
# Only report failures of pushes (PRs have are visible through the Checks section) to the default branch
if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/master'
with:
title: 🐛 Lint failed for ${{ github.sha }}
token: ${{ secrets.GITHUB_TOKEN }}
labels: kind/bug
body: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
36 changes: 36 additions & 0 deletions .github/workflows/testdata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Testdata verification

# Trigger the workflow on pull requests and direct pushes to any branch
on:
push:
pull_request:

jobs:

testdata:
name: Verify testdata directory
runs-on: ubuntu-latest
# Pull requests from the same repository won't trigger this checks as they were already triggered by the push
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- name: Clone the code
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.15'
- name: Remove pre-installed kustomize
# This step is needed as the following one tries to remove
# kustomize for each test but has no permission to do so
run: sudo rm -f /usr/local/bin/kustomize
- name: Verify testdata directory
run: make check-testdata
- name: Report failure
uses: nashmaniac/[email protected]
# Only report failures of pushes (PRs have are visible through the Checks section) to the default branch
if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/master'
with:
title: 🐛 Testadata verification failed for ${{ github.sha }}
token: ${{ secrets.GITHUB_TOKEN }}
labels: kind/bug
body: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
72 changes: 72 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Unit tests

# Trigger the workflow on pull requests and direct pushes to any branch
on:
push:
pull_request:


jobs:

test:
name: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
# Pull requests from the same repository won't trigger this checks as they were already triggered by the push
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- name: Clone the code
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.15'
# This step is needed as the following one tries to remove
# kustomize for each test but has no permission to do so
- name: Remove pre-installed kustomize
run: sudo rm -f /usr/local/bin/kustomize
- name: Perform the test
run: make test
- name: Report failure
uses: nashmaniac/[email protected]
# Only report failures of pushes (PRs have are visible through the Checks section) to the default branch
if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/master'
with:
title: 🐛 Unit tests failed on ${{ matrix.os }} for ${{ github.sha }}
token: ${{ secrets.GITHUB_TOKEN }}
labels: kind/bug
body: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}

coverage:
name: Code coverage
needs:
- test
runs-on: ubuntu-latest
# Pull requests from the same repository won't trigger this checks as they were already triggered by the push
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- name: Clone the code
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.15'
- name: Generate the coverage output
run: make test-coverage
- name: Send the coverage output
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: coverage-all.out
- name: Report failure
uses: nashmaniac/[email protected]
# Only report failures of pushes (PRs have are visible through the Checks section) to the default branch
if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/master'
with:
title: 🐛 Coverage report failed for ${{ github.sha }}
token: ${{ secrets.GITHUB_TOKEN }}
labels: kind/bug
body: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
25 changes: 18 additions & 7 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,33 @@ import (
"sigs.k8s.io/kubebuilder/v3/pkg/cli"
cfgv2 "sigs.k8s.io/kubebuilder/v3/pkg/config/v2"
cfgv3 "sigs.k8s.io/kubebuilder/v3/pkg/config/v3"
declarativev1 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/declarative/v1"
pluginv2 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v2"
pluginv3 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v3"
"sigs.k8s.io/kubebuilder/v3/pkg/plugin"
kustomizecommonv1 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/common/kustomize/v1"
"sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang"
declarativev1 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/declarative/v1"
golangv2 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v2"
golangv3 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v3"
)

func main() {

// Bundle plugin which built the golang projects scaffold by Kubebuilder go/v3
gov3Bundle, _ := plugin.NewBundle(golang.DefaultNameQualifier, plugin.Version{Number: 3},
kustomizecommonv1.Plugin{},
golangv3.Plugin{},
)

c, err := cli.New(
cli.WithCommandName("kubebuilder"),
cli.WithVersion(versionString()),
cli.WithPlugins(
&pluginv2.Plugin{},
&pluginv3.Plugin{},
golangv2.Plugin{},
gov3Bundle,
&kustomizecommonv1.Plugin{},
&declarativev1.Plugin{},
),
cli.WithDefaultPlugins(cfgv2.Version, &pluginv2.Plugin{}),
cli.WithDefaultPlugins(cfgv3.Version, &pluginv3.Plugin{}),
cli.WithDefaultPlugins(cfgv2.Version, golangv2.Plugin{}),
cli.WithDefaultPlugins(cfgv3.Version, gov3Bundle),
cli.WithDefaultProjectVersion(cfgv3.Version),
cli.WithCompletion(),
)
Expand Down
4 changes: 2 additions & 2 deletions docs/book/src/reference/generating-crd.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ type CustomSet struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ToySpec `json:"spec,omitempty"`
Status ToyStatus `json:"status,omitempty"`
Spec CustomSetSpec `json:"spec,omitempty"`
Status CustomSetStatus `json:"status,omitempty"`
}
```

Expand Down
6 changes: 5 additions & 1 deletion pkg/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type CLI struct { //nolint:maligned
commandName string
// CLI version string.
version string
// CLI root's command description.
description string
// Plugins registered in the CLI.
plugins map[string]plugin.Plugin
// Default plugins in case none is provided and a config file can't be found.
Expand Down Expand Up @@ -120,7 +122,9 @@ func New(options ...Option) (*CLI, error) {
func newCLI(options ...Option) (*CLI, error) {
// Default CLI options.
c := &CLI{
commandName: "kubebuilder",
commandName: "kubebuilder",
description: `CLI tool for building Kubernetes extensions and tools.
`,
plugins: make(map[string]plugin.Plugin),
defaultPlugins: make(map[config.Version][]string),
fs: machinery.Filesystem{FS: afero.NewOsFs()},
Expand Down
8 changes: 8 additions & 0 deletions pkg/cli/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ func WithVersion(version string) Option {
}
}

// WithDescription is an Option that sets the CLI's root description.
func WithDescription(description string) Option {
return func(c *CLI) error {
c.description = description
return nil
}
}

// WithPlugins is an Option that sets the CLI's plugins.
//
// Specifying any invalid plugin results in an error.
Expand Down
10 changes: 10 additions & 0 deletions pkg/cli/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ var _ = Describe("CLI options", func() {
})
})

Context("WithDescription", func() {
It("should use the provided description string", func() {
description := "alternative description"
c, err = newCLI(WithDescription(description))
Expect(err).NotTo(HaveOccurred())
Expect(c).NotTo(BeNil())
Expect(c.description).To(Equal(description))
})
})

Context("WithPlugins", func() {
It("should return a valid CLI", func() {
c, err = newCLI(WithPlugins(p))
Expand Down
5 changes: 2 additions & 3 deletions pkg/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ const (

func (c CLI) newRootCmd() *cobra.Command {
cmd := &cobra.Command{
Use: c.commandName,
Long: `CLI tool for building Kubernetes extensions and tools.
`,
Use: c.commandName,
Long: c.description,
Example: c.rootExamples(),
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
Expand Down
14 changes: 13 additions & 1 deletion pkg/plugin/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,22 @@ func NewBundle(name string, version Version, plugins ...Plugin) (Bundle, error)
return nil, fmt.Errorf("in order to bundle plugins, they must all support at least one common project version")
}

// Plugins may be bundles themselves, so unbundle here
// NOTE(Adirio): unbundling here ensures that Bundle.Plugin always returns a flat list of Plugins instead of also
// including Bundles, and therefore we don't have to use a recursive algorithm when resolving.
allPlugins := make([]Plugin, 0, len(plugins))
for _, plugin := range plugins {
if pluginBundle, isBundle := plugin.(Bundle); isBundle {
allPlugins = append(allPlugins, pluginBundle.Plugins()...)
} else {
allPlugins = append(allPlugins, plugin)
}
}

return bundle{
name: name,
version: version,
plugins: plugins,
plugins: allPlugins,
supportedProjectVersions: supportedProjectVersions,
}, nil
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/plugin/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,26 @@ var _ = Describe("Bundle", func() {
}
})

It("should accept bundles as input", func() {
var a, b Bundle
var err error
plugins := []Plugin{p1, p2, p3}
a, err = NewBundle("a", version, p1, p2)
Expect(err).NotTo(HaveOccurred())
b, err = NewBundle("b", version, a, p3)
Expect(err).NotTo(HaveOccurred())
versions := b.SupportedProjectVersions()
sort.Slice(versions, func(i int, j int) bool {
return versions[i].Compare(versions[j]) == -1
})
expectedVersions := CommonSupportedProjectVersions(plugins...)
sort.Slice(expectedVersions, func(i int, j int) bool {
return expectedVersions[i].Compare(expectedVersions[j]) == -1
})
Expect(versions).To(Equal(expectedVersions))
Expect(b.Plugins()).To(Equal(plugins))
})

It("should fail for plugins with no common supported project version", func() {
for _, plugins := range [][]Plugin{
{p2, p4},
Expand Down
Loading