26
pkg/apis/addtoscheme_storage_v1alpha1.go
Normal file
26
pkg/apis/addtoscheme_storage_v1alpha1.go
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
Copyright 2019 The KubeSphere authors.
|
||||
|
||||
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 apis
|
||||
|
||||
import (
|
||||
storagev1alpha1 "kubesphere.io/kubesphere/pkg/apis/storage/v1alpha1"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// Register the types with the Scheme so the components can map objects to GroupVersionKinds and back
|
||||
AddToSchemes = append(AddToSchemes, storagev1alpha1.SchemeBuilder.AddToScheme)
|
||||
}
|
||||
29
pkg/apis/storage/crdinstall/install.go
Normal file
29
pkg/apis/storage/crdinstall/install.go
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
|
||||
Copyright 2019 The KubeSphere Authors.
|
||||
|
||||
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 install
|
||||
|
||||
import (
|
||||
k8sruntime "k8s.io/apimachinery/pkg/runtime"
|
||||
urlruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
storagev1alpha1 "kubesphere.io/kubesphere/pkg/apis/storage/v1alpha1"
|
||||
)
|
||||
|
||||
func Install(scheme *k8sruntime.Scheme) {
|
||||
urlruntime.Must(storagev1alpha1.AddToScheme(scheme))
|
||||
urlruntime.Must(scheme.SetVersionPriority(storagev1alpha1.SchemeGroupVersion))
|
||||
}
|
||||
18
pkg/apis/storage/group.go
Normal file
18
pkg/apis/storage/group.go
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
Copyright 2019 The KubeSphere authors.
|
||||
|
||||
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 storage contains storage API versions
|
||||
package storage
|
||||
88
pkg/apis/storage/v1alpha1/capability_types.go
Normal file
88
pkg/apis/storage/v1alpha1/capability_types.go
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
Copyright 2019 The KubeSphere authors.
|
||||
|
||||
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 v1alpha1
|
||||
|
||||
import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
type ExpandMode string
|
||||
|
||||
const (
|
||||
ExpandModeUnknown ExpandMode = "UNKNOWN"
|
||||
ExpandModeOffline ExpandMode = "OFFLINE"
|
||||
ExpandModeOnline ExpandMode = "ONLINE"
|
||||
)
|
||||
|
||||
// +genclient
|
||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||
// +genclient:noStatus
|
||||
// +genclient:nonNamespaced
|
||||
|
||||
// StorageClassCapability is the Schema for the storage class capability API
|
||||
// +k8s:openapi-gen=true
|
||||
type StorageClassCapability struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ObjectMeta `json:"metadata,omitempty"`
|
||||
|
||||
Spec StorageClassCapabilitySpec `json:"spec"`
|
||||
}
|
||||
|
||||
// StorageClassCapabilitySpec defines the desired state of StorageClassCapability
|
||||
type StorageClassCapabilitySpec struct {
|
||||
Provisioner string `json:"provisioner"`
|
||||
Features StorageClassCapabilitySpecFeatures `json:"features"`
|
||||
}
|
||||
|
||||
// StorageClassCapabilitySpecFeatures describe storage class features
|
||||
type StorageClassCapabilitySpecFeatures struct {
|
||||
Topology bool `json:"topology"`
|
||||
Volume StorageClassCapabilitySpecFeaturesVolume `json:"volume"`
|
||||
Snapshot StorageClassCapabilitySpecFeaturesSnapshot `json:"snapshot"`
|
||||
}
|
||||
|
||||
// StorageClassCapabilitySpecFeaturesVolume describe volume features
|
||||
type StorageClassCapabilitySpecFeaturesVolume struct {
|
||||
Create bool `json:"create"`
|
||||
Attach bool `json:"attach"`
|
||||
List bool `json:"list"`
|
||||
Clone bool `json:"clone"`
|
||||
Stats bool `json:"stats"`
|
||||
Expand ExpandMode `json:"expandMode"`
|
||||
}
|
||||
|
||||
// StorageClassCapabilitySpecFeaturesSnapshot describe snapshot features
|
||||
type StorageClassCapabilitySpecFeaturesSnapshot struct {
|
||||
Create bool `json:"create"`
|
||||
List bool `json:"list"`
|
||||
}
|
||||
|
||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||
// +genclient:nonNamespaced
|
||||
|
||||
// StorageClassCapabilityList contains a list of StorageClassCapability
|
||||
type StorageClassCapabilityList struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ListMeta `json:"metadata"`
|
||||
Items []StorageClassCapability `json:"items"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
SchemeBuilder.Register(
|
||||
&StorageClassCapability{},
|
||||
&StorageClassCapabilityList{})
|
||||
}
|
||||
23
pkg/apis/storage/v1alpha1/doc.go
Normal file
23
pkg/apis/storage/v1alpha1/doc.go
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
Copyright 2019 The KubeSphere authors.
|
||||
|
||||
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 v1alpha1 contains API Schema definitions for the storage v1alpha1 API group
|
||||
// +k8s:openapi-gen=true
|
||||
// +k8s:deepcopy-gen=package,register
|
||||
// +k8s:conversion-gen=kubesphere.io/kubesphere/pkg/apis/storage
|
||||
// +k8s:defaulter-gen=TypeMeta
|
||||
// +groupName=storage.kubesphere.io
|
||||
package v1alpha1
|
||||
46
pkg/apis/storage/v1alpha1/register.go
Normal file
46
pkg/apis/storage/v1alpha1/register.go
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
Copyright 2019 The KubeSphere authors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
// NOTE: Boilerplate only. Ignore this file.
|
||||
|
||||
// Package v1alpha1 contains API Schema definitions for the storage v1alpha1 API group
|
||||
// +k8s:openapi-gen=true
|
||||
// +k8s:deepcopy-gen=package,register
|
||||
// +k8s:conversion-gen=kubesphere.io/kubesphere/pkg/apis/storage
|
||||
// +k8s:defaulter-gen=TypeMeta
|
||||
// +groupName=storage.kubesphere.io
|
||||
package v1alpha1
|
||||
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"sigs.k8s.io/controller-runtime/pkg/runtime/scheme"
|
||||
)
|
||||
|
||||
var (
|
||||
// SchemeGroupVersion is group version used to register these objects
|
||||
SchemeGroupVersion = schema.GroupVersion{Group: "storage.kubesphere.io", Version: "v1alpha1"}
|
||||
|
||||
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
|
||||
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
|
||||
|
||||
// AddToScheme is required by pkg/client/...
|
||||
AddToScheme = SchemeBuilder.AddToScheme
|
||||
)
|
||||
|
||||
// Resource is required by pkg/client/listers/...
|
||||
func Resource(resource string) schema.GroupResource {
|
||||
return SchemeGroupVersion.WithResource(resource).GroupResource()
|
||||
}
|
||||
152
pkg/apis/storage/v1alpha1/zz_generated.deepcopy.go
generated
Normal file
152
pkg/apis/storage/v1alpha1/zz_generated.deepcopy.go
generated
Normal file
@@ -0,0 +1,152 @@
|
||||
// +build !ignore_autogenerated
|
||||
|
||||
/*
|
||||
Copyright The Kubernetes Authors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
// Code generated by deepcopy-gen. DO NOT EDIT.
|
||||
|
||||
package v1alpha1
|
||||
|
||||
import (
|
||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
||||
)
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *StorageClassCapability) DeepCopyInto(out *StorageClassCapability) {
|
||||
*out = *in
|
||||
out.TypeMeta = in.TypeMeta
|
||||
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
|
||||
out.Spec = in.Spec
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StorageClassCapability.
|
||||
func (in *StorageClassCapability) DeepCopy() *StorageClassCapability {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(StorageClassCapability)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
||||
func (in *StorageClassCapability) DeepCopyObject() runtime.Object {
|
||||
if c := in.DeepCopy(); c != nil {
|
||||
return c
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *StorageClassCapabilityList) DeepCopyInto(out *StorageClassCapabilityList) {
|
||||
*out = *in
|
||||
out.TypeMeta = in.TypeMeta
|
||||
in.ListMeta.DeepCopyInto(&out.ListMeta)
|
||||
if in.Items != nil {
|
||||
in, out := &in.Items, &out.Items
|
||||
*out = make([]StorageClassCapability, len(*in))
|
||||
for i := range *in {
|
||||
(*in)[i].DeepCopyInto(&(*out)[i])
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StorageClassCapabilityList.
|
||||
func (in *StorageClassCapabilityList) DeepCopy() *StorageClassCapabilityList {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(StorageClassCapabilityList)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
||||
func (in *StorageClassCapabilityList) DeepCopyObject() runtime.Object {
|
||||
if c := in.DeepCopy(); c != nil {
|
||||
return c
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *StorageClassCapabilitySpec) DeepCopyInto(out *StorageClassCapabilitySpec) {
|
||||
*out = *in
|
||||
out.Features = in.Features
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StorageClassCapabilitySpec.
|
||||
func (in *StorageClassCapabilitySpec) DeepCopy() *StorageClassCapabilitySpec {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(StorageClassCapabilitySpec)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *StorageClassCapabilitySpecFeatures) DeepCopyInto(out *StorageClassCapabilitySpecFeatures) {
|
||||
*out = *in
|
||||
out.Volume = in.Volume
|
||||
out.Snapshot = in.Snapshot
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StorageClassCapabilitySpecFeatures.
|
||||
func (in *StorageClassCapabilitySpecFeatures) DeepCopy() *StorageClassCapabilitySpecFeatures {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(StorageClassCapabilitySpecFeatures)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *StorageClassCapabilitySpecFeaturesSnapshot) DeepCopyInto(out *StorageClassCapabilitySpecFeaturesSnapshot) {
|
||||
*out = *in
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProvisionerCapabilitySpecFeaturesSnapshot.
|
||||
func (in *StorageClassCapabilitySpecFeaturesSnapshot) DeepCopy() *StorageClassCapabilitySpecFeaturesSnapshot {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(StorageClassCapabilitySpecFeaturesSnapshot)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *StorageClassCapabilitySpecFeaturesVolume) DeepCopyInto(out *StorageClassCapabilitySpecFeaturesVolume) {
|
||||
*out = *in
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProvisionerCapabilitySpecFeaturesVolume.
|
||||
func (in *StorageClassCapabilitySpecFeaturesVolume) DeepCopy() *StorageClassCapabilitySpecFeaturesVolume {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(StorageClassCapabilitySpecFeaturesVolume)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
@@ -30,6 +30,7 @@ import (
|
||||
iamv1alpha2 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/iam/v1alpha2"
|
||||
networkv1alpha1 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/network/v1alpha1"
|
||||
servicemeshv1alpha2 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/servicemesh/v1alpha2"
|
||||
storagev1alpha1 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/storage/v1alpha1"
|
||||
tenantv1alpha1 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/tenant/v1alpha1"
|
||||
tenantv1alpha2 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/tenant/v1alpha2"
|
||||
)
|
||||
@@ -42,6 +43,7 @@ type Interface interface {
|
||||
IamV1alpha2() iamv1alpha2.IamV1alpha2Interface
|
||||
NetworkV1alpha1() networkv1alpha1.NetworkV1alpha1Interface
|
||||
ServicemeshV1alpha2() servicemeshv1alpha2.ServicemeshV1alpha2Interface
|
||||
StorageV1alpha1() storagev1alpha1.StorageV1alpha1Interface
|
||||
TenantV1alpha1() tenantv1alpha1.TenantV1alpha1Interface
|
||||
TenantV1alpha2() tenantv1alpha2.TenantV1alpha2Interface
|
||||
}
|
||||
@@ -56,6 +58,7 @@ type Clientset struct {
|
||||
iamV1alpha2 *iamv1alpha2.IamV1alpha2Client
|
||||
networkV1alpha1 *networkv1alpha1.NetworkV1alpha1Client
|
||||
servicemeshV1alpha2 *servicemeshv1alpha2.ServicemeshV1alpha2Client
|
||||
storageV1alpha1 *storagev1alpha1.StorageV1alpha1Client
|
||||
tenantV1alpha1 *tenantv1alpha1.TenantV1alpha1Client
|
||||
tenantV1alpha2 *tenantv1alpha2.TenantV1alpha2Client
|
||||
}
|
||||
@@ -90,6 +93,11 @@ func (c *Clientset) ServicemeshV1alpha2() servicemeshv1alpha2.ServicemeshV1alpha
|
||||
return c.servicemeshV1alpha2
|
||||
}
|
||||
|
||||
// StorageV1alpha1 retrieves the StorageV1alpha1Client
|
||||
func (c *Clientset) StorageV1alpha1() storagev1alpha1.StorageV1alpha1Interface {
|
||||
return c.storageV1alpha1
|
||||
}
|
||||
|
||||
// TenantV1alpha1 retrieves the TenantV1alpha1Client
|
||||
func (c *Clientset) TenantV1alpha1() tenantv1alpha1.TenantV1alpha1Interface {
|
||||
return c.tenantV1alpha1
|
||||
@@ -145,6 +153,10 @@ func NewForConfig(c *rest.Config) (*Clientset, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cs.storageV1alpha1, err = storagev1alpha1.NewForConfig(&configShallowCopy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cs.tenantV1alpha1, err = tenantv1alpha1.NewForConfig(&configShallowCopy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -171,6 +183,7 @@ func NewForConfigOrDie(c *rest.Config) *Clientset {
|
||||
cs.iamV1alpha2 = iamv1alpha2.NewForConfigOrDie(c)
|
||||
cs.networkV1alpha1 = networkv1alpha1.NewForConfigOrDie(c)
|
||||
cs.servicemeshV1alpha2 = servicemeshv1alpha2.NewForConfigOrDie(c)
|
||||
cs.storageV1alpha1 = storagev1alpha1.NewForConfigOrDie(c)
|
||||
cs.tenantV1alpha1 = tenantv1alpha1.NewForConfigOrDie(c)
|
||||
cs.tenantV1alpha2 = tenantv1alpha2.NewForConfigOrDie(c)
|
||||
|
||||
@@ -187,6 +200,7 @@ func New(c rest.Interface) *Clientset {
|
||||
cs.iamV1alpha2 = iamv1alpha2.New(c)
|
||||
cs.networkV1alpha1 = networkv1alpha1.New(c)
|
||||
cs.servicemeshV1alpha2 = servicemeshv1alpha2.New(c)
|
||||
cs.storageV1alpha1 = storagev1alpha1.New(c)
|
||||
cs.tenantV1alpha1 = tenantv1alpha1.New(c)
|
||||
cs.tenantV1alpha2 = tenantv1alpha2.New(c)
|
||||
|
||||
|
||||
@@ -37,6 +37,8 @@ import (
|
||||
fakenetworkv1alpha1 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/network/v1alpha1/fake"
|
||||
servicemeshv1alpha2 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/servicemesh/v1alpha2"
|
||||
fakeservicemeshv1alpha2 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/servicemesh/v1alpha2/fake"
|
||||
storagev1alpha1 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/storage/v1alpha1"
|
||||
fakestoragev1alpha1 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/storage/v1alpha1/fake"
|
||||
tenantv1alpha1 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/tenant/v1alpha1"
|
||||
faketenantv1alpha1 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/tenant/v1alpha1/fake"
|
||||
tenantv1alpha2 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/tenant/v1alpha2"
|
||||
@@ -120,6 +122,11 @@ func (c *Clientset) ServicemeshV1alpha2() servicemeshv1alpha2.ServicemeshV1alpha
|
||||
return &fakeservicemeshv1alpha2.FakeServicemeshV1alpha2{Fake: &c.Fake}
|
||||
}
|
||||
|
||||
// StorageV1alpha1 retrieves the StorageV1alpha1Client
|
||||
func (c *Clientset) StorageV1alpha1() storagev1alpha1.StorageV1alpha1Interface {
|
||||
return &fakestoragev1alpha1.FakeStorageV1alpha1{Fake: &c.Fake}
|
||||
}
|
||||
|
||||
// TenantV1alpha1 retrieves the TenantV1alpha1Client
|
||||
func (c *Clientset) TenantV1alpha1() tenantv1alpha1.TenantV1alpha1Interface {
|
||||
return &faketenantv1alpha1.FakeTenantV1alpha1{Fake: &c.Fake}
|
||||
|
||||
@@ -30,6 +30,7 @@ import (
|
||||
iamv1alpha2 "kubesphere.io/kubesphere/pkg/apis/iam/v1alpha2"
|
||||
networkv1alpha1 "kubesphere.io/kubesphere/pkg/apis/network/v1alpha1"
|
||||
servicemeshv1alpha2 "kubesphere.io/kubesphere/pkg/apis/servicemesh/v1alpha2"
|
||||
storagev1alpha1 "kubesphere.io/kubesphere/pkg/apis/storage/v1alpha1"
|
||||
tenantv1alpha1 "kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1"
|
||||
tenantv1alpha2 "kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha2"
|
||||
)
|
||||
@@ -44,6 +45,7 @@ var localSchemeBuilder = runtime.SchemeBuilder{
|
||||
iamv1alpha2.AddToScheme,
|
||||
networkv1alpha1.AddToScheme,
|
||||
servicemeshv1alpha2.AddToScheme,
|
||||
storagev1alpha1.AddToScheme,
|
||||
tenantv1alpha1.AddToScheme,
|
||||
tenantv1alpha2.AddToScheme,
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import (
|
||||
iamv1alpha2 "kubesphere.io/kubesphere/pkg/apis/iam/v1alpha2"
|
||||
networkv1alpha1 "kubesphere.io/kubesphere/pkg/apis/network/v1alpha1"
|
||||
servicemeshv1alpha2 "kubesphere.io/kubesphere/pkg/apis/servicemesh/v1alpha2"
|
||||
storagev1alpha1 "kubesphere.io/kubesphere/pkg/apis/storage/v1alpha1"
|
||||
tenantv1alpha1 "kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1"
|
||||
tenantv1alpha2 "kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha2"
|
||||
)
|
||||
@@ -44,6 +45,7 @@ var localSchemeBuilder = runtime.SchemeBuilder{
|
||||
iamv1alpha2.AddToScheme,
|
||||
networkv1alpha1.AddToScheme,
|
||||
servicemeshv1alpha2.AddToScheme,
|
||||
storagev1alpha1.AddToScheme,
|
||||
tenantv1alpha1.AddToScheme,
|
||||
tenantv1alpha2.AddToScheme,
|
||||
}
|
||||
|
||||
20
pkg/client/clientset/versioned/typed/storage/v1alpha1/doc.go
Normal file
20
pkg/client/clientset/versioned/typed/storage/v1alpha1/doc.go
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
Copyright 2019 The KubeSphere authors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
// Code generated by client-gen. DO NOT EDIT.
|
||||
|
||||
// This package has the automatically generated typed clients.
|
||||
package v1alpha1
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
Copyright 2019 The KubeSphere authors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
// Code generated by client-gen. DO NOT EDIT.
|
||||
|
||||
// Package fake has the automatically generated clients.
|
||||
package fake
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
Copyright 2019 The KubeSphere authors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
// Code generated by client-gen. DO NOT EDIT.
|
||||
|
||||
package fake
|
||||
|
||||
import (
|
||||
rest "k8s.io/client-go/rest"
|
||||
testing "k8s.io/client-go/testing"
|
||||
v1alpha1 "kubesphere.io/kubesphere/pkg/client/clientset/versioned/typed/storage/v1alpha1"
|
||||
)
|
||||
|
||||
type FakeStorageV1alpha1 struct {
|
||||
*testing.Fake
|
||||
}
|
||||
|
||||
func (c *FakeStorageV1alpha1) StorageClassCapabilities() v1alpha1.StorageClassCapabilityInterface {
|
||||
return &FakeStorageClassCapabilities{c}
|
||||
}
|
||||
|
||||
// RESTClient returns a RESTClient that is used to communicate
|
||||
// with API server by this client implementation.
|
||||
func (c *FakeStorageV1alpha1) RESTClient() rest.Interface {
|
||||
var ret *rest.RESTClient
|
||||
return ret
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
Copyright 2019 The KubeSphere authors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
// Code generated by client-gen. DO NOT EDIT.
|
||||
|
||||
package fake
|
||||
|
||||
import (
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
labels "k8s.io/apimachinery/pkg/labels"
|
||||
schema "k8s.io/apimachinery/pkg/runtime/schema"
|
||||
types "k8s.io/apimachinery/pkg/types"
|
||||
watch "k8s.io/apimachinery/pkg/watch"
|
||||
testing "k8s.io/client-go/testing"
|
||||
v1alpha1 "kubesphere.io/kubesphere/pkg/apis/storage/v1alpha1"
|
||||
)
|
||||
|
||||
// FakeStorageClassCapabilities implements StorageClassCapabilityInterface
|
||||
type FakeStorageClassCapabilities struct {
|
||||
Fake *FakeStorageV1alpha1
|
||||
}
|
||||
|
||||
var storageclasscapabilitiesResource = schema.GroupVersionResource{Group: "storage.kubesphere.io", Version: "v1alpha1", Resource: "storageclasscapabilities"}
|
||||
|
||||
var storageclasscapabilitiesKind = schema.GroupVersionKind{Group: "storage.kubesphere.io", Version: "v1alpha1", Kind: "StorageClassCapability"}
|
||||
|
||||
// Get takes name of the storageClassCapability, and returns the corresponding storageClassCapability object, and an error if there is any.
|
||||
func (c *FakeStorageClassCapabilities) Get(name string, options v1.GetOptions) (result *v1alpha1.StorageClassCapability, err error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewRootGetAction(storageclasscapabilitiesResource, name), &v1alpha1.StorageClassCapability{})
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*v1alpha1.StorageClassCapability), err
|
||||
}
|
||||
|
||||
// List takes label and field selectors, and returns the list of StorageClassCapabilities that match those selectors.
|
||||
func (c *FakeStorageClassCapabilities) List(opts v1.ListOptions) (result *v1alpha1.StorageClassCapabilityList, err error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewRootListAction(storageclasscapabilitiesResource, storageclasscapabilitiesKind, opts), &v1alpha1.StorageClassCapabilityList{})
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
label, _, _ := testing.ExtractFromListOptions(opts)
|
||||
if label == nil {
|
||||
label = labels.Everything()
|
||||
}
|
||||
list := &v1alpha1.StorageClassCapabilityList{ListMeta: obj.(*v1alpha1.StorageClassCapabilityList).ListMeta}
|
||||
for _, item := range obj.(*v1alpha1.StorageClassCapabilityList).Items {
|
||||
if label.Matches(labels.Set(item.Labels)) {
|
||||
list.Items = append(list.Items, item)
|
||||
}
|
||||
}
|
||||
return list, err
|
||||
}
|
||||
|
||||
// Watch returns a watch.Interface that watches the requested storageClassCapabilities.
|
||||
func (c *FakeStorageClassCapabilities) Watch(opts v1.ListOptions) (watch.Interface, error) {
|
||||
return c.Fake.
|
||||
InvokesWatch(testing.NewRootWatchAction(storageclasscapabilitiesResource, opts))
|
||||
}
|
||||
|
||||
// Create takes the representation of a storageClassCapability and creates it. Returns the server's representation of the storageClassCapability, and an error, if there is any.
|
||||
func (c *FakeStorageClassCapabilities) Create(storageClassCapability *v1alpha1.StorageClassCapability) (result *v1alpha1.StorageClassCapability, err error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewRootCreateAction(storageclasscapabilitiesResource, storageClassCapability), &v1alpha1.StorageClassCapability{})
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*v1alpha1.StorageClassCapability), err
|
||||
}
|
||||
|
||||
// Update takes the representation of a storageClassCapability and updates it. Returns the server's representation of the storageClassCapability, and an error, if there is any.
|
||||
func (c *FakeStorageClassCapabilities) Update(storageClassCapability *v1alpha1.StorageClassCapability) (result *v1alpha1.StorageClassCapability, err error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewRootUpdateAction(storageclasscapabilitiesResource, storageClassCapability), &v1alpha1.StorageClassCapability{})
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*v1alpha1.StorageClassCapability), err
|
||||
}
|
||||
|
||||
// Delete takes name of the storageClassCapability and deletes it. Returns an error if one occurs.
|
||||
func (c *FakeStorageClassCapabilities) Delete(name string, options *v1.DeleteOptions) error {
|
||||
_, err := c.Fake.
|
||||
Invokes(testing.NewRootDeleteAction(storageclasscapabilitiesResource, name), &v1alpha1.StorageClassCapability{})
|
||||
return err
|
||||
}
|
||||
|
||||
// DeleteCollection deletes a collection of objects.
|
||||
func (c *FakeStorageClassCapabilities) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error {
|
||||
action := testing.NewRootDeleteCollectionAction(storageclasscapabilitiesResource, listOptions)
|
||||
|
||||
_, err := c.Fake.Invokes(action, &v1alpha1.StorageClassCapabilityList{})
|
||||
return err
|
||||
}
|
||||
|
||||
// Patch applies the patch and returns the patched storageClassCapability.
|
||||
func (c *FakeStorageClassCapabilities) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.StorageClassCapability, err error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewRootPatchSubresourceAction(storageclasscapabilitiesResource, name, pt, data, subresources...), &v1alpha1.StorageClassCapability{})
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*v1alpha1.StorageClassCapability), err
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
Copyright 2019 The KubeSphere authors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
// Code generated by client-gen. DO NOT EDIT.
|
||||
|
||||
package v1alpha1
|
||||
|
||||
type StorageClassCapabilityExpansion interface{}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
Copyright 2019 The KubeSphere authors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
// Code generated by client-gen. DO NOT EDIT.
|
||||
|
||||
package v1alpha1
|
||||
|
||||
import (
|
||||
rest "k8s.io/client-go/rest"
|
||||
v1alpha1 "kubesphere.io/kubesphere/pkg/apis/storage/v1alpha1"
|
||||
"kubesphere.io/kubesphere/pkg/client/clientset/versioned/scheme"
|
||||
)
|
||||
|
||||
type StorageV1alpha1Interface interface {
|
||||
RESTClient() rest.Interface
|
||||
StorageClassCapabilitiesGetter
|
||||
}
|
||||
|
||||
// StorageV1alpha1Client is used to interact with features provided by the storage.kubesphere.io group.
|
||||
type StorageV1alpha1Client struct {
|
||||
restClient rest.Interface
|
||||
}
|
||||
|
||||
func (c *StorageV1alpha1Client) StorageClassCapabilities() StorageClassCapabilityInterface {
|
||||
return newStorageClassCapabilities(c)
|
||||
}
|
||||
|
||||
// NewForConfig creates a new StorageV1alpha1Client for the given config.
|
||||
func NewForConfig(c *rest.Config) (*StorageV1alpha1Client, error) {
|
||||
config := *c
|
||||
if err := setConfigDefaults(&config); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
client, err := rest.RESTClientFor(&config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &StorageV1alpha1Client{client}, nil
|
||||
}
|
||||
|
||||
// NewForConfigOrDie creates a new StorageV1alpha1Client for the given config and
|
||||
// panics if there is an error in the config.
|
||||
func NewForConfigOrDie(c *rest.Config) *StorageV1alpha1Client {
|
||||
client, err := NewForConfig(c)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return client
|
||||
}
|
||||
|
||||
// New creates a new StorageV1alpha1Client for the given RESTClient.
|
||||
func New(c rest.Interface) *StorageV1alpha1Client {
|
||||
return &StorageV1alpha1Client{c}
|
||||
}
|
||||
|
||||
func setConfigDefaults(config *rest.Config) error {
|
||||
gv := v1alpha1.SchemeGroupVersion
|
||||
config.GroupVersion = &gv
|
||||
config.APIPath = "/apis"
|
||||
config.NegotiatedSerializer = scheme.Codecs.WithoutConversion()
|
||||
|
||||
if config.UserAgent == "" {
|
||||
config.UserAgent = rest.DefaultKubernetesUserAgent()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RESTClient returns a RESTClient that is used to communicate
|
||||
// with API server by this client implementation.
|
||||
func (c *StorageV1alpha1Client) RESTClient() rest.Interface {
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return c.restClient
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
Copyright 2019 The KubeSphere authors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
// Code generated by client-gen. DO NOT EDIT.
|
||||
|
||||
package v1alpha1
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
types "k8s.io/apimachinery/pkg/types"
|
||||
watch "k8s.io/apimachinery/pkg/watch"
|
||||
rest "k8s.io/client-go/rest"
|
||||
v1alpha1 "kubesphere.io/kubesphere/pkg/apis/storage/v1alpha1"
|
||||
scheme "kubesphere.io/kubesphere/pkg/client/clientset/versioned/scheme"
|
||||
)
|
||||
|
||||
// StorageClassCapabilitiesGetter has a method to return a StorageClassCapabilityInterface.
|
||||
// A group's client should implement this interface.
|
||||
type StorageClassCapabilitiesGetter interface {
|
||||
StorageClassCapabilities() StorageClassCapabilityInterface
|
||||
}
|
||||
|
||||
// StorageClassCapabilityInterface has methods to work with StorageClassCapability resources.
|
||||
type StorageClassCapabilityInterface interface {
|
||||
Create(*v1alpha1.StorageClassCapability) (*v1alpha1.StorageClassCapability, error)
|
||||
Update(*v1alpha1.StorageClassCapability) (*v1alpha1.StorageClassCapability, error)
|
||||
Delete(name string, options *v1.DeleteOptions) error
|
||||
DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error
|
||||
Get(name string, options v1.GetOptions) (*v1alpha1.StorageClassCapability, error)
|
||||
List(opts v1.ListOptions) (*v1alpha1.StorageClassCapabilityList, error)
|
||||
Watch(opts v1.ListOptions) (watch.Interface, error)
|
||||
Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.StorageClassCapability, err error)
|
||||
StorageClassCapabilityExpansion
|
||||
}
|
||||
|
||||
// storageClassCapabilities implements StorageClassCapabilityInterface
|
||||
type storageClassCapabilities struct {
|
||||
client rest.Interface
|
||||
}
|
||||
|
||||
// newStorageClassCapabilities returns a StorageClassCapabilities
|
||||
func newStorageClassCapabilities(c *StorageV1alpha1Client) *storageClassCapabilities {
|
||||
return &storageClassCapabilities{
|
||||
client: c.RESTClient(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get takes name of the storageClassCapability, and returns the corresponding storageClassCapability object, and an error if there is any.
|
||||
func (c *storageClassCapabilities) Get(name string, options v1.GetOptions) (result *v1alpha1.StorageClassCapability, err error) {
|
||||
result = &v1alpha1.StorageClassCapability{}
|
||||
err = c.client.Get().
|
||||
Resource("storageclasscapabilities").
|
||||
Name(name).
|
||||
VersionedParams(&options, scheme.ParameterCodec).
|
||||
Do().
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// List takes label and field selectors, and returns the list of StorageClassCapabilities that match those selectors.
|
||||
func (c *storageClassCapabilities) List(opts v1.ListOptions) (result *v1alpha1.StorageClassCapabilityList, err error) {
|
||||
var timeout time.Duration
|
||||
if opts.TimeoutSeconds != nil {
|
||||
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
|
||||
}
|
||||
result = &v1alpha1.StorageClassCapabilityList{}
|
||||
err = c.client.Get().
|
||||
Resource("storageclasscapabilities").
|
||||
VersionedParams(&opts, scheme.ParameterCodec).
|
||||
Timeout(timeout).
|
||||
Do().
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// Watch returns a watch.Interface that watches the requested storageClassCapabilities.
|
||||
func (c *storageClassCapabilities) Watch(opts v1.ListOptions) (watch.Interface, error) {
|
||||
var timeout time.Duration
|
||||
if opts.TimeoutSeconds != nil {
|
||||
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
|
||||
}
|
||||
opts.Watch = true
|
||||
return c.client.Get().
|
||||
Resource("storageclasscapabilities").
|
||||
VersionedParams(&opts, scheme.ParameterCodec).
|
||||
Timeout(timeout).
|
||||
Watch()
|
||||
}
|
||||
|
||||
// Create takes the representation of a storageClassCapability and creates it. Returns the server's representation of the storageClassCapability, and an error, if there is any.
|
||||
func (c *storageClassCapabilities) Create(storageClassCapability *v1alpha1.StorageClassCapability) (result *v1alpha1.StorageClassCapability, err error) {
|
||||
result = &v1alpha1.StorageClassCapability{}
|
||||
err = c.client.Post().
|
||||
Resource("storageclasscapabilities").
|
||||
Body(storageClassCapability).
|
||||
Do().
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// Update takes the representation of a storageClassCapability and updates it. Returns the server's representation of the storageClassCapability, and an error, if there is any.
|
||||
func (c *storageClassCapabilities) Update(storageClassCapability *v1alpha1.StorageClassCapability) (result *v1alpha1.StorageClassCapability, err error) {
|
||||
result = &v1alpha1.StorageClassCapability{}
|
||||
err = c.client.Put().
|
||||
Resource("storageclasscapabilities").
|
||||
Name(storageClassCapability.Name).
|
||||
Body(storageClassCapability).
|
||||
Do().
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// Delete takes name of the storageClassCapability and deletes it. Returns an error if one occurs.
|
||||
func (c *storageClassCapabilities) Delete(name string, options *v1.DeleteOptions) error {
|
||||
return c.client.Delete().
|
||||
Resource("storageclasscapabilities").
|
||||
Name(name).
|
||||
Body(options).
|
||||
Do().
|
||||
Error()
|
||||
}
|
||||
|
||||
// DeleteCollection deletes a collection of objects.
|
||||
func (c *storageClassCapabilities) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error {
|
||||
var timeout time.Duration
|
||||
if listOptions.TimeoutSeconds != nil {
|
||||
timeout = time.Duration(*listOptions.TimeoutSeconds) * time.Second
|
||||
}
|
||||
return c.client.Delete().
|
||||
Resource("storageclasscapabilities").
|
||||
VersionedParams(&listOptions, scheme.ParameterCodec).
|
||||
Timeout(timeout).
|
||||
Body(options).
|
||||
Do().
|
||||
Error()
|
||||
}
|
||||
|
||||
// Patch applies the patch and returns the patched storageClassCapability.
|
||||
func (c *storageClassCapabilities) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.StorageClassCapability, err error) {
|
||||
result = &v1alpha1.StorageClassCapability{}
|
||||
err = c.client.Patch(pt).
|
||||
Resource("storageclasscapabilities").
|
||||
SubResource(subresources...).
|
||||
Name(name).
|
||||
Body(data).
|
||||
Do().
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
@@ -34,6 +34,7 @@ import (
|
||||
internalinterfaces "kubesphere.io/kubesphere/pkg/client/informers/externalversions/internalinterfaces"
|
||||
network "kubesphere.io/kubesphere/pkg/client/informers/externalversions/network"
|
||||
servicemesh "kubesphere.io/kubesphere/pkg/client/informers/externalversions/servicemesh"
|
||||
storage "kubesphere.io/kubesphere/pkg/client/informers/externalversions/storage"
|
||||
tenant "kubesphere.io/kubesphere/pkg/client/informers/externalversions/tenant"
|
||||
)
|
||||
|
||||
@@ -182,6 +183,7 @@ type SharedInformerFactory interface {
|
||||
Iam() iam.Interface
|
||||
Network() network.Interface
|
||||
Servicemesh() servicemesh.Interface
|
||||
Storage() storage.Interface
|
||||
Tenant() tenant.Interface
|
||||
}
|
||||
|
||||
@@ -205,6 +207,10 @@ func (f *sharedInformerFactory) Servicemesh() servicemesh.Interface {
|
||||
return servicemesh.New(f, f.namespace, f.tweakListOptions)
|
||||
}
|
||||
|
||||
func (f *sharedInformerFactory) Storage() storage.Interface {
|
||||
return storage.New(f, f.namespace, f.tweakListOptions)
|
||||
}
|
||||
|
||||
func (f *sharedInformerFactory) Tenant() tenant.Interface {
|
||||
return tenant.New(f, f.namespace, f.tweakListOptions)
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
v1alpha2 "kubesphere.io/kubesphere/pkg/apis/iam/v1alpha2"
|
||||
networkv1alpha1 "kubesphere.io/kubesphere/pkg/apis/network/v1alpha1"
|
||||
servicemeshv1alpha2 "kubesphere.io/kubesphere/pkg/apis/servicemesh/v1alpha2"
|
||||
storagev1alpha1 "kubesphere.io/kubesphere/pkg/apis/storage/v1alpha1"
|
||||
tenantv1alpha1 "kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1"
|
||||
tenantv1alpha2 "kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha2"
|
||||
)
|
||||
@@ -101,6 +102,10 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource
|
||||
case servicemeshv1alpha2.SchemeGroupVersion.WithResource("strategies"):
|
||||
return &genericInformer{resource: resource.GroupResource(), informer: f.Servicemesh().V1alpha2().Strategies().Informer()}, nil
|
||||
|
||||
// Group=storage.kubesphere.io, Version=v1alpha1
|
||||
case storagev1alpha1.SchemeGroupVersion.WithResource("storageclasscapabilities"):
|
||||
return &genericInformer{resource: resource.GroupResource(), informer: f.Storage().V1alpha1().StorageClassCapabilities().Informer()}, nil
|
||||
|
||||
// Group=tenant.kubesphere.io, Version=v1alpha1
|
||||
case tenantv1alpha1.SchemeGroupVersion.WithResource("workspaces"):
|
||||
return &genericInformer{resource: resource.GroupResource(), informer: f.Tenant().V1alpha1().Workspaces().Informer()}, nil
|
||||
|
||||
46
pkg/client/informers/externalversions/storage/interface.go
Normal file
46
pkg/client/informers/externalversions/storage/interface.go
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
Copyright 2019 The KubeSphere authors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
// Code generated by informer-gen. DO NOT EDIT.
|
||||
|
||||
package storage
|
||||
|
||||
import (
|
||||
internalinterfaces "kubesphere.io/kubesphere/pkg/client/informers/externalversions/internalinterfaces"
|
||||
v1alpha1 "kubesphere.io/kubesphere/pkg/client/informers/externalversions/storage/v1alpha1"
|
||||
)
|
||||
|
||||
// Interface provides access to each of this group's versions.
|
||||
type Interface interface {
|
||||
// V1alpha1 provides access to shared informers for resources in V1alpha1.
|
||||
V1alpha1() v1alpha1.Interface
|
||||
}
|
||||
|
||||
type group struct {
|
||||
factory internalinterfaces.SharedInformerFactory
|
||||
namespace string
|
||||
tweakListOptions internalinterfaces.TweakListOptionsFunc
|
||||
}
|
||||
|
||||
// New returns a new Interface.
|
||||
func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface {
|
||||
return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions}
|
||||
}
|
||||
|
||||
// V1alpha1 returns a new v1alpha1.Interface.
|
||||
func (g *group) V1alpha1() v1alpha1.Interface {
|
||||
return v1alpha1.New(g.factory, g.namespace, g.tweakListOptions)
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
Copyright 2019 The KubeSphere authors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
// Code generated by informer-gen. DO NOT EDIT.
|
||||
|
||||
package v1alpha1
|
||||
|
||||
import (
|
||||
internalinterfaces "kubesphere.io/kubesphere/pkg/client/informers/externalversions/internalinterfaces"
|
||||
)
|
||||
|
||||
// Interface provides access to all the informers in this group version.
|
||||
type Interface interface {
|
||||
// StorageClassCapabilities returns a StorageClassCapabilityInformer.
|
||||
StorageClassCapabilities() StorageClassCapabilityInformer
|
||||
}
|
||||
|
||||
type version struct {
|
||||
factory internalinterfaces.SharedInformerFactory
|
||||
namespace string
|
||||
tweakListOptions internalinterfaces.TweakListOptionsFunc
|
||||
}
|
||||
|
||||
// New returns a new Interface.
|
||||
func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface {
|
||||
return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions}
|
||||
}
|
||||
|
||||
// StorageClassCapabilities returns a StorageClassCapabilityInformer.
|
||||
func (v *version) StorageClassCapabilities() StorageClassCapabilityInformer {
|
||||
return &storageClassCapabilityInformer{factory: v.factory, tweakListOptions: v.tweakListOptions}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
Copyright 2019 The KubeSphere authors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
// Code generated by informer-gen. DO NOT EDIT.
|
||||
|
||||
package v1alpha1
|
||||
|
||||
import (
|
||||
time "time"
|
||||
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
||||
watch "k8s.io/apimachinery/pkg/watch"
|
||||
cache "k8s.io/client-go/tools/cache"
|
||||
storagev1alpha1 "kubesphere.io/kubesphere/pkg/apis/storage/v1alpha1"
|
||||
versioned "kubesphere.io/kubesphere/pkg/client/clientset/versioned"
|
||||
internalinterfaces "kubesphere.io/kubesphere/pkg/client/informers/externalversions/internalinterfaces"
|
||||
v1alpha1 "kubesphere.io/kubesphere/pkg/client/listers/storage/v1alpha1"
|
||||
)
|
||||
|
||||
// StorageClassCapabilityInformer provides access to a shared informer and lister for
|
||||
// StorageClassCapabilities.
|
||||
type StorageClassCapabilityInformer interface {
|
||||
Informer() cache.SharedIndexInformer
|
||||
Lister() v1alpha1.StorageClassCapabilityLister
|
||||
}
|
||||
|
||||
type storageClassCapabilityInformer struct {
|
||||
factory internalinterfaces.SharedInformerFactory
|
||||
tweakListOptions internalinterfaces.TweakListOptionsFunc
|
||||
}
|
||||
|
||||
// NewStorageClassCapabilityInformer constructs a new informer for StorageClassCapability type.
|
||||
// Always prefer using an informer factory to get a shared informer instead of getting an independent
|
||||
// one. This reduces memory footprint and number of connections to the server.
|
||||
func NewStorageClassCapabilityInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
|
||||
return NewFilteredStorageClassCapabilityInformer(client, resyncPeriod, indexers, nil)
|
||||
}
|
||||
|
||||
// NewFilteredStorageClassCapabilityInformer constructs a new informer for StorageClassCapability type.
|
||||
// Always prefer using an informer factory to get a shared informer instead of getting an independent
|
||||
// one. This reduces memory footprint and number of connections to the server.
|
||||
func NewFilteredStorageClassCapabilityInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer {
|
||||
return cache.NewSharedIndexInformer(
|
||||
&cache.ListWatch{
|
||||
ListFunc: func(options v1.ListOptions) (runtime.Object, error) {
|
||||
if tweakListOptions != nil {
|
||||
tweakListOptions(&options)
|
||||
}
|
||||
return client.StorageV1alpha1().StorageClassCapabilities().List(options)
|
||||
},
|
||||
WatchFunc: func(options v1.ListOptions) (watch.Interface, error) {
|
||||
if tweakListOptions != nil {
|
||||
tweakListOptions(&options)
|
||||
}
|
||||
return client.StorageV1alpha1().StorageClassCapabilities().Watch(options)
|
||||
},
|
||||
},
|
||||
&storagev1alpha1.StorageClassCapability{},
|
||||
resyncPeriod,
|
||||
indexers,
|
||||
)
|
||||
}
|
||||
|
||||
func (f *storageClassCapabilityInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
|
||||
return NewFilteredStorageClassCapabilityInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions)
|
||||
}
|
||||
|
||||
func (f *storageClassCapabilityInformer) Informer() cache.SharedIndexInformer {
|
||||
return f.factory.InformerFor(&storagev1alpha1.StorageClassCapability{}, f.defaultInformer)
|
||||
}
|
||||
|
||||
func (f *storageClassCapabilityInformer) Lister() v1alpha1.StorageClassCapabilityLister {
|
||||
return v1alpha1.NewStorageClassCapabilityLister(f.Informer().GetIndexer())
|
||||
}
|
||||
23
pkg/client/listers/storage/v1alpha1/expansion_generated.go
Normal file
23
pkg/client/listers/storage/v1alpha1/expansion_generated.go
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
Copyright 2019 The KubeSphere authors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
// Code generated by lister-gen. DO NOT EDIT.
|
||||
|
||||
package v1alpha1
|
||||
|
||||
// StorageClassCapabilityListerExpansion allows custom methods to be added to
|
||||
// StorageClassCapabilityLister.
|
||||
type StorageClassCapabilityListerExpansion interface{}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
Copyright 2019 The KubeSphere authors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
// Code generated by lister-gen. DO NOT EDIT.
|
||||
|
||||
package v1alpha1
|
||||
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
v1alpha1 "kubesphere.io/kubesphere/pkg/apis/storage/v1alpha1"
|
||||
)
|
||||
|
||||
// StorageClassCapabilityLister helps list StorageClassCapabilities.
|
||||
type StorageClassCapabilityLister interface {
|
||||
// List lists all StorageClassCapabilities in the indexer.
|
||||
List(selector labels.Selector) (ret []*v1alpha1.StorageClassCapability, err error)
|
||||
// Get retrieves the StorageClassCapability from the index for a given name.
|
||||
Get(name string) (*v1alpha1.StorageClassCapability, error)
|
||||
StorageClassCapabilityListerExpansion
|
||||
}
|
||||
|
||||
// storageClassCapabilityLister implements the StorageClassCapabilityLister interface.
|
||||
type storageClassCapabilityLister struct {
|
||||
indexer cache.Indexer
|
||||
}
|
||||
|
||||
// NewStorageClassCapabilityLister returns a new StorageClassCapabilityLister.
|
||||
func NewStorageClassCapabilityLister(indexer cache.Indexer) StorageClassCapabilityLister {
|
||||
return &storageClassCapabilityLister{indexer: indexer}
|
||||
}
|
||||
|
||||
// List lists all StorageClassCapabilities in the indexer.
|
||||
func (s *storageClassCapabilityLister) List(selector labels.Selector) (ret []*v1alpha1.StorageClassCapability, err error) {
|
||||
err = cache.ListAll(s.indexer, selector, func(m interface{}) {
|
||||
ret = append(ret, m.(*v1alpha1.StorageClassCapability))
|
||||
})
|
||||
return ret, err
|
||||
}
|
||||
|
||||
// Get retrieves the StorageClassCapability from the index for a given name.
|
||||
func (s *storageClassCapabilityLister) Get(name string) (*v1alpha1.StorageClassCapability, error) {
|
||||
obj, exists, err := s.indexer.GetByKey(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !exists {
|
||||
return nil, errors.NewNotFound(v1alpha1.Resource("storageclasscapability"), name)
|
||||
}
|
||||
return obj.(*v1alpha1.StorageClassCapability), nil
|
||||
}
|
||||
313
pkg/controller/storage/capability/capability_controller.go
Normal file
313
pkg/controller/storage/capability/capability_controller.go
Normal file
@@ -0,0 +1,313 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 The KubeSphere Authors.
|
||||
|
||||
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 capability
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
snapapi "github.com/kubernetes-csi/external-snapshotter/v2/pkg/apis/volumesnapshot/v1beta1"
|
||||
snapinformers "github.com/kubernetes-csi/external-snapshotter/v2/pkg/client/informers/externalversions/volumesnapshot/v1beta1"
|
||||
snaplisters "github.com/kubernetes-csi/external-snapshotter/v2/pkg/client/listers/volumesnapshot/v1beta1"
|
||||
v1strorage "k8s.io/api/storage/v1"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/version"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
scinformers "k8s.io/client-go/informers/storage/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
sclisters "k8s.io/client-go/listers/storage/v1"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
"k8s.io/client-go/util/workqueue"
|
||||
"k8s.io/klog"
|
||||
crdapi "kubesphere.io/kubesphere/pkg/apis/storage/v1alpha1"
|
||||
clientset "kubesphere.io/kubesphere/pkg/client/clientset/versioned"
|
||||
crdscheme "kubesphere.io/kubesphere/pkg/client/clientset/versioned/scheme"
|
||||
storageinformers "kubesphere.io/kubesphere/pkg/client/informers/externalversions/storage/v1alpha1"
|
||||
crdlisters "kubesphere.io/kubesphere/pkg/client/listers/storage/v1alpha1"
|
||||
)
|
||||
|
||||
const (
|
||||
minKubernetesVersion = "v1.17.0"
|
||||
CSIAddressFormat = "/var/lib/kubelet/plugins/%s/csi.sock"
|
||||
)
|
||||
|
||||
type csiAddressGetter func(storageClassProvisioner string) string
|
||||
|
||||
type StorageCapabilityController struct {
|
||||
k8sClient kubernetes.Interface
|
||||
storageClassCapabilityClient clientset.Interface
|
||||
storageClassLister sclisters.StorageClassLister
|
||||
storageClassSynced cache.InformerSynced
|
||||
snapshotClassLister snaplisters.VolumeSnapshotClassLister
|
||||
snapshotClassSynced cache.InformerSynced
|
||||
storageClassCapabilityLister crdlisters.StorageClassCapabilityLister
|
||||
storageClassCapabilitySynced cache.InformerSynced
|
||||
workQueue workqueue.RateLimitingInterface
|
||||
csiAddressGetter csiAddressGetter
|
||||
}
|
||||
|
||||
// This controller is responsible to watch StorageClass, SnapshotClass.
|
||||
// And then update StorageClassCapability CRD resource object to the newest status.
|
||||
func NewController(
|
||||
k8sClient kubernetes.Interface,
|
||||
storageClassCapabilityClient clientset.Interface,
|
||||
storageClassInformer scinformers.StorageClassInformer,
|
||||
snapshotClassInformer snapinformers.VolumeSnapshotClassInformer,
|
||||
storageClassCapabilityInformer storageinformers.StorageClassCapabilityInformer,
|
||||
csiAddressGetter csiAddressGetter,
|
||||
) *StorageCapabilityController {
|
||||
|
||||
utilruntime.Must(crdscheme.AddToScheme(scheme.Scheme))
|
||||
controller := &StorageCapabilityController{
|
||||
k8sClient: k8sClient,
|
||||
storageClassCapabilityClient: storageClassCapabilityClient,
|
||||
storageClassLister: storageClassInformer.Lister(),
|
||||
storageClassSynced: storageClassInformer.Informer().HasSynced,
|
||||
snapshotClassLister: snapshotClassInformer.Lister(),
|
||||
snapshotClassSynced: snapshotClassInformer.Informer().HasSynced,
|
||||
storageClassCapabilityLister: storageClassCapabilityInformer.Lister(),
|
||||
storageClassCapabilitySynced: storageClassCapabilityInformer.Informer().HasSynced,
|
||||
workQueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "StorageClasses"),
|
||||
csiAddressGetter: csiAddressGetter,
|
||||
}
|
||||
storageClassInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||
AddFunc: controller.enqueueStorageClass,
|
||||
UpdateFunc: func(old, new interface{}) {
|
||||
newStorageClass := new.(*v1strorage.StorageClass)
|
||||
oldStorageClass := old.(*v1strorage.StorageClass)
|
||||
if newStorageClass.ResourceVersion == oldStorageClass.ResourceVersion {
|
||||
return
|
||||
}
|
||||
controller.enqueueStorageClass(newStorageClass)
|
||||
},
|
||||
DeleteFunc: controller.enqueueStorageClass,
|
||||
})
|
||||
snapshotClassInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||
AddFunc: controller.enqueueSnapshotClass,
|
||||
UpdateFunc: func(old, new interface{}) {
|
||||
return
|
||||
},
|
||||
DeleteFunc: controller.enqueueSnapshotClass,
|
||||
})
|
||||
return controller
|
||||
}
|
||||
|
||||
func (c *StorageCapabilityController) Start(stopCh <-chan struct{}) error {
|
||||
return c.Run(5, stopCh)
|
||||
}
|
||||
|
||||
func (c *StorageCapabilityController) Run(threadCnt int, stopCh <-chan struct{}) error {
|
||||
defer utilruntime.HandleCrash()
|
||||
defer c.workQueue.ShutDown()
|
||||
|
||||
// Wait for the caches to be synced before starting workers
|
||||
klog.Info("Waiting for informer caches to sync")
|
||||
if ok := cache.WaitForCacheSync(stopCh, c.storageClassSynced, c.snapshotClassSynced, c.storageClassCapabilitySynced); !ok {
|
||||
return fmt.Errorf("failed to wait for caches to sync")
|
||||
}
|
||||
|
||||
for i := 0; i < threadCnt; i++ {
|
||||
go wait.Until(c.runWorker, time.Second, stopCh)
|
||||
}
|
||||
klog.Info("Started workers")
|
||||
<-stopCh
|
||||
klog.Info("Shutting down workers")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *StorageCapabilityController) enqueueStorageClass(obj interface{}) {
|
||||
storageClass := obj.(*v1strorage.StorageClass)
|
||||
if !fileExist(c.csiAddressGetter(storageClass.Provisioner)) {
|
||||
klog.V(4).Infof("CSI address of storage class: %s, provisioner :%s not exist", storageClass.Name, storageClass.Provisioner)
|
||||
return
|
||||
}
|
||||
var key string
|
||||
var err error
|
||||
if key, err = cache.MetaNamespaceKeyFunc(obj); err != nil {
|
||||
utilruntime.HandleError(err)
|
||||
return
|
||||
}
|
||||
c.workQueue.Add(key)
|
||||
}
|
||||
|
||||
func (c *StorageCapabilityController) enqueueSnapshotClass(obj interface{}) {
|
||||
snapshotClass := obj.(*snapapi.VolumeSnapshotClass)
|
||||
if !fileExist(c.csiAddressGetter(snapshotClass.Driver)) {
|
||||
klog.V(4).Infof("CSI address of snapshot class: %s, driver:%s not exist", snapshotClass.Name, snapshotClass.Driver)
|
||||
return
|
||||
}
|
||||
var key string
|
||||
var err error
|
||||
if key, err = cache.MetaNamespaceKeyFunc(obj); err != nil {
|
||||
utilruntime.HandleError(err)
|
||||
return
|
||||
}
|
||||
c.workQueue.Add(key)
|
||||
}
|
||||
|
||||
func (c *StorageCapabilityController) runWorker() {
|
||||
for c.processNextWorkItem() {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *StorageCapabilityController) processNextWorkItem() bool {
|
||||
obj, shutdown := c.workQueue.Get()
|
||||
if shutdown {
|
||||
return false
|
||||
}
|
||||
|
||||
err := func(obj interface{}) error {
|
||||
defer c.workQueue.Done(obj)
|
||||
var key string
|
||||
var ok bool
|
||||
if key, ok = obj.(string); !ok {
|
||||
c.workQueue.Forget(obj)
|
||||
utilruntime.HandleError(fmt.Errorf("expected string in workQueue but got %#v", obj))
|
||||
return nil
|
||||
}
|
||||
if err := c.syncHandler(key); err != nil {
|
||||
c.workQueue.AddRateLimited(key)
|
||||
return fmt.Errorf("error syncing '%s': %s, requeuing", key, err.Error())
|
||||
}
|
||||
c.workQueue.Forget(obj)
|
||||
klog.Infof("Successfully synced '%s'", key)
|
||||
return nil
|
||||
}(obj)
|
||||
|
||||
if err != nil {
|
||||
utilruntime.HandleError(err)
|
||||
return true
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// When creating a new storage class, the controller will create a new storage capability object.
|
||||
// When updating storage class, the controller will update or create the storage capability object.
|
||||
// When deleting storage class, the controller will delete storage capability object.
|
||||
func (c *StorageCapabilityController) syncHandler(key string) error {
|
||||
_, name, err := cache.SplitMetaNamespaceKey(key)
|
||||
if err != nil {
|
||||
utilruntime.HandleError(fmt.Errorf("invalid resource key: %s", key))
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get StorageClass
|
||||
storageClass, err := c.storageClassLister.Get(name)
|
||||
klog.V(4).Infof("Get storageClass %s: entity %v", name, storageClass)
|
||||
if err != nil {
|
||||
if errors.IsNotFound(err) {
|
||||
_, err = c.storageClassCapabilityLister.Get(name)
|
||||
if err != nil {
|
||||
if errors.IsNotFound(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
return c.storageClassCapabilityClient.StorageV1alpha1().StorageClassCapabilities().Delete(name, &metav1.DeleteOptions{})
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// Get SnapshotClass
|
||||
snapshotClassCreated := true
|
||||
_, err = c.snapshotClassLister.Get(storageClass.Name)
|
||||
if err != nil {
|
||||
if errors.IsNotFound(err) {
|
||||
snapshotClassCreated = false
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Get exist StorageClassCapability
|
||||
storageClassCapabilityExist, err := c.storageClassCapabilityLister.Get(storageClass.Name)
|
||||
if errors.IsNotFound(err) {
|
||||
// If the resource doesn't exist, we'll create it
|
||||
klog.V(4).Infof("Create StorageClassProvisioner %s", storageClass.GetName())
|
||||
storageClassCapabilityCreate := &crdapi.StorageClassCapability{ObjectMeta: metav1.ObjectMeta{Name: storageClass.Name}}
|
||||
err = c.addSpec(&storageClassCapabilityCreate.Spec, storageClass, snapshotClassCreated)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
klog.V(4).Info("Create StorageClassCapability: ", storageClassCapabilityCreate)
|
||||
_, err = c.storageClassCapabilityClient.StorageV1alpha1().StorageClassCapabilities().Create(storageClassCapabilityCreate)
|
||||
return err
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// If the resource exist, we can update it.
|
||||
storageClassCapabilityUpdate := storageClassCapabilityExist.DeepCopy()
|
||||
err = c.addSpec(&storageClassCapabilityUpdate.Spec, storageClass, snapshotClassCreated)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !reflect.DeepEqual(storageClassCapabilityExist, storageClassCapabilityUpdate) {
|
||||
klog.V(4).Info("Update StorageClassCapability: ", storageClassCapabilityUpdate)
|
||||
_, err = c.storageClassCapabilityClient.StorageV1alpha1().StorageClassCapabilities().Update(storageClassCapabilityUpdate)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *StorageCapabilityController) IsValidKubernetesVersion() bool {
|
||||
minVer := version.MustParseGeneric(minKubernetesVersion)
|
||||
rawVer, err := c.k8sClient.Discovery().ServerVersion()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
ver, err := version.ParseSemantic(rawVer.String())
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return ver.AtLeast(minVer)
|
||||
}
|
||||
|
||||
func (c *StorageCapabilityController) addSpec(spec *crdapi.StorageClassCapabilitySpec, storageClass *v1strorage.StorageClass, snapshotClassCreated bool) error {
|
||||
csiCapability, err := csiCapability(c.csiAddressGetter(storageClass.Provisioner))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
spec.Provisioner = storageClass.Provisioner
|
||||
spec.Features.Volume = csiCapability.Features.Volume
|
||||
spec.Features.Topology = csiCapability.Features.Topology
|
||||
if *storageClass.AllowVolumeExpansion {
|
||||
spec.Features.Volume.Expand = csiCapability.Features.Volume.Expand
|
||||
} else {
|
||||
spec.Features.Volume.Expand = crdapi.ExpandModeUnknown
|
||||
}
|
||||
if snapshotClassCreated {
|
||||
spec.Features.Snapshot = csiCapability.Features.Snapshot
|
||||
} else {
|
||||
spec.Features.Snapshot.Create = false
|
||||
spec.Features.Snapshot.List = false
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func fileExist(name string) bool {
|
||||
_, err := os.Stat(name)
|
||||
return !os.IsNotExist(err)
|
||||
}
|
||||
340
pkg/controller/storage/capability/capability_controller_test.go
Normal file
340
pkg/controller/storage/capability/capability_controller_test.go
Normal file
@@ -0,0 +1,340 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 The KubeSphere Authors.
|
||||
|
||||
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 capability
|
||||
|
||||
import (
|
||||
"github.com/google/go-cmp/cmp"
|
||||
snapbeta1 "github.com/kubernetes-csi/external-snapshotter/v2/pkg/apis/volumesnapshot/v1beta1"
|
||||
snapfake "github.com/kubernetes-csi/external-snapshotter/v2/pkg/client/clientset/versioned/fake"
|
||||
snapinformers "github.com/kubernetes-csi/external-snapshotter/v2/pkg/client/informers/externalversions"
|
||||
storagev1 "k8s.io/api/storage/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/util/diff"
|
||||
kubeinformers "k8s.io/client-go/informers"
|
||||
k8sfake "k8s.io/client-go/kubernetes/fake"
|
||||
core "k8s.io/client-go/testing"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
crdv1alpha1 "kubesphere.io/kubesphere/pkg/apis/storage/v1alpha1"
|
||||
crdfake "kubesphere.io/kubesphere/pkg/client/clientset/versioned/fake"
|
||||
crdinformers "kubesphere.io/kubesphere/pkg/client/informers/externalversions"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
alwaysReady = func() bool { return true }
|
||||
noReSyncPeriodFunc = func() time.Duration { return 0 }
|
||||
)
|
||||
|
||||
type fixture struct {
|
||||
t *testing.T
|
||||
// Clients
|
||||
k8sClient *k8sfake.Clientset
|
||||
snapshotClassClient *snapfake.Clientset
|
||||
storageClassCapabilitiesClient *crdfake.Clientset
|
||||
// Objects from here preload into NewSimpleFake.
|
||||
storageClassObjects []runtime.Object
|
||||
snapshotClassObjects []runtime.Object
|
||||
storageClassCapabilityObjects []runtime.Object
|
||||
// Objects to put in the store.
|
||||
storageClassLister []*storagev1.StorageClass
|
||||
snapshotClassLister []*snapbeta1.VolumeSnapshotClass
|
||||
storageClassCapabilityLister []*crdv1alpha1.StorageClassCapability
|
||||
// Actions expected to happen on the client.
|
||||
storageClassCapabilitiesActions []core.Action
|
||||
// CSI server
|
||||
fakeCSIServer *fakeCSIServer
|
||||
}
|
||||
|
||||
func newFixture(t *testing.T) *fixture {
|
||||
return &fixture{
|
||||
t: t,
|
||||
}
|
||||
}
|
||||
|
||||
func (f *fixture) newController() (*StorageCapabilityController, kubeinformers.SharedInformerFactory,
|
||||
crdinformers.SharedInformerFactory, snapinformers.SharedInformerFactory) {
|
||||
|
||||
fakeCSIServer, address := newTestCSIServer()
|
||||
f.fakeCSIServer = fakeCSIServer
|
||||
|
||||
f.k8sClient = k8sfake.NewSimpleClientset(f.storageClassObjects...)
|
||||
f.storageClassCapabilitiesClient = crdfake.NewSimpleClientset(f.storageClassCapabilityObjects...)
|
||||
f.snapshotClassClient = snapfake.NewSimpleClientset(f.snapshotClassObjects...)
|
||||
|
||||
k8sI := kubeinformers.NewSharedInformerFactory(f.k8sClient, noReSyncPeriodFunc())
|
||||
crdI := crdinformers.NewSharedInformerFactory(f.storageClassCapabilitiesClient, noReSyncPeriodFunc())
|
||||
snapI := snapinformers.NewSharedInformerFactory(f.snapshotClassClient, noReSyncPeriodFunc())
|
||||
|
||||
c := NewController(
|
||||
f.k8sClient,
|
||||
f.storageClassCapabilitiesClient,
|
||||
k8sI.Storage().V1().StorageClasses(),
|
||||
snapI.Snapshot().V1beta1().VolumeSnapshotClasses(),
|
||||
crdI.Storage().V1alpha1().StorageClassCapabilities(),
|
||||
func(storageClassProvisioner string) string { return address },
|
||||
)
|
||||
|
||||
for _, storageClass := range f.storageClassLister {
|
||||
_ = k8sI.Storage().V1().StorageClasses().Informer().GetIndexer().Add(storageClass)
|
||||
}
|
||||
for _, snapshotClass := range f.snapshotClassLister {
|
||||
_ = snapI.Snapshot().V1beta1().VolumeSnapshotClasses().Informer().GetIndexer().Add(snapshotClass)
|
||||
}
|
||||
for _, storageClassCapability := range f.storageClassCapabilityLister {
|
||||
_ = crdI.Storage().V1alpha1().StorageClassCapabilities().Informer().GetIndexer().Add(storageClassCapability)
|
||||
}
|
||||
|
||||
return c, k8sI, crdI, snapI
|
||||
}
|
||||
|
||||
func (f *fixture) runController(scName string, startInformers bool, expectError bool) {
|
||||
c, k8sI, crdI, snapI := f.newController()
|
||||
|
||||
f.fakeCSIServer.run()
|
||||
defer f.fakeCSIServer.stop()
|
||||
|
||||
if startInformers {
|
||||
stopCh := make(chan struct{})
|
||||
defer close(stopCh)
|
||||
k8sI.Start(stopCh)
|
||||
crdI.Start(stopCh)
|
||||
snapI.Start(stopCh)
|
||||
}
|
||||
c.storageClassSynced = alwaysReady
|
||||
c.snapshotClassSynced = alwaysReady
|
||||
c.storageClassCapabilitySynced = alwaysReady
|
||||
|
||||
err := c.syncHandler(scName)
|
||||
if !expectError && err != nil {
|
||||
f.t.Errorf("error syncing: %v", err)
|
||||
} else if expectError && err == nil {
|
||||
f.t.Error("expected error syncing, got nil")
|
||||
}
|
||||
|
||||
actions := filterInformerActions(f.storageClassCapabilitiesClient.Actions())
|
||||
for i, action := range actions {
|
||||
if len(f.storageClassCapabilitiesActions) < i+1 {
|
||||
f.t.Errorf("%d unexpected actions: %+v", len(actions)-len(f.storageClassCapabilitiesActions), actions[i:])
|
||||
break
|
||||
}
|
||||
expectedAction := f.storageClassCapabilitiesActions[i]
|
||||
checkAction(expectedAction, action, f.t)
|
||||
}
|
||||
}
|
||||
|
||||
func (f *fixture) run(scName string) {
|
||||
f.runController(scName, true, false)
|
||||
}
|
||||
|
||||
func (f *fixture) expectCreateStorageClassCapabilitiesAction(storageClassCapability *crdv1alpha1.StorageClassCapability) {
|
||||
f.storageClassCapabilitiesActions = append(f.storageClassCapabilitiesActions, core.NewCreateAction(
|
||||
schema.GroupVersionResource{Resource: "storageclasscapabilities"}, storageClassCapability.Namespace, storageClassCapability))
|
||||
}
|
||||
|
||||
func (f *fixture) expectUpdateStorageClassCapabilitiesAction(storageClassCapability *crdv1alpha1.StorageClassCapability) {
|
||||
f.storageClassCapabilitiesActions = append(f.storageClassCapabilitiesActions, core.NewUpdateAction(
|
||||
schema.GroupVersionResource{Resource: "storageclasscapabilities"}, storageClassCapability.Namespace, storageClassCapability))
|
||||
}
|
||||
|
||||
func (f *fixture) expectDeleteStorageClassCapabilitiesAction(storageClassCapability *crdv1alpha1.StorageClassCapability) {
|
||||
f.storageClassCapabilitiesActions = append(f.storageClassCapabilitiesActions, core.NewDeleteAction(
|
||||
schema.GroupVersionResource{Resource: "storageclasscapabilities"}, storageClassCapability.Namespace, storageClassCapability.Name))
|
||||
}
|
||||
|
||||
// filterInformerActions filters list and watch actions for testing resources.
|
||||
// Since list and watch don't change resource state we can filter it to lower
|
||||
// nose level in our tests.
|
||||
func filterInformerActions(actions []core.Action) []core.Action {
|
||||
var ret []core.Action
|
||||
for _, action := range actions {
|
||||
if action.GetVerb() == "list" || action.GetVerb() == "watch" {
|
||||
continue
|
||||
}
|
||||
ret = append(ret, action)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// checkAction verifies that expected and actual actions are equal and both have
|
||||
// same attached resources
|
||||
func checkAction(expected, actual core.Action, t *testing.T) {
|
||||
if !(expected.Matches(actual.GetVerb(), actual.GetResource().Resource) && actual.GetSubresource() == expected.GetSubresource()) {
|
||||
t.Errorf("Expected\n\t%#v\ngot\n\t%#v", expected, actual)
|
||||
return
|
||||
}
|
||||
|
||||
if reflect.TypeOf(actual) != reflect.TypeOf(expected) {
|
||||
t.Errorf("Action has wrong type. Expected: %t. Got: %t", expected, actual)
|
||||
return
|
||||
}
|
||||
|
||||
switch a := actual.(type) {
|
||||
case core.CreateActionImpl:
|
||||
e, _ := expected.(core.CreateActionImpl)
|
||||
expObject := e.GetObject()
|
||||
object := a.GetObject()
|
||||
if difference := cmp.Diff(object, expObject); len(difference) > 0 {
|
||||
t.Errorf("[CreateAction] %T differ (-got, +want): %s", expObject, difference)
|
||||
}
|
||||
case core.UpdateActionImpl:
|
||||
e, _ := expected.(core.UpdateActionImpl)
|
||||
expObject := e.GetObject()
|
||||
object := a.GetObject()
|
||||
if difference := cmp.Diff(object, expObject); len(difference) > 0 {
|
||||
t.Errorf("[UpdateAction] %T differ (-got, +want): %s", expObject, difference)
|
||||
}
|
||||
case core.PatchActionImpl:
|
||||
e, _ := expected.(core.PatchActionImpl)
|
||||
expPatch := e.GetPatch()
|
||||
patch := a.GetPatch()
|
||||
if !reflect.DeepEqual(expPatch, patch) {
|
||||
t.Errorf("Action %s %s has wrong patch\nDiff:\n %s",
|
||||
a.GetVerb(), a.GetResource().Resource, diff.ObjectGoPrintSideBySide(expPatch, patch))
|
||||
}
|
||||
case core.DeleteActionImpl:
|
||||
e, _ := expected.(core.DeleteActionImpl)
|
||||
if difference := cmp.Diff(e.Name, a.Name); len(difference) > 0 {
|
||||
t.Errorf("[UpdateAction] %T differ (-got, +want): %s", e.Name, difference)
|
||||
}
|
||||
default:
|
||||
t.Errorf("Uncaptured Action %s %s, you should explicitly add a case to capture it",
|
||||
actual.GetVerb(), actual.GetResource().Resource)
|
||||
}
|
||||
}
|
||||
|
||||
func newStorageClass(name string, provisioner string) *storagev1.StorageClass {
|
||||
isExpansion := true
|
||||
return &storagev1.StorageClass{
|
||||
ObjectMeta: v1.ObjectMeta{
|
||||
Name: name,
|
||||
},
|
||||
Provisioner: provisioner,
|
||||
AllowVolumeExpansion: &isExpansion,
|
||||
}
|
||||
}
|
||||
|
||||
func newStorageClassCapability(storageClass *storagev1.StorageClass) *crdv1alpha1.StorageClassCapability {
|
||||
storageClassCapability := &crdv1alpha1.StorageClassCapability{}
|
||||
storageClassCapability.Name = storageClass.Name
|
||||
storageClassCapability.Spec = *newStorageClassCapabilitySpec()
|
||||
storageClassCapability.Spec.Provisioner = storageClass.Provisioner
|
||||
return storageClassCapability
|
||||
}
|
||||
|
||||
func newSnapshotClass(storageClass *storagev1.StorageClass) *snapbeta1.VolumeSnapshotClass {
|
||||
return &snapbeta1.VolumeSnapshotClass{
|
||||
ObjectMeta: v1.ObjectMeta{
|
||||
Name: storageClass.Name,
|
||||
},
|
||||
Driver: storageClass.Provisioner,
|
||||
}
|
||||
}
|
||||
|
||||
func getKey(sc *storagev1.StorageClass, t *testing.T) string {
|
||||
key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(sc)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error getting key for %v: %v", sc.Name, err)
|
||||
return ""
|
||||
}
|
||||
return key
|
||||
}
|
||||
|
||||
func TestCreateStorageClass(t *testing.T) {
|
||||
fixture := newFixture(t)
|
||||
storageClass := newStorageClass("csi-example", "csi.example.com")
|
||||
snapshotClass := newSnapshotClass(storageClass)
|
||||
storageClassCapability := newStorageClassCapability(storageClass)
|
||||
|
||||
// Objects exist
|
||||
fixture.storageClassObjects = append(fixture.storageClassObjects, storageClass)
|
||||
fixture.storageClassLister = append(fixture.storageClassLister, storageClass)
|
||||
fixture.snapshotClassObjects = append(fixture.snapshotClassObjects, snapshotClass)
|
||||
fixture.snapshotClassLister = append(fixture.snapshotClassLister, snapshotClass)
|
||||
|
||||
// Action expected
|
||||
fixture.expectCreateStorageClassCapabilitiesAction(storageClassCapability)
|
||||
|
||||
// Run test
|
||||
fixture.run(getKey(storageClass, t))
|
||||
}
|
||||
|
||||
func TestUpdateStorageClass(t *testing.T) {
|
||||
storageClass := newStorageClass("csi-example", "csi.example.com")
|
||||
snapshotClass := newSnapshotClass(storageClass)
|
||||
storageClassCapability := newStorageClassCapability(storageClass)
|
||||
|
||||
fixture := newFixture(t)
|
||||
// Object exist
|
||||
fixture.storageClassObjects = append(fixture.storageClassObjects, storageClass)
|
||||
fixture.storageClassLister = append(fixture.storageClassLister, storageClass)
|
||||
fixture.snapshotClassObjects = append(fixture.snapshotClassObjects, snapshotClass)
|
||||
fixture.snapshotClassLister = append(fixture.snapshotClassLister, snapshotClass)
|
||||
fixture.storageClassCapabilityObjects = append(fixture.storageClassCapabilityObjects, storageClassCapability)
|
||||
fixture.storageClassCapabilityLister = append(fixture.storageClassCapabilityLister, storageClassCapability)
|
||||
|
||||
// Action expected
|
||||
fixture.expectUpdateStorageClassCapabilitiesAction(storageClassCapability)
|
||||
|
||||
// Run test
|
||||
fixture.run(getKey(storageClass, t))
|
||||
}
|
||||
|
||||
func TestDeleteStorageClass(t *testing.T) {
|
||||
storageClass := newStorageClass("csi-example", "csi.example.com")
|
||||
snapshotClass := newSnapshotClass(storageClass)
|
||||
storageClassCapability := newStorageClassCapability(storageClass)
|
||||
|
||||
fixture := newFixture(t)
|
||||
// Object exist
|
||||
fixture.snapshotClassObjects = append(fixture.snapshotClassObjects, snapshotClass)
|
||||
fixture.snapshotClassLister = append(fixture.snapshotClassLister, snapshotClass)
|
||||
fixture.storageClassCapabilityObjects = append(fixture.storageClassCapabilityObjects, storageClassCapability)
|
||||
fixture.storageClassCapabilityLister = append(fixture.storageClassCapabilityLister, storageClassCapability)
|
||||
|
||||
// Action expected
|
||||
fixture.expectDeleteStorageClassCapabilitiesAction(storageClassCapability)
|
||||
|
||||
// Run test
|
||||
fixture.run(getKey(storageClass, t))
|
||||
}
|
||||
|
||||
func TestDeleteSnapshotClass(t *testing.T) {
|
||||
storageClass := newStorageClass("csi-example", "csi.example.com")
|
||||
storageClassCapability := newStorageClassCapability(storageClass)
|
||||
|
||||
fixture := newFixture(t)
|
||||
// Object exist
|
||||
fixture.storageClassCapabilityObjects = append(fixture.storageClassCapabilityObjects, storageClassCapability)
|
||||
fixture.storageClassCapabilityLister = append(fixture.storageClassCapabilityLister, storageClassCapability)
|
||||
fixture.storageClassObjects = append(fixture.storageClassObjects, storageClass)
|
||||
fixture.storageClassLister = append(fixture.storageClassLister, storageClass)
|
||||
|
||||
// Action expected
|
||||
storageClassCapabilityUpdate := storageClassCapability.DeepCopy()
|
||||
storageClassCapabilityUpdate.Spec.Features.Snapshot.Create = false
|
||||
storageClassCapabilityUpdate.Spec.Features.Snapshot.List = false
|
||||
fixture.expectUpdateStorageClassCapabilitiesAction(storageClassCapabilityUpdate)
|
||||
|
||||
// Run test
|
||||
fixture.run(getKey(storageClass, t))
|
||||
}
|
||||
166
pkg/controller/storage/capability/csi_capability.go
Normal file
166
pkg/controller/storage/capability/csi_capability.go
Normal file
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 The KubeSphere Authors.
|
||||
|
||||
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 capability
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/container-storage-interface/spec/lib/go/csi"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/connectivity"
|
||||
"google.golang.org/grpc/keepalive"
|
||||
"kubesphere.io/kubesphere/pkg/apis/storage/v1alpha1"
|
||||
"net"
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
dialDuration = time.Second * 5
|
||||
requestDuration = time.Second * 10
|
||||
)
|
||||
|
||||
func csiCapability(csiAddress string) (*v1alpha1.StorageClassCapabilitySpec, error) {
|
||||
csiConn, err := connect(csiAddress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() { _ = csiConn.Close() }()
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), requestDuration)
|
||||
defer cancel()
|
||||
|
||||
spec := &v1alpha1.StorageClassCapabilitySpec{}
|
||||
err = addPluginCapabilities(ctx, csiConn, spec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = addControllerCapabilities(ctx, csiConn, spec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = addNodeCapabilities(ctx, csiConn, spec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return spec, nil
|
||||
|
||||
}
|
||||
|
||||
func addPluginCapabilities(ctx context.Context, conn *grpc.ClientConn, spec *v1alpha1.StorageClassCapabilitySpec) error {
|
||||
identityClient := csi.NewIdentityClient(conn)
|
||||
pluginCapabilitiesResponse, err := identityClient.GetPluginCapabilities(ctx, &csi.GetPluginCapabilitiesRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, capability := range pluginCapabilitiesResponse.GetCapabilities() {
|
||||
if capability == nil {
|
||||
continue
|
||||
}
|
||||
if capability.GetService().GetType() == csi.PluginCapability_Service_VOLUME_ACCESSIBILITY_CONSTRAINTS {
|
||||
spec.Features.Topology = true
|
||||
}
|
||||
volumeExpansion := capability.GetVolumeExpansion()
|
||||
if volumeExpansion != nil {
|
||||
switch volumeExpansion.GetType() {
|
||||
case csi.PluginCapability_VolumeExpansion_ONLINE:
|
||||
spec.Features.Volume.Expand = v1alpha1.ExpandModeOnline
|
||||
case csi.PluginCapability_VolumeExpansion_OFFLINE:
|
||||
spec.Features.Volume.Expand = v1alpha1.ExpandModeOffline
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func addControllerCapabilities(ctx context.Context, conn *grpc.ClientConn, spec *v1alpha1.StorageClassCapabilitySpec) error {
|
||||
controllerClient := csi.NewControllerClient(conn)
|
||||
controllerCapabilitiesResponse, err := controllerClient.ControllerGetCapabilities(ctx, &csi.ControllerGetCapabilitiesRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, capability := range controllerCapabilitiesResponse.GetCapabilities() {
|
||||
switch capability.GetRpc().GetType() {
|
||||
case csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME:
|
||||
spec.Features.Volume.Create = true
|
||||
case csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME:
|
||||
spec.Features.Volume.Attach = true
|
||||
case csi.ControllerServiceCapability_RPC_LIST_VOLUMES:
|
||||
spec.Features.Volume.List = true
|
||||
case csi.ControllerServiceCapability_RPC_CLONE_VOLUME:
|
||||
spec.Features.Volume.Clone = true
|
||||
case csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT:
|
||||
spec.Features.Snapshot.Create = true
|
||||
case csi.ControllerServiceCapability_RPC_LIST_SNAPSHOTS:
|
||||
spec.Features.Snapshot.List = true
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func addNodeCapabilities(ctx context.Context, conn *grpc.ClientConn, spec *v1alpha1.StorageClassCapabilitySpec) error {
|
||||
nodeClient := csi.NewNodeClient(conn)
|
||||
controllerCapabilitiesResponse, err := nodeClient.NodeGetCapabilities(ctx, &csi.NodeGetCapabilitiesRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, capability := range controllerCapabilitiesResponse.GetCapabilities() {
|
||||
switch capability.GetRpc().GetType() {
|
||||
case csi.NodeServiceCapability_RPC_GET_VOLUME_STATS:
|
||||
spec.Features.Volume.Stats = true
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Connect address by GRPC
|
||||
func connect(address string) (*grpc.ClientConn, error) {
|
||||
dialOptions := []grpc.DialOption{
|
||||
grpc.WithInsecure(),
|
||||
}
|
||||
u, err := url.Parse(address)
|
||||
if err == nil && (!u.IsAbs() || u.Scheme == "unix") {
|
||||
dialOptions = append(dialOptions,
|
||||
grpc.WithDialer(
|
||||
func(addr string, timeout time.Duration) (net.Conn, error) {
|
||||
return net.DialTimeout("unix", u.Path, timeout)
|
||||
}))
|
||||
}
|
||||
// This is necessary when connecting via TCP and does not hurt
|
||||
// when using Unix domain sockets. It ensures that gRPC detects a dead connection
|
||||
// in a timely manner.
|
||||
dialOptions = append(dialOptions,
|
||||
grpc.WithKeepaliveParams(keepalive.ClientParameters{PermitWithoutStream: true}))
|
||||
|
||||
conn, err := grpc.Dial(address, dialOptions...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), dialDuration)
|
||||
defer cancel()
|
||||
for {
|
||||
if !conn.WaitForStateChange(ctx, conn.GetState()) {
|
||||
return conn, errors.New("connection timed out")
|
||||
}
|
||||
if conn.GetState() == connectivity.Ready {
|
||||
return conn, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
187
pkg/controller/storage/capability/csi_capability_test.go
Normal file
187
pkg/controller/storage/capability/csi_capability_test.go
Normal file
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 The KubeSphere Authors.
|
||||
|
||||
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 capability
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/container-storage-interface/spec/lib/go/csi"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"google.golang.org/grpc"
|
||||
"k8s.io/apimachinery/pkg/util/rand"
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/apis/storage/v1alpha1"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var DefaultControllerRPCType = []csi.ControllerServiceCapability_RPC_Type{
|
||||
csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME,
|
||||
csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT,
|
||||
csi.ControllerServiceCapability_RPC_EXPAND_VOLUME,
|
||||
csi.ControllerServiceCapability_RPC_CLONE_VOLUME,
|
||||
}
|
||||
|
||||
var DefaultNodeRPCType = []csi.NodeServiceCapability_RPC_Type{
|
||||
csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME,
|
||||
csi.NodeServiceCapability_RPC_EXPAND_VOLUME,
|
||||
csi.NodeServiceCapability_RPC_GET_VOLUME_STATS,
|
||||
}
|
||||
|
||||
var DefaultPluginCapability = []*csi.PluginCapability{
|
||||
{
|
||||
Type: &csi.PluginCapability_Service_{
|
||||
Service: &csi.PluginCapability_Service{
|
||||
Type: csi.PluginCapability_Service_CONTROLLER_SERVICE,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Type: &csi.PluginCapability_VolumeExpansion_{
|
||||
VolumeExpansion: &csi.PluginCapability_VolumeExpansion{
|
||||
Type: csi.PluginCapability_VolumeExpansion_OFFLINE,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
type fakeCSIServer struct {
|
||||
csi.UnimplementedIdentityServer
|
||||
csi.UnimplementedControllerServer
|
||||
csi.UnimplementedNodeServer
|
||||
network string
|
||||
address string
|
||||
server *grpc.Server
|
||||
}
|
||||
|
||||
func newTestCSIServer() (csiServer *fakeCSIServer, address string) {
|
||||
if runtime.GOOS == "windows" {
|
||||
address = "localhost:38886"
|
||||
csiServer = newFakeCSIServer("tcp", address)
|
||||
} else {
|
||||
address = filepath.Join(os.TempDir(), "csi.sock"+rand.String(4))
|
||||
csiServer = newFakeCSIServer("unix", address)
|
||||
address = "unix://" + address
|
||||
}
|
||||
return csiServer, address
|
||||
}
|
||||
|
||||
func newFakeCSIServer(network, address string) *fakeCSIServer {
|
||||
return &fakeCSIServer{
|
||||
network: network,
|
||||
address: address,
|
||||
}
|
||||
}
|
||||
|
||||
func (f *fakeCSIServer) run() {
|
||||
listener, err := net.Listen(f.network, f.address)
|
||||
if err != nil {
|
||||
klog.Error("fake CSI server listen failed, ", err)
|
||||
return
|
||||
}
|
||||
server := grpc.NewServer()
|
||||
csi.RegisterIdentityServer(server, f)
|
||||
csi.RegisterControllerServer(server, f)
|
||||
csi.RegisterNodeServer(server, f)
|
||||
go func() {
|
||||
err = server.Serve(listener)
|
||||
if err != nil && !strings.Contains(err.Error(), "stopped") {
|
||||
klog.Error("fake CSI server serve failed, ", err)
|
||||
}
|
||||
}()
|
||||
f.server = server
|
||||
}
|
||||
|
||||
func (f *fakeCSIServer) stop() {
|
||||
if f.server != nil {
|
||||
f.server.Stop()
|
||||
}
|
||||
}
|
||||
|
||||
func (*fakeCSIServer) GetPluginCapabilities(ctx context.Context, req *csi.GetPluginCapabilitiesRequest) (*csi.GetPluginCapabilitiesResponse, error) {
|
||||
return &csi.GetPluginCapabilitiesResponse{Capabilities: DefaultPluginCapability}, nil
|
||||
}
|
||||
|
||||
func (*fakeCSIServer) ControllerGetCapabilities(ctx context.Context, req *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error) {
|
||||
var capabilities []*csi.ControllerServiceCapability
|
||||
for _, rpcType := range DefaultControllerRPCType {
|
||||
capability := &csi.ControllerServiceCapability{
|
||||
Type: &csi.ControllerServiceCapability_Rpc{
|
||||
Rpc: &csi.ControllerServiceCapability_RPC{
|
||||
Type: rpcType,
|
||||
},
|
||||
},
|
||||
}
|
||||
capabilities = append(capabilities, capability)
|
||||
}
|
||||
return &csi.ControllerGetCapabilitiesResponse{Capabilities: capabilities}, nil
|
||||
}
|
||||
|
||||
func (*fakeCSIServer) NodeGetCapabilities(ctx context.Context, req *csi.NodeGetCapabilitiesRequest) (*csi.NodeGetCapabilitiesResponse, error) {
|
||||
var capabilities []*csi.NodeServiceCapability
|
||||
for _, rpcType := range DefaultNodeRPCType {
|
||||
capability := &csi.NodeServiceCapability{
|
||||
Type: &csi.NodeServiceCapability_Rpc{
|
||||
Rpc: &csi.NodeServiceCapability_RPC{
|
||||
Type: rpcType,
|
||||
},
|
||||
},
|
||||
}
|
||||
capabilities = append(capabilities, capability)
|
||||
}
|
||||
return &csi.NodeGetCapabilitiesResponse{Capabilities: capabilities}, nil
|
||||
}
|
||||
|
||||
func Test_CSICapability(t *testing.T) {
|
||||
fakeCSIServer, address := newTestCSIServer()
|
||||
fakeCSIServer.run()
|
||||
defer fakeCSIServer.stop()
|
||||
|
||||
specGot, err := csiCapability(address)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
specExpected := newStorageClassCapabilitySpec()
|
||||
if diff := cmp.Diff(specGot, specExpected); diff != "" {
|
||||
t.Errorf("%T differ (-got, +want): %s", specExpected, diff)
|
||||
}
|
||||
}
|
||||
|
||||
func newStorageClassCapabilitySpec() *v1alpha1.StorageClassCapabilitySpec {
|
||||
return &v1alpha1.StorageClassCapabilitySpec{
|
||||
Features: v1alpha1.StorageClassCapabilitySpecFeatures{
|
||||
Topology: false,
|
||||
Volume: v1alpha1.StorageClassCapabilitySpecFeaturesVolume{
|
||||
Create: true,
|
||||
Attach: false,
|
||||
List: false,
|
||||
Clone: true,
|
||||
Stats: true,
|
||||
Expand: v1alpha1.ExpandModeOffline,
|
||||
},
|
||||
Snapshot: v1alpha1.StorageClassCapabilitySpecFeaturesSnapshot{
|
||||
Create: true,
|
||||
List: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user