Skip to content

Commit

Permalink
Merge pull request #2134 from kubernetes-sigs/master
Browse files Browse the repository at this point in the history
🌱 rebase with master for the release 3.0.0-rc-0
  • Loading branch information
k8s-ci-robot authored Apr 8, 2021
2 parents ad5f0b8 + 72f7c2e commit 90fe412
Show file tree
Hide file tree
Showing 56 changed files with 522 additions and 235 deletions.
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

0 comments on commit 90fe412

Please sign in to comment.