Use Kubernetes API instead of API group

This commit is contained in:
Murat Kabilov
2017-05-12 11:41:36 +02:00
parent ec3f24c3ee
commit fd449342e5
6 changed files with 46 additions and 53 deletions
+23 -6
View File
@@ -1,6 +1,9 @@
package k8sutil
import (
"fmt"
"time"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/pkg/api"
apierrors "k8s.io/client-go/pkg/api/errors"
@@ -12,6 +15,7 @@ import (
"github.bus.zalan.do/acid/postgres-operator/pkg/spec"
"github.bus.zalan.do/acid/postgres-operator/pkg/util/constants"
"github.bus.zalan.do/acid/postgres-operator/pkg/util/retryutil"
)
func RestConfig(kubeConfig string, outOfCluster bool) (*rest.Config, error) {
@@ -34,17 +38,17 @@ func ResourceNotFound(err error) bool {
}
func KubernetesRestClient(c *rest.Config) (*rest.RESTClient, error) {
c.APIPath = "/apis"
c.GroupVersion = &unversioned.GroupVersion{
Group: constants.TPRVendor,
Version: constants.TPRApiVersion,
}
c.GroupVersion = &unversioned.GroupVersion{Version: constants.K8sVersion}
c.APIPath = constants.K8sApiPath
c.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: api.Codecs}
schemeBuilder := runtime.NewSchemeBuilder(
func(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(
*c.GroupVersion,
unversioned.GroupVersion{
Group: constants.TPRVendor,
Version: constants.TPRApiVersion,
},
&spec.Postgresql{},
&spec.PostgresqlList{},
&api.ListOptions{},
@@ -56,3 +60,16 @@ func KubernetesRestClient(c *rest.Config) (*rest.RESTClient, error) {
return rest.RESTClientFor(c)
}
func WaitTPRReady(restclient rest.Interface, interval, timeout time.Duration, ns string) error {
return retryutil.Retry(interval, timeout, func() (bool, error) {
_, err := restclient.Get().RequestURI(fmt.Sprintf(constants.ListClustersURITemplate, ns)).DoRaw()
if err != nil {
if ResourceNotFound(err) { // not set up yet. wait more.
return false, nil
}
return false, err
}
return true, nil
})
}
-28
View File
@@ -1,28 +0,0 @@
package k8sutil
import (
"fmt"
"time"
"k8s.io/client-go/rest"
"github.bus.zalan.do/acid/postgres-operator/pkg/util/constants"
"github.bus.zalan.do/acid/postgres-operator/pkg/util/retryutil"
)
func listClustersURI(ns string) string {
return fmt.Sprintf("/apis/%s/%s/namespaces/%s/%s", constants.TPRVendor, constants.TPRApiVersion, ns, constants.ResourceName)
}
func WaitTPRReady(restclient rest.Interface, interval, timeout time.Duration, ns string) error {
return retryutil.Retry(interval, timeout, func() (bool, error) {
_, err := restclient.Get().RequestURI(listClustersURI(ns)).DoRaw()
if err != nil {
if ResourceNotFound(err) { // not set up yet. wait more.
return false, nil
}
return false, err
}
return true, nil
})
}