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

Create a dedicated module for api #169

Merged
merged 3 commits into from
May 10, 2021
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
3 changes: 3 additions & 0 deletions .ci/pipeline_definitions
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ etcd-druid:
preprocess: 'finalize'
release:
nextversion: 'bump_minor'
git_tags:
- ref_template: 'refs/tags/{VERSION}'
- ref_template: 'refs/tags/api/{VERSION}'
slack:
default_channel: 'internal_scp_workspace'
channel_cfgs:
Expand Down
2 changes: 1 addition & 1 deletion .ci/test
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function test_with_coverage() {
fetch_envtest_tools "$kb_root_dir"
setup_envtest_env "$kb_root_dir"

TEST_PACKAGES="api controllers"
TEST_PACKAGES="api api_tests controllers"
amshuman-kr marked this conversation as resolved.
Show resolved Hide resolved
GINKGO_COMMON_FLAGS="-r -timeout=1h0m0s --randomizeAllSpecs --randomizeSuites --failOnPending --progress"
if [ -z $COVER ] || [ "$COVER" = false ] ; then
echo "[INFO] Test coverage is disabled."
Expand Down
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ CRD_OPTIONS ?= "crd:trivialVersions=true"

.PHONY: revendor
revendor:
@cd "$(REPO_ROOT)/api" && go mod tidy
@env GO111MODULE=on go mod vendor
@env GO111MODULE=on go mod tidy
@chmod +x "$(REPO_ROOT)/vendor/github.com/gardener/gardener/hack/"*
Expand Down Expand Up @@ -64,7 +65,8 @@ deploy: manifests
# Generate manifests e.g. CRD, RBAC etc.
.PHONY: manifests
manifests: install-requirements
@controller-gen $(CRD_OPTIONS) rbac:roleName=manager-role paths="./api/...;./controllers/..." output:crd:artifacts:config=config/crd/bases
"cd $(REPO_ROOT)/api" && "$(CONTROLLER_GEN)" $(CRD_OPTIONS) paths="./..." output:crd:artifacts:config=../config/crd/bases
"$(CONTROLLER_GEN)" rbac:roleName=manager-role paths="./controllers/..."

# Run go fmt against code
.PHONY: fmt
Expand All @@ -74,12 +76,13 @@ fmt:
# Check packages
.PHONY: check
check:
@"$(REPO_ROOT)/vendor/github.com/gardener/gardener/hack/check.sh" --golangci-lint-config=./.golangci.yaml ./api/... ./pkg/... ./controllers/...
@cd "$(REPO_ROOT)/api" && "$(REPO_ROOT)/vendor/github.com/gardener/gardener/hack/check.sh" --golangci-lint-config=../.golangci.yaml ./...
@"$(REPO_ROOT)/vendor/github.com/gardener/gardener/hack/check.sh" --golangci-lint-config=./.golangci.yaml ./pkg/... ./controllers/...

# Generate code
.PHONY: generate
generate: install-requirements
@controller-gen object:headerFile=./hack/boilerplate.go.txt paths=./api/...
cd "$(REPO_ROOT)/api" && "$(CONTROLLER_GEN)" object:headerFile=../hack/boilerplate.go.txt paths=./...

# Build the docker image
.PHONY: docker-build
Expand Down
9 changes: 9 additions & 0 deletions api/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module github.com/gardener/etcd-druid/api

go 1.15

require (
gopkg.in/yaml.v2 v2.3.0 // indirect
k8s.io/api v0.19.6
k8s.io/apimachinery v0.19.6
)
173 changes: 173 additions & 0 deletions api/go.sum

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions api/v1alpha1/etcd_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,3 @@ type EtcdList struct {
metav1.ListMeta `json:"metadata,omitempty"`
Items []Etcd `json:"items"`
}

func init() {
SchemeBuilder.Register(&Etcd{}, &EtcdList{})
}
22 changes: 17 additions & 5 deletions api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,29 @@
package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

// nolint:gochecknoglobals
var (
localSchemeBuilder = &SchemeBuilder
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "druid.gardener.cloud", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
AddToScheme = localSchemeBuilder.AddToScheme
)

// Adds the list of known types to the given scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(GroupVersion,
&Etcd{},
&EtcdList{},
)
metav1.AddToGroupVersion(scheme, GroupVersion)

return nil
}
2 changes: 1 addition & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

"context"
"time"

druidv1alpha1 "github.com/gardener/etcd-druid/api/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

"k8s.io/apimachinery/pkg/api/resource"

corev1 "k8s.io/api/core/v1"
Expand All @@ -37,7 +38,7 @@ import (
var _ = Describe("Etcd", func() {
var (
key types.NamespacedName
created, fetched *Etcd
created, fetched *druidv1alpha1.Etcd
)

BeforeEach(func() {
Expand Down Expand Up @@ -65,7 +66,7 @@ var _ = Describe("Etcd", func() {
By("creating an API obj")
Expect(k8sClient.Create(context.TODO(), created)).To(Succeed())

fetched = &Etcd{}
fetched = &druidv1alpha1.Etcd{}
Expect(k8sClient.Get(context.TODO(), key, fetched)).To(Succeed())
Expect(fetched).To(Equal(created))

Expand All @@ -78,12 +79,12 @@ var _ = Describe("Etcd", func() {

})

func getEtcd(name, namespace string) *Etcd {
func getEtcd(name, namespace string) *druidv1alpha1.Etcd {
var (
clientPort int32 = 2379
serverPort int32 = 2380
backupPort int32 = 8080
metricLevel MetricsLevel = Basic
clientPort int32 = 2379
serverPort int32 = 2380
backupPort int32 = 8080
metricLevel druidv1alpha1.MetricsLevel = druidv1alpha1.Basic
)

garbageCollectionPeriod := metav1.Duration{
Expand All @@ -101,11 +102,11 @@ func getEtcd(name, namespace string) *Etcd {
deltaSnapShotMemLimit := resource.MustParse("100Mi")
quota := resource.MustParse("8Gi")
storageClass := "gardener.cloud-fast"
provider := StorageProvider("aws")
provider := druidv1alpha1.StorageProvider("aws")
prefix := "etcd-test"
garbageCollectionPolicy := GarbageCollectionPolicy(GarbageCollectionPolicyExponential)
garbageCollectionPolicy := druidv1alpha1.GarbageCollectionPolicy(druidv1alpha1.GarbageCollectionPolicyExponential)

tlsConfig := &TLSConfig{
tlsConfig := &druidv1alpha1.TLSConfig{
ClientTLSSecretRef: corev1.SecretReference{
Name: "etcd-client-tls",
},
Expand All @@ -117,12 +118,12 @@ func getEtcd(name, namespace string) *Etcd {
},
}

instance := &Etcd{
instance := &druidv1alpha1.Etcd{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: EtcdSpec{
Spec: druidv1alpha1.EtcdSpec{
Annotations: map[string]string{
"app": "etcd-statefulset",
"role": "test",
Expand All @@ -142,7 +143,7 @@ func getEtcd(name, namespace string) *Etcd {
StorageClass: &storageClass,
StorageCapacity: &storageCapacity,

Backup: BackupSpec{
Backup: druidv1alpha1.BackupSpec{
Image: &imageBR,
Port: &backupPort,
FullSnapshotSchedule: &snapshotSchedule,
Expand All @@ -161,7 +162,7 @@ func getEtcd(name, namespace string) *Etcd {
"memory": parseQuantity("128Mi"),
},
},
Store: &StoreSpec{
Store: &druidv1alpha1.StoreSpec{
SecretRef: &corev1.SecretReference{
Name: "etcd-backup",
},
Expand All @@ -170,7 +171,7 @@ func getEtcd(name, namespace string) *Etcd {
Prefix: prefix,
},
},
Etcd: EtcdConfig{
Etcd: druidv1alpha1.EtcdConfig{
Quota: &quota,
Metrics: &metricLevel,
Image: &imageEtcd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

druidv1alpha1 "github.com/gardener/etcd-druid/api/v1alpha1"

"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -57,7 +59,7 @@ var _ = BeforeSuite(func(done Done) {
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
}

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

cfg, err = testEnv.Start()
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/gardener/etcd-druid
go 1.15

require (
github.com/gardener/etcd-druid/api v0.0.0-00010101000000-000000000000
github.com/gardener/gardener v1.17.1
github.com/ghodss/yaml v1.0.0
github.com/onsi/ginkgo v1.14.1
Expand All @@ -18,6 +19,7 @@ require (
)

replace (
github.com/gardener/etcd-druid/api => ./api
k8s.io/api => k8s.io/api v0.19.6
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.19.6
k8s.io/apimachinery => k8s.io/apimachinery v0.19.6
Expand Down
Loading