Skip to content

Commit

Permalink
CAPI: Stop panicking in newMachineController
Browse files Browse the repository at this point in the history
  • Loading branch information
enxebre authored and detiber committed Jun 1, 2020
1 parent 9cd7d97 commit fd59e23
Showing 1 changed file with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ const (
nodeProviderIDIndex = "nodeProviderIDIndex"
defaultCAPIGroup = "cluster.x-k8s.io"
// CAPIGroupEnvVar contains the environment variable name which allows overriding defaultCAPIGroup.
CAPIGroupEnvVar = "CAPI_GROUP"
CAPIGroupEnvVar = "CAPI_GROUP"
resourceNameMachine = "machines"
resourceNameMachineSet = "machinesets"
resourceNameMachineDeployment = "machinedeployments"
)

// machineController watches for Nodes, Machines, MachineSets and
Expand Down Expand Up @@ -301,32 +304,33 @@ func newMachineController(
CAPIGroup := getCAPIGroup()
CAPIVersion, err := getAPIGroupPreferredVersion(discoveryclient, CAPIGroup)
if err != nil {
panic("CAPIVersion")
return nil, fmt.Errorf("could not find preferred version for CAPI group %q: %v", CAPIGroup, err)
}
klog.Infof("Using version %q for API group %q", CAPIVersion, CAPIGroup)

machineDeploymentResource, _ := schema.ParseResourceArg(fmt.Sprintf("machinedeployments.%v.%v", CAPIVersion, CAPIGroup))
if machineDeploymentResource == nil {
panic("MachineDeployment")
gvrMachineDeployment := &schema.GroupVersionResource{
Group: CAPIGroup,
Version: CAPIVersion,
Resource: resourceNameMachineDeployment,
}
machineDeploymentInformer := informerFactory.ForResource(*gvrMachineDeployment)
machineDeploymentInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{})

machineSetResource, _ := schema.ParseResourceArg(fmt.Sprintf("machinesets.%v.%v", CAPIVersion, CAPIGroup))
if machineSetResource == nil {
panic("MachineSetResource")
gvrMachineSet := &schema.GroupVersionResource{
Group: CAPIGroup,
Version: CAPIVersion,
Resource: resourceNameMachineSet,
}
machineSetInformer := informerFactory.ForResource(*gvrMachineSet)
machineSetInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{})

machineResource, _ := schema.ParseResourceArg(fmt.Sprintf("machines.%v.%v", CAPIVersion, CAPIGroup))
if machineResource == nil {
panic("machineResource")
gvrMachine := &schema.GroupVersionResource{
Group: CAPIGroup,
Version: CAPIVersion,
Resource: resourceNameMachine,
}

machineInformer := informerFactory.ForResource(*machineResource)
machineSetInformer := informerFactory.ForResource(*machineSetResource)
machineDeploymentInformer := informerFactory.ForResource(*machineDeploymentResource)

machineInformer := informerFactory.ForResource(*gvrMachine)
machineInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{})
machineSetInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{})
machineDeploymentInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{})

nodeInformer := kubeInformerFactory.Core().V1().Nodes().Informer()
nodeInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{})
Expand All @@ -351,9 +355,9 @@ func newMachineController(
machineSetInformer: machineSetInformer,
nodeInformer: nodeInformer,
dynamicclient: dynamicclient,
machineSetResource: machineSetResource,
machineResource: machineResource,
machineDeploymentResource: machineDeploymentResource,
machineSetResource: gvrMachineSet,
machineResource: gvrMachine,
machineDeploymentResource: gvrMachineDeployment,
}, nil
}

Expand Down

0 comments on commit fd59e23

Please sign in to comment.