681f75ddd0
This PR adds license for all files. It also adds a script hack/verify-boilerplate.sh for checking whether license is set correctly. Change-Id: Ib691187f3128f6787510aa914d5c0e01e8e1b22f Signed-off-by: Pengfei Ni <feiskyer@gmail.com>
82 lines
2.4 KiB
Go
82 lines
2.4 KiB
Go
/*
|
|
Copyright (c) 2017 OpenStack Foundation.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package kubecrd
|
|
|
|
import (
|
|
"reflect"
|
|
"time"
|
|
|
|
crv1 "git.openstack.org/openstack/stackube/pkg/apis/v1"
|
|
"git.openstack.org/openstack/stackube/pkg/util"
|
|
|
|
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
|
|
apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/apimachinery/pkg/util/wait"
|
|
"k8s.io/client-go/rest"
|
|
)
|
|
|
|
const (
|
|
tenantCRDName = crv1.TenantResourcePlural + "." + crv1.GroupName
|
|
)
|
|
|
|
func CreateTenantCRD(clientset apiextensionsclient.Interface) (*apiextensionsv1beta1.CustomResourceDefinition, error) {
|
|
crd := &apiextensionsv1beta1.CustomResourceDefinition{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: tenantCRDName,
|
|
},
|
|
Spec: apiextensionsv1beta1.CustomResourceDefinitionSpec{
|
|
Group: crv1.GroupName,
|
|
Version: crv1.SchemeGroupVersion.Version,
|
|
Scope: apiextensionsv1beta1.NamespaceScoped,
|
|
Names: apiextensionsv1beta1.CustomResourceDefinitionNames{
|
|
Plural: crv1.TenantResourcePlural,
|
|
Kind: reflect.TypeOf(crv1.Tenant{}).Name(),
|
|
},
|
|
},
|
|
}
|
|
_, err := clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// wait for CRD being established
|
|
if err = util.WaitForCRDReady(clientset, tenantCRDName); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return crd, nil
|
|
}
|
|
}
|
|
|
|
func WaitForTenantInstanceProcessed(tenantClient *rest.RESTClient, name string) error {
|
|
return wait.Poll(100*time.Millisecond, 10*time.Second, func() (bool, error) {
|
|
var tenant crv1.Tenant
|
|
err := tenantClient.Get().
|
|
Resource(crv1.TenantResourcePlural).
|
|
// namespace and tenant has same name
|
|
Namespace(name).
|
|
Name(name).
|
|
Do().Into(&tenant)
|
|
|
|
if err == nil && tenant.Status.State == crv1.TenantActive {
|
|
return true, nil
|
|
}
|
|
|
|
return false, err
|
|
})
|
|
}
|