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

Convert manifests + BSL api client to kubebuilder #2561

Merged
merged 34 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
540376a
kubebuilder init - minimalist version
May 14, 2020
ef80469
Add back main.go, apparently kb needs it
May 14, 2020
ce3e4b1
Tweak makefile to accomodate kubebuilder expectations
May 14, 2020
616f708
Port BSL to kubebuilder api client
May 14, 2020
09c20d5
s/cache/client bc client fetches from cache
May 20, 2020
8871dbb
So, .GetAPIReader is how we bypass the cache
May 20, 2020
f098482
Oh that's what this code was for... adding back
May 20, 2020
d987489
Tie in CRD/code generation w/ existing scripts
May 20, 2020
17c12fd
Mostly result of running update-fmt, updated file formatting
May 20, 2020
79d2d20
Just a copyright fix
May 20, 2020
88328a8
All the test fixes
May 21, 2020
e6e0f59
Add changelog + some cleanup
May 22, 2020
b3c92ea
Update backup manifest
May 27, 2020
bd2a3e6
Remove unneeded auto-generated files
Jun 3, 2020
18ddea2
Keep everything in the same (existing) package
Jun 3, 2020
de261b4
Fix/clean scripts, generated code, and calls
Jun 4, 2020
d9a4256
Clean up schema and client calls + code reviews
Jun 7, 2020
0f4572b
Move all code gen to inside builder container
Jun 11, 2020
1e884b2
Address code review
Jun 11, 2020
fd849b2
Fix imports/aliases
Jun 11, 2020
e0f8552
More code reviews
Jun 11, 2020
b7a3246
Add waitforcachesync
Jun 16, 2020
4714454
Have manager register ALL controllers
Jun 17, 2020
041adf8
Status subresource is now enabled; cleanup
Jun 17, 2020
6f72f6b
More code reviews
Jun 17, 2020
e8c830f
Clean up
Jun 17, 2020
7d51d02
Manager registers ALL controllers for restic too
Jun 18, 2020
1dcfd04
More code reviews
Jun 19, 2020
d63fb4f
Add deprecation warning/todo
Jun 19, 2020
e9fb8dd
Add documentation
Jun 19, 2020
ff7e546
Add helpful comments
Jun 19, 2020
4732d4f
Address code review
Jun 24, 2020
8160dee
More idiomatic Runnable
Jun 24, 2020
3261b32
Clean up imports
Jun 24, 2020
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
7 changes: 7 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
domain: io
repo: github.com/vmware-tanzu/velero
resources:
- group: velero
kind: BackupStorageLocation
version: v1
version: "2"
nrb marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions changelogs/unreleased/2561-carlisia
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Convert manifests + BSL api client to kubebuilder
423 changes: 423 additions & 0 deletions config/crd/bases/velero.io_backups.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ metadata:
creationTimestamp: null
name: backupstoragelocations.velero.io
spec:
additionalPrinterColumns:
- JSONPath: .status.phase
description: Backup Storage Location status such as Available/Unavailable
name: Phase
type: string
- JSONPath: .metadata.creationTimestamp
name: Age
type: date
group: velero.io
names:
kind: BackupStorageLocation
Expand All @@ -16,10 +24,12 @@ spec:
singular: backupstoragelocation
preserveUnknownFields: false
scope: Namespaced
subresources:
status: {}
validation:
openAPIV3Schema:
description: BackupStorageLocation is a location where Velero stores backup
objects.
objects
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
Expand All @@ -34,8 +44,8 @@ spec:
metadata:
type: object
spec:
description: BackupStorageLocationSpec defines the specification for a Velero
BackupStorageLocation.
description: BackupStorageLocationSpec defines the desired state of a Velero
BackupStorageLocation
properties:
accessMode:
description: AccessMode defines the permissions for the backup storage
Expand Down Expand Up @@ -81,8 +91,7 @@ spec:
- provider
type: object
status:
description: BackupStorageLocationStatus describes the current status of
a Velero BackupStorageLocation.
description: BackupStorageLocationStatus defines the observed state of BackupStorageLocation
properties:
accessMode:
description: "AccessMode is an unused field. \n Deprecated: there is
Expand Down
379 changes: 379 additions & 0 deletions config/crd/bases/velero.io_schedules.yaml

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions config/crd/crds/crds.go

Large diffs are not rendered by default.

