Skip to content

Commit

Permalink
Fix bug w/ disabling controllers + fix test + clean up
Browse files Browse the repository at this point in the history
Signed-off-by: Carlisia <carlisia@vmware.com>
  • Loading branch information
Carlisia committed Aug 21, 2020
1 parent 5e07d94 commit b05f497
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
28 changes: 28 additions & 0 deletions config/samples/rbac/role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: manager-role
rules:
- apiGroups:
- velero.io
resources:
- backupstoragelocations
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- velero.io
resources:
- backupstoragelocations/status
verbs:
- get
- patch
- update
6 changes: 4 additions & 2 deletions internal/velero/serverstatusrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
"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
Expand All @@ -41,7 +43,7 @@ func (s *ServerStatus) PatchStatusProcessed(kbClient client.Client, req *velerov
req.Status.ServerVersion = buildinfo.Version
req.Status.Phase = velerov1api.ServerStatusRequestPhaseProcessed
req.Status.ProcessedTimestamp = &metav1.Time{Time: s.Clock.Now()}
req.Status.Plugins = loadPlugins(s.PluginRegistry)
req.Status.Plugins = getInstalledPluginInfo(s.PluginRegistry)

if err := kbClient.Status().Patch(ctx, req, statusPatch); err != nil {
return errors.WithStack(err)
Expand All @@ -55,7 +57,7 @@ type PluginLister interface {
List(kind framework.PluginKind) []framework.PluginIdentifier
}

func loadPlugins(pluginLister PluginLister) []velerov1api.PluginInfo {
func getInstalledPluginInfo(pluginLister PluginLister) []velerov1api.PluginInfo {
var plugins []velerov1api.PluginInfo
for _, v := range framework.AllPluginKinds() {
list := pluginLister.List(v)
Expand Down
15 changes: 7 additions & 8 deletions pkg/cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,14 +808,13 @@ func (s *server) runControllers(defaultVolumeSnapshotLocations map[string]string
s.logger.Infof("Disabling controller: %s", controllerName)
delete(enabledControllers, controllerName)
} else {
s.logger.Fatalf("Invalid value for --disable-controllers flag provided: %s. Valid values are: %s", controllerName, strings.Join(disableControllerList, ","))
}
}
// remove disabled runtime type controllers
for _, controllerName := range s.config.disabledControllers {
if _, ok := enabledRuntimeControllers[controllerName]; ok {
s.logger.Infof("Disabling controller: %s", controllerName)
delete(enabledRuntimeControllers, controllerName)
// maybe it is a runtime type controllers, so attempt to remove that
if _, ok := enabledRuntimeControllers[controllerName]; ok {
s.logger.Infof("Disabling controller: %s", controllerName)
delete(enabledRuntimeControllers, controllerName)
} else {
s.logger.Fatalf("Invalid value for --disable-controllers flag provided: %s. Valid values are: %s", controllerName, strings.Join(disableControllerList, ","))
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/server_status_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ var _ = Describe("Server Status Request Reconciler", func() {
},
},
},
expectedErrMsg: "unexpected ServerStatusRequest phase \"an-invalid-phase\"",
expectedErrMsg: "unexpected ServerStatusRequest phase",
expectedRequeue: ctrl.Result{Requeue: false, RequeueAfter: 0},
},
}
Expand Down

0 comments on commit b05f497

Please sign in to comment.