-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate ServerStatusRequest controller and resource to kubebuilder (#…
…2838) * Convert ServerStatusRequest controller to controller-runtime Signed-off-by: Carlisia <carlisia@vmware.com> * Add select stm Signed-off-by: Carlisia <carlisia@vmware.com> * Fixed status patch bug Signed-off-by: Carlisia <carlisia@vmware.com> * Add mgr start Signed-off-by: Carlisia <carlisia@vmware.com> * Trying to sync Signed-off-by: Carlisia <carlisia@vmware.com> * Clean async now Signed-off-by: Carlisia <carlisia@vmware.com> * Clean up + move context out Signed-off-by: Carlisia <carlisia@vmware.com> * Bug: not closing the channel Signed-off-by: Carlisia <carlisia@vmware.com> * Clean up some tests Signed-off-by: Carlisia <carlisia@vmware.com> * Much better way to fetch an update using a backoff loop Signed-off-by: Carlisia <carlisia@vmware.com> * Even better way to retry: use apimachinery lib Signed-off-by: Carlisia <carlisia@vmware.com> * Refactor controller + add test Signed-off-by: Carlisia <carlisia@vmware.com> * partially fix unit tests Signed-off-by: Ashish Amarnath <ashisham@vmware.com> * Fix and add tests Signed-off-by: Carlisia <carlisia@vmware.com> * Add changelog Signed-off-by: Carlisia <carlisia@vmware.com> * Add ability to disable the controller + cleanups Signed-off-by: Carlisia <carlisia@vmware.com> * Fix bug w/ disabling controllers + fix test + clean up Signed-off-by: Carlisia <carlisia@vmware.com> * Move role.yaml to the correct folder Signed-off-by: Carlisia <carlisia@vmware.com> * Add sample serverstatusrequest.yaml Signed-off-by: Carlisia <carlisia@vmware.com> * Add requeue + better formatting Signed-off-by: Carlisia <carlisia@vmware.com> * Increase # of max concurrent reconciles Signed-off-by: Carlisia <carlisia@vmware.com> Co-authored-by: Ashish Amarnath <ashisham@vmware.com>
- Loading branch information
1 parent
aed504a
commit c952932
Showing
19 changed files
with
760 additions
and
383 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Convert ServerStatusRequest controller to kubebuilder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
apiVersion: velero.io/v1 | ||
kind: ServerStatusRequest | ||
metadata: | ||
creationTimestamp: "2020-08-21T15:34:34Z" | ||
generateName: velero-cli- | ||
generation: 1 | ||
name: velero-cli-6wkzd | ||
namespace: velero | ||
resourceVersion: "544749" | ||
selfLink: /apis/velero.io/v1/namespaces/velero/serverstatusrequests/velero-cli-6wkzd | ||
uid: 335ea64e-1904-40ec-8106-1f2b22e9540e | ||
spec: {} | ||
status: | ||
phase: Processed | ||
plugins: | ||
- kind: ObjectStore | ||
name: velero.io/aws | ||
- kind: VolumeSnapshotter | ||
name: velero.io/aws | ||
- kind: BackupItemAction | ||
name: velero.io/crd-remap-version | ||
- kind: BackupItemAction | ||
name: velero.io/pod | ||
processedTimestamp: "2020-08-21T15:34:34Z" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
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. | ||
*/ | ||
|
||
package velero | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pkg/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/util/clock" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" | ||
"github.com/vmware-tanzu/velero/pkg/buildinfo" | ||
"github.com/vmware-tanzu/velero/pkg/plugin/framework" | ||
) | ||
|
||
// ServerStatus holds information for retrieving installed | ||
// plugins and for updating the ServerStatusRequest timestamp. | ||
type ServerStatus struct { | ||
PluginRegistry PluginLister | ||
Clock clock.Clock | ||
} | ||
|
||
// PatchStatusProcessed patches status fields, including loading the plugin info, and updates | ||
// the ServerStatusRequest.Status.Phase to ServerStatusRequestPhaseProcessed. | ||
func (s *ServerStatus) PatchStatusProcessed(kbClient client.Client, req *velerov1api.ServerStatusRequest, ctx context.Context) error { | ||
statusPatch := client.MergeFrom(req.DeepCopyObject()) | ||
req.Status.ServerVersion = buildinfo.Version | ||
req.Status.Phase = velerov1api.ServerStatusRequestPhaseProcessed | ||
req.Status.ProcessedTimestamp = &metav1.Time{Time: s.Clock.Now()} | ||
req.Status.Plugins = getInstalledPluginInfo(s.PluginRegistry) | ||
|
||
if err := kbClient.Status().Patch(ctx, req, statusPatch); err != nil { | ||
return errors.WithStack(err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
type PluginLister interface { | ||
// List returns all PluginIdentifiers for kind. | ||
List(kind framework.PluginKind) []framework.PluginIdentifier | ||
} | ||
|
||
func getInstalledPluginInfo(pluginLister PluginLister) []velerov1api.PluginInfo { | ||
var plugins []velerov1api.PluginInfo | ||
for _, v := range framework.AllPluginKinds() { | ||
list := pluginLister.List(v) | ||
for _, plugin := range list { | ||
pluginInfo := velerov1api.PluginInfo{ | ||
Name: plugin.Name, | ||
Kind: plugin.Kind.String(), | ||
} | ||
plugins = append(plugins, pluginInfo) | ||
} | ||
} | ||
return plugins | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.