There are two ways to import resources from your cluster. These methods cannot be used simultaneously.
- Import resources from your cluster once when initializing the simulator.
- Keep importing resources from your cluster.
To use this, you need to follow these two steps in the simulator configuration:
- Set
true
toexternalImportEnabled
. - Set the path of the kubeconfig file for the your cluster to
KubeConfig
.- This feature only requires the read permission for resources.
externalImportEnabled: true
kubeConfig: "/path/to/your-cluster-kubeconfig"
To use this, you need to follow these two steps in the scheduler configuration:
- Set
true
toresourceSyncEnabled
. - Set the path of the kubeconfig file for the your cluster to
KubeConfig
.- This feature only requires the read permission for resources.
resourceSyncEnabled: true
kubeConfig: "/path/to/your-cluster-kubeconfig"
Note
When you enable resourceSyncEnabled
, adding/updating/deleting resources directly in the simulator cluster could cause a problem of syncing.
You can do them for debugging etc purposes though, make sure you reboot the simulator and the fake source cluster afterward.
We cannot simply sync all changes to Pods, because the real cluster has the scheduler, and it schedules all Pods in the cluster. If we simply synced all changes to Pods, the scheduling result would also be synced, and may conflicted with the decision of another scheduler which is in a fake cluster.
So, we don't sync any of updated events to scheduled Pods. Pods are synced like:
- In a real cluster, Pod-a is created
- In a fake cluster, Pod-a is created. (synced)
- In a real cluster, the scheduler schedules Pod-a to Node-a. We don't copy this change to a fake cluster.
- In a fake cluster, the scheduler, which is different one from (3), schedules Pod-a to Node-x.
It means that the scheduling results may be different between a real cluster and a fake cluster. But, it's OK. Our purpose is to create a fake cluster for testing the scheduling, which gets the same load as the production cluster.
It imports the following resources, which the scheduler's default plugins take into account during scheduling.
- Pods
- Nodes
- PersistentVolumes
- PersistentVolumeClaims
- StorageClasses
If you need to, you can tweak which resources to import via the option in /simulator/cmd/simulator/simulator.go:
dic, err := di.NewDIContainer(..., syncer.Options{
// GVRsToSync is a list of GroupVersionResource that will be synced.
// If GVRsToSync is nil, defaultGVRs are used.
GVRsToSync: []schema.GroupVersionResource{
{Group: "your-group", Version: "v1", Resource: "your-custom-resources"},
}
// Actually, more options are available...
// AdditionalMutatingFunctions is a list of mutating functions that users add.
AdditionalMutatingFunctions: map[schema.GroupVersionResource]MutatingFunction{...}
// AdditionalFilteringFunctions is a list of filtering functions that users add.
AdditionalFilteringFunctions: map[schema.GroupVersionResource]FilteringFunction{...}
})
Note
Right now, one-shot import cannot change which resources to import.