Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify API and Generate Addon API clientset/lister/informers #111

Closed
wants to merge 23 commits into from
Closed
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ADD go.sum .
RUN go mod download

COPY pkg/ pkg/
COPY api/ api/
COPY apis/ apis/
COPY cmd/ cmd/
COPY controllers/ controllers/
COPY main.go main.go
Expand Down
42 changes: 38 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,25 @@ GO111MODULE=on
all: test manager addonctl

# Run tests
test: generate fmt vet manifests
ccfishk marked this conversation as resolved.
Show resolved Hide resolved
go test ./api/... ./controllers/... ./pkg/... ./cmd/... -coverprofile cover.out
.PHONY: test
test:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs the other targets also.

Suggested change
test:
test: generate fmt vet manifests

go test -v -race ./controllers/... ./apis/addon/... ./pkg/... ./cmd/... -coverprofile cover.out

.PHONY: test.controllers
test.controllers:
go test -v -race ./controllers/... -coverprofile cover.out

.PHONY: test.api
test.api:
go test -v -race ./apis/addon/... -coverprofile cover.out

.PHONY: test.pkg
test.pkg:
go test -v -race ./pkg/... -coverprofile cover.out

.PHONY: test.cmd
test.pkg:
go test -v -race ./cmd/... -coverprofile cover.out

# Run E2E tests
bdd: fmt vet deploy
Expand Down Expand Up @@ -95,8 +112,13 @@ vet:
go vet ./...

# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./api/...
generate: controller-gen code-generator
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./apis/addon/...
bash $(GOPATH)/src/k8s.io/[email protected]/generate-groups.sh \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's capture this code-generator call as env. var, $(CODE_GEN)

"deepcopy,client,informer,lister" \
github.com/keikoproj/addon-manager/pkg/client github.com/keikoproj/addon-manager/apis\
addon:v1alpha1 \
--go-header-file ./hack/custom-boilerplate.go.txt

# Build the docker image
docker-build: manager
Expand Down Expand Up @@ -130,3 +152,15 @@ CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif

code-generator:
ifeq (, $(shell which code-generator))
@{ \
set -e ;\
CODE_GENERATOR_DIR=$$(mkdir -p $(GOPATH)/src/k8s.io/) ;\
cd $$CODE_GENERATOR_DIR ;\
go get github.com/kubernetes/[email protected] ;\
}
endif
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
endif
else
CODE_GEN="bash $(GOPATH)/src/k8s.io/[email protected]/generate-groups.sh"
endif



19 changes: 19 additions & 0 deletions apis/addon/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package addon

import "time"

// Addon constants
const (
Group string = "addonmgr.keikoproj.io"
Version string = "v1alpha1"
APIVersion string = Group + "/" + Version
AddonKind string = "Addon"
AddonSingular string = "addon"
AddonPlural string = "addons"
AddonShortName string = "addon"
AddonFullName string = AddonPlural + "." + Group

ManagedNameSpace string = "addon-manager-system"

AddonResyncPeriod = 20 * time.Minute
)
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ const (
Deleting ApplicationAssemblyPhase = "Deleting"
// DeleteFailed Used to indicate that delete failed.
DeleteFailed ApplicationAssemblyPhase = "Delete Failed"
// Error used to indicate system error
Error ApplicationAssemblyPhase = "error"
)

// DeploymentPhase represents the status of observed resources
Expand Down Expand Up @@ -281,8 +283,8 @@ type AddonStatus struct {
StartTime int64 `json:"starttime"`
}

// AddonList contains a list of Addon
// +kubebuilder:object:root=true

// Addon is the Schema for the addons API
// +k8s:openapi-gen=true
// +kubebuilder:subresource:status
Expand All @@ -292,6 +294,8 @@ type AddonStatus struct {
// +kubebuilder:printcolumn:name="STATUS",type="string",JSONPath=".status.lifecycle.installed"
// +kubebuilder:printcolumn:name="REASON",type="string",JSONPath=".status.reason"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type Addon struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -301,18 +305,13 @@ type Addon struct {
}

// +kubebuilder:object:root=true

// AddonList contains a list of Addon
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type AddonList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Addon `json:"items"`
}

func init() {
SchemeBuilder.Register(&Addon{}, &AddonList{})
}

// GetPackageSpec returns the addon package details from addon spec
func (a *Addon) GetPackageSpec() PackageSpec {
return PackageSpec{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,41 @@ import (
)

var wfSpecTemplate = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: scripts-python-
spec:
entrypoint: python-script-example
templates:
- name: python-script-example
steps:
- - name: generate
template: gen-random-int
- - name: print
template: print-message
arguments:
parameters:
- name: message
value: "{{steps.generate.outputs.result}}"

- name: gen-random-int
script:
image: python:alpine3.6
command: [python]
source: |
import random
i = random.randint(1, 100)
print(i)
- name: print-message
inputs:
parameters:
- name: message
container:
image: alpine:latest
command: [sh, -c]
args: ["echo result was: {{inputs.parameters.message}}"]
`
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: scripts-python-
spec:
entrypoint: python-script-example
templates:
- name: python-script-example
steps:
- - name: generate
template: gen-random-int
- - name: print
template: print-message
arguments:
parameters:
- name: message
value: "{{steps.generate.outputs.result}}"
- name: gen-random-int
script:
image: python:alpine3.6
command: [python]
source: |
import random
i = random.randint(1, 100)
print(i)
- name: print-message
inputs:
parameters:
- name: message
container:
image: alpine:latest
command: [sh, -c]
args: ["echo result was: {{inputs.parameters.message}}"]
`

// These tests are written in BDD-style using Ginkgo framework. Refer to
// http://onsi.github.io/ginkgo to learn more.
Expand Down
3 changes: 3 additions & 0 deletions apis/addon/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// +k8s:deepcopy-gen=package
// +groupName=addonmgr.keikoproj.io
package v1alpha1
23 changes: 23 additions & 0 deletions apis/addon/v1alpha1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
)

// SchemeGroupVersion is group version used to register these objects
var (
SchemeGroupVersion = schema.GroupVersion{Group: "addonmgr.keikoproj.io", Version: "v1alpha1"}
AddonSchemaGroupVersionKind = schema.GroupVersionKind{Group: "addonmgr.keikoproj.io", Version: "v1alpha1", Kind: "Addon"}
)

// Kind takes an unqualified kind and returns back a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}

// Resource takes an unqualified resource and returns a Group-qualified GroupResource.
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

// Compitability, temp revert
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var _ = BeforeSuite(func(done Done) {
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
}

err := SchemeBuilder.AddToScheme(scheme.Scheme)
err := AddToScheme(scheme.Scheme)
Expect(err).NotTo(HaveOccurred())

cfg, err = testEnv.Start()
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion controllers/addon_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

addonmgrv1alpha1 "github.com/keikoproj/addon-manager/api/v1alpha1"
addonmgrv1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1"
"github.com/keikoproj/addon-manager/pkg/addon"
"github.com/keikoproj/addon-manager/pkg/common"
"github.com/keikoproj/addon-manager/pkg/workflows"
Expand Down
2 changes: 1 addition & 1 deletion controllers/addon_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/scheme"

"github.com/keikoproj/addon-manager/api/v1alpha1"
"github.com/keikoproj/addon-manager/apis/addon/v1alpha1"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion controllers/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

addonmgrv1alpha1 "github.com/keikoproj/addon-manager/api/v1alpha1"
addonmgrv1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/client"

appsv1 "k8s.io/api/apps/v1"
Expand Down
2 changes: 1 addition & 1 deletion controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

addonmgrv1alpha1 "github.com/keikoproj/addon-manager/api/v1alpha1"
addonmgrv1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1"
// +kubebuilder:scaffold:imports
)

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"

wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
addonmgrv1alpha1 "github.com/keikoproj/addon-manager/api/v1alpha1"
addonmgrv1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1"
"github.com/keikoproj/addon-manager/controllers"
"github.com/keikoproj/addon-manager/pkg/common"
"github.com/keikoproj/addon-manager/pkg/version"
Expand Down
2 changes: 1 addition & 1 deletion pkg/addon/addon_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/dynamic"

addonmgrv1alpha1 "github.com/keikoproj/addon-manager/api/v1alpha1"
addonmgrv1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1"
"github.com/keikoproj/addon-manager/pkg/common"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/addon/addon_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/dynamic/fake"

addonmgrv1alpha1 "github.com/keikoproj/addon-manager/api/v1alpha1"
addonmgrv1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1"
)

var dynClient = fake.NewSimpleDynamicClient(runtime.NewScheme())
Expand Down
5 changes: 3 additions & 2 deletions pkg/addon/addon_version_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
package addon

import (
"github.com/Masterminds/semver/v3"
addonmgrv1alpha1 "github.com/keikoproj/addon-manager/api/v1alpha1"
"sync"

"github.com/Masterminds/semver/v3"
addonmgrv1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1"
)

// VersionCacheClient interface clients must implement for addon version cache.
Expand Down
2 changes: 1 addition & 1 deletion pkg/addon/addon_version_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"reflect"
"testing"

addonmgrv1alpha1 "github.com/keikoproj/addon-manager/api/v1alpha1"
addonmgrv1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1"
)

func TestNewCachedClient(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/addonctl/addonctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"

addonmgrv1alpha1 "github.com/keikoproj/addon-manager/api/v1alpha1"
addonmgrv1alpha1 "github.com/keikoproj/addon-manager/apis/addon/v1alpha1"
"github.com/keikoproj/addon-manager/pkg/common"
"github.com/keikoproj/addon-manager/pkg/version"
"github.com/keikoproj/addon-manager/pkg/workflows"
Expand Down
Loading