-
Notifications
You must be signed in to change notification settings - Fork 944
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor controller to make testing easier.
Avoid relying on Clientset structure to call Kubernetes API functions. While Clientset is a convinient "catch-all" abstraction for calling REST API related to different Kubernetes objects, it's impossible to mock. Replacing it wih the kubernetes.Interface would be quite straightforward, but would require an exra level of mocked interfaces, because of the versioning. Instead, a new interface is defined, which contains only the objects we need of the pre-defined versions. Add one more test.
- Loading branch information
1 parent
be82ab8
commit d86cccf
Showing
8 changed files
with
142 additions
and
24 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
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 |
---|---|---|
@@ -1,8 +1,41 @@ | ||
package cluster | ||
|
||
import ( | ||
"k8s.io/client-go/kubernetes" | ||
v1beta1 "k8s.io/client-go/kubernetes/typed/apps/v1beta1" | ||
v1core "k8s.io/client-go/kubernetes/typed/core/v1" | ||
extensions "k8s.io/client-go/kubernetes/typed/extensions/v1beta1" | ||
) | ||
|
||
type PostgresRole string | ||
|
||
const ( | ||
Master PostgresRole = "master" | ||
Replica PostgresRole = "replica" | ||
) | ||
|
||
type KubernetesClient struct { | ||
v1core.SecretsGetter | ||
v1core.ServicesGetter | ||
v1core.EndpointsGetter | ||
v1core.PodsGetter | ||
v1core.PersistentVolumesGetter | ||
v1core.PersistentVolumeClaimsGetter | ||
v1core.ConfigMapsGetter | ||
v1beta1.StatefulSetsGetter | ||
extensions.ThirdPartyResourcesGetter | ||
} | ||
|
||
func NewFromKubernetesInterface(src kubernetes.Interface) (c KubernetesClient) { | ||
c = KubernetesClient{} | ||
c.PodsGetter = src.CoreV1() | ||
c.ServicesGetter = src.CoreV1() | ||
c.EndpointsGetter = src.CoreV1() | ||
c.SecretsGetter = src.CoreV1() | ||
c.ConfigMapsGetter = src.CoreV1() | ||
c.PersistentVolumeClaimsGetter = src.CoreV1() | ||
c.PersistentVolumesGetter = src.CoreV1() | ||
c.StatefulSetsGetter = src.AppsV1beta1() | ||
c.ThirdPartyResourcesGetter = src.ExtensionsV1beta1() | ||
return | ||
} |
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
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