File renamed without changes.
16 changes: 16 additions & 0 deletions config/samples/velero_v1_backupstoragelocation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: velero.io/v1
kind: BackupStorageLocation
metadata:
creationTimestamp: null
labels:
component: velero
name: default
namespace: velero
spec:
config:
region: minio
s3ForcePathStyle: "true"
s3Url: http://minio.velero.svc:9000
objectStorage:
bucket: velero
provider: aws
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.4.0
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553
golang.org/x/net v0.0.0-20200602114024-627f9648deb9
google.golang.org/grpc v1.26.0
k8s.io/api v0.17.4
k8s.io/apiextensions-apiserver v0.17.4
Expand All @@ -39,4 +39,5 @@ require (
k8s.io/client-go v0.17.4
k8s.io/klog v1.0.0
k8s.io/utils v0.0.0-20191218082557-f07c713de883 // indirect
sigs.k8s.io/controller-runtime v0.5.2
)
39 changes: 38 additions & 1 deletion go.sum

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions hack/crd-gen/main.go

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

11 changes: 7 additions & 4 deletions hack/update-generated-crd-code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ ${GOPATH}/src/k8s.io/code-generator/generate-groups.sh \
--output-base ../../.. \
$@

# Generate manifests e.g. CRD, RBAC etc.
controller-gen \
crd:crdVersions=v1beta1,preserveUnknownFields=false \
output:dir=./pkg/generated/crds/manifests \
paths=./pkg/apis/velero/v1/...
crd:crdVersions=v1beta1,preserveUnknownFields=false,trivialVersions=true \
rbac:roleName=manager-role \
paths=./pkg/apis/velero/v1/... \
paths=./pkg/controller/... \
output:crd:artifacts:config=config/crd/bases

go generate ./pkg/generated/crds
go generate ./config/crd/crds
6 changes: 3 additions & 3 deletions hack/verify-generated-crd-code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ HACK_DIR=$(dirname "${BASH_SOURCE}")
${HACK_DIR}/update-generated-crd-code.sh --verify-only

# ensure no changes to generated CRDs
if ! git diff --exit-code pkg/generated/crds/crds.go >/dev/null; then
if ! git diff --exit-code config/crd/crds/crds.go >/dev/null; then
# revert changes to state before running CRD generation to stay consistent
# with code-generator `--verify-only` option which discards generated changes
git checkout pkg/generated/crds
git checkout config/crd/bases

echo "CRD verification - failed! Generated CRDs are out-of-date, please run 'make update'."
exit 1
fi
fi
54 changes: 54 additions & 0 deletions internal/util/managercontroller/managercontroller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
Copyright 2020 the Velero contributors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// TODO(2.0) After converting all controllers to runttime-controller,
// the functions in this file will no longer be needed and should be removed.
package managercontroller

import (
"context"

"sigs.k8s.io/controller-runtime/pkg/manager"

"github.com/vmware-tanzu/velero/pkg/controller"
)

carlisia marked this conversation as resolved.
Show resolved Hide resolved
// Runnable will turn a "regular" runnable component (such as a controller)
// into a controller-runtime Runnable
func Runnable(p controller.Interface, numWorkers int) manager.Runnable {
f := func(stop <-chan struct{}) error {

// Create a cancel context for handling the stop signal.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// If a signal is received on the stop channel, cancel the
// context. This will propagate the cancel into the p.Run
// function below.
go func() {
select {
case <-stop:
cancel()
case <-ctx.Done():
}
}()

// This is a blocking call that either completes
// or is cancellable on receiving a stop signal.
return p.Run(ctx, numWorkers)
}
return manager.RunnableFunc(f)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2018 the Velero contributors.
Copyright 2017, 2020 the Velero contributors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -21,33 +21,85 @@ import (
"k8s.io/apimachinery/pkg/types"
)

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// BackupStorageLocationSpec defines the desired state of a Velero BackupStorageLocation
type BackupStorageLocationSpec struct {
// Provider is the provider of the backup storage.
Provider string `json:"provider"`

// BackupStorageLocation is a location where Velero stores backup objects.
type BackupStorageLocation struct {
metav1.TypeMeta `json:",inline"`
// Config is for provider-specific configuration fields.
// +optional
Config map[string]string `json:"config,omitempty"`

StorageType `json:",inline"`

// AccessMode defines the permissions for the backup storage location.
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`
AccessMode BackupStorageLocationAccessMode `json:"accessMode,omitempty"`

// BackupSyncPeriod defines how frequently to sync backup API objects from object storage. A value of 0 disables sync.
// +optional
// +nullable
BackupSyncPeriod *metav1.Duration `json:"backupSyncPeriod,omitempty"`
}

// BackupStorageLocationStatus defines the observed state of BackupStorageLocation
type BackupStorageLocationStatus struct {
// Phase is the current state of the BackupStorageLocation.
// +optional
Phase BackupStorageLocationPhase `json:"phase,omitempty"`

// LastSyncedTime is the last time the contents of the location were synced into
// the cluster.
// +optional
Spec BackupStorageLocationSpec `json:"spec,omitempty"`
// +nullable
LastSyncedTime *metav1.Time `json:"lastSyncedTime,omitempty"`

// LastSyncedRevision is the value of the `metadata/revision` file in the backup
// storage location the last time the BSL's contents were synced into the cluster.
//
// Deprecated: this field is no longer updated or used for detecting changes to
// the location's contents and will be removed entirely in v2.0.
// +optional
LastSyncedRevision types.UID `json:"lastSyncedRevision,omitempty"`

// AccessMode is an unused field.
//
// Deprecated: there is now an AccessMode field on the Spec and this field
// will be removed entirely as of v2.0.
// +optional
AccessMode BackupStorageLocationAccessMode `json:"accessMode,omitempty"`
}

// TODO(2.0) After converting all resources to use the runttime-controller client,
// the genclient and k8s:deepcopy markers will no longer be needed and should be removed.
// +genclient
carlisia marked this conversation as resolved.
Show resolved Hide resolved
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// +kubebuilder:object:generate=true
// +kubebuilder:storageversion
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase",description="Backup Storage Location status such as Available/Unavailable"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"

// BackupStorageLocation is a location where Velero stores backup objects
type BackupStorageLocation struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec BackupStorageLocationSpec `json:"spec,omitempty"`
Status BackupStorageLocationStatus `json:"status,omitempty"`
}

// TODO(2.0) After converting all resources to use the runttime-controller client,
// the k8s:deepcopy marker will no longer be needed and should be removed.
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true

// BackupStorageLocationList is a list of BackupStorageLocations.
// BackupStorageLocationList contains a list of BackupStorageLocation
type BackupStorageLocationList struct {
metav1.TypeMeta `json:",inline"`

// +optional
metav1.ListMeta `json:"metadata,omitempty"`

Items []BackupStorageLocation `json:"items"`
Items []BackupStorageLocation `json:"items"`
}

// StorageType represents the type of storage that a backup location uses.
Expand All @@ -70,28 +122,7 @@ type ObjectStorageLocation struct {
CACert []byte `json:"caCert,omitempty"`
}

// BackupStorageLocationSpec defines the specification for a Velero BackupStorageLocation.
type BackupStorageLocationSpec struct {
// Provider is the provider of the backup storage.
Provider string `json:"provider"`

// Config is for provider-specific configuration fields.
// +optional
Config map[string]string `json:"config,omitempty"`

StorageType `json:",inline"`

// AccessMode defines the permissions for the backup storage location.
// +optional
AccessMode BackupStorageLocationAccessMode `json:"accessMode,omitempty"`

// BackupSyncPeriod defines how frequently to sync backup API objects from object storage. A value of 0 disables sync.
// +optional
// +nullable
BackupSyncPeriod *metav1.Duration `json:"backupSyncPeriod,omitempty"`
}

// BackupStorageLocationPhase is the lifecyle phase of a Velero BackupStorageLocation.
// BackupStorageLocationPhase is the lifecycle phase of a Velero BackupStorageLocation.
// +kubebuilder:validation:Enum=Available;Unavailable
type BackupStorageLocationPhase string

Expand All @@ -117,31 +148,3 @@ const (

// TODO(2.0): remove the AccessMode field from BackupStorageLocationStatus.
// TODO(2.0): remove the LastSyncedRevision field from BackupStorageLocationStatus.

// BackupStorageLocationStatus describes the current status of a Velero BackupStorageLocation.
type BackupStorageLocationStatus struct {
// Phase is the current state of the BackupStorageLocation.
// +optional
Phase BackupStorageLocationPhase `json:"phase,omitempty"`

// LastSyncedTime is the last time the contents of the location were synced into
// the cluster.
// +optional
// +nullable
LastSyncedTime *metav1.Time `json:"lastSyncedTime,omitempty"`

// LastSyncedRevision is the value of the `metadata/revision` file in the backup
// storage location the last time the BSL's contents were synced into the cluster.
//
// Deprecated: this field is no longer updated or used for detecting changes to
// the location's contents and will be removed entirely in v2.0.
// +optional
LastSyncedRevision types.UID `json:"lastSyncedRevision,omitempty"`

// AccessMode is an unused field.
//
// Deprecated: there is now an AccessMode field on the Spec and this field
// will be removed entirely as of v2.0.
// +optional
AccessMode BackupStorageLocationAccessMode `json:"accessMode,omitempty"`
}
Loading