diff --git a/client/apis/xuanwu/v1/resourcetopology.go b/client/apis/xuanwu/v1/resourcetopology.go deleted file mode 100644 index 36c5af77..00000000 --- a/client/apis/xuanwu/v1/resourcetopology.go +++ /dev/null @@ -1,98 +0,0 @@ -/* -Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved. - -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 v1 - -import metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1" - -// ResourceTopologyStatusPhase defines the ResourceTopologyStatusPhase type -type ResourceTopologyStatusPhase string - -const ( - // ResourceTopologyStatusNormal indicates that the resource is normal - ResourceTopologyStatusNormal ResourceTopologyStatusPhase = "Normal" - // ResourceTopologyStatusPending indicates that the resource is pending - ResourceTopologyStatusPending ResourceTopologyStatusPhase = "Pending" - // ResourceTopologyStatusDeleting indicates that the resource is deleting - ResourceTopologyStatusDeleting ResourceTopologyStatusPhase = "Deleting" -) - -// ResourceTopologySpec defines the fields in Spec -type ResourceTopologySpec struct { - // Provisioner is the volume provisioner name - // +kubebuilder:validation:Required - Provisioner string `json:"provisioner" protobuf:"bytes,2,name=provisioner"` - - // VolumeHandle is the backend name and identity of the volume, format as . - // +kubebuilder:validation:Required - VolumeHandle string `json:"volumeHandle" protobuf:"bytes,2,name=volumeHandle"` - - // Tags defines pv and other relationships and ownership - // +kubebuilder:validation:Required - Tags []Tag `json:"tags" protobuf:"bytes,2,name=tags"` -} - -// ResourceTopologyStatus status of resource topology -type ResourceTopologyStatus struct { - // Status is the status of the ResourceTopology - Status ResourceTopologyStatusPhase `json:"status,omitempty" protobuf:"bytes,2,opt,name=status"` - - // Tags defines pv and other relationships and ownership - Tags []Tag `json:"tags,omitempty" protobuf:"bytes,3,opt,name=tags"` -} - -// Tag defines pv and other relationships and ownership -type Tag struct { - ResourceInfo `json:",inline"` - - // Owner defines who does the resource belongs to - // +kubebuilder:validation:Optional - Owner ResourceInfo `json:"owner" protobuf:"bytes,2,name=owner"` -} - -// ResourceInfo define resource information -type ResourceInfo struct { - metaV1.TypeMeta `json:",inline"` - // NameSpace is the namespace of the resource - Namespace string `json:"namespace,omitempty" protobuf:"bytes,2,opt,name=target"` - // Name is the name of the resource - Name string `json:"name,omitempty" protobuf:"bytes,2,opt,name=name"` -} - -// ResourceTopology is the Schema for the ResourceTopologys API -// +genclient -// +genclient:nonNamespaced -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// +kubebuilder:object:root=true -// +kubebuilder:resource:scope=Cluster,shortName="rt" -// +kubebuilder:subresource:status -// +kubebuilder:printcolumn:name="Provisioner",type=string,JSONPath=`.spec.provisioner` -// +kubebuilder:printcolumn:name="VolumeHandle",type=string,JSONPath=`.spec.volumeHandle` -// +kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.status` -// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp` -type ResourceTopology struct { - metaV1.TypeMeta `json:",inline"` - metaV1.ObjectMeta `json:"metadata,omitempty"` - Spec ResourceTopologySpec `json:"spec,omitempty"` - Status ResourceTopologyStatus `json:"status,omitempty"` -} - -// ResourceTopologyList contains a list of ResourceTopology -// +kubebuilder:object:root=true -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type ResourceTopologyList struct { - metaV1.TypeMeta `json:",inline"` - metaV1.ListMeta `json:"metadata,omitempty"` - Items []ResourceTopology `json:"items"` -} diff --git a/connector/nfs_plus/nfs_plus.go b/connector/nfs_plus/nfs_plus.go deleted file mode 100644 index ab00dae2..00000000 --- a/connector/nfs_plus/nfs_plus.go +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved. - * - * 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 nfs_plus to mount or unmount filesystem -package nfs_plus - -import ( - "context" - - "huawei-csi-driver/connector" - "huawei-csi-driver/utils/log" -) - -// NFSPlus to define a local lock when connect or disconnect, in order to preventing mounting and unmounting confusion -type NFSPlus struct { -} - -func init() { - connector.RegisterConnector(connector.NFSPlusDriver, &NFSPlus{}) -} - -// ConnectVolume to mount the source to target path, the source path can be block or nfs -// Example: -// mount /dev/sdb / -// mount / -func (nfsPlus *NFSPlus) ConnectVolume(ctx context.Context, conn map[string]interface{}) (string, error) { - log.AddContext(ctx).Infof("NFS+ Start to connect volume ==> connect info: %v", conn) - return tryConnectVolume(ctx, conn) -} - -// DisConnectVolume to unmount the target path -func (nfsPlus *NFSPlus) DisConnectVolume(ctx context.Context, targetPath string) error { - log.AddContext(ctx).Infof("NFS+ Start to disconnect volume ==> target path is: %v", targetPath) - return tryDisConnectVolume(ctx, targetPath) -} diff --git a/connector/nfs_plus/nfs_plus_helper.go b/connector/nfs_plus/nfs_plus_helper.go deleted file mode 100644 index 61f1d4bf..00000000 --- a/connector/nfs_plus/nfs_plus_helper.go +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved. - * - * 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 nfs_plus to mount or unmount filesystem -package nfs_plus - -import ( - "context" - "errors" - "fmt" - "os" - "path" - "strings" - - "huawei-csi-driver/connector" - "huawei-csi-driver/connector/nfs" - "huawei-csi-driver/csi/backend/plugin" - pkgUtils "huawei-csi-driver/pkg/utils" - "huawei-csi-driver/utils" - "huawei-csi-driver/utils/log" -) - -const nfsPlusMountCommand = "mount %s %s %s %s" - -type connectorInfo struct { - sourcePath string - targetPath string - portals []string - localAdds string - remoteAdds string - mntFlags mountParam -} - -type mountParam struct { - dashT string - dashO string -} - -func tryConnectVolume(ctx context.Context, connMap map[string]interface{}) (string, error) { - connInfo, err := parseNFSPlusInfo(ctx, connMap) - if err != nil { - log.AddContext(ctx).Errorf("parse nfs plus info failed, connMap: %+v err: %v", connMap, err) - return "", err - } - - err = mountNFSPlus(ctx, connInfo) - if err != nil { - log.AddContext(ctx).Errorf("mount plus info failed, connMap: %+v err: %v", connInfo, err) - return "", err - } - - return "", nil -} - -func parseNFSPlusInfo(ctx context.Context, connectionProperties map[string]interface{}) (*connectorInfo, error) { - var con connectorInfo - sourcePath, srcPathExist := connectionProperties["sourcePath"].(string) - if !srcPathExist || sourcePath == "" { - return nil, pkgUtils.Errorln(ctx, "there are no source path in the connection info") - } - - targetPath, tgtPathExist := connectionProperties["targetPath"].(string) - if !tgtPathExist || targetPath == "" { - return nil, pkgUtils.Errorln(ctx, "there are no target path in the connection info") - } - - portals, portalsExist := connectionProperties["portals"].([]string) - if !portalsExist || len(portals) == 0 { - return nil, pkgUtils.Errorln(ctx, "there are no portals in the connection info") - } - - // format mount flags : remoteAdds - con.remoteAdds = strings.Join(portals, "~") - // format mount flags : mountFlag - mountFlags, _ := connectionProperties["mountFlags"].(string) - mountFlagsArr := make([]string, 0) - mountFlagsArr = append(mountFlagsArr, fmt.Sprintf("remoteaddrs=%s", con.remoteAdds)) - mountFlagsArr = append(mountFlagsArr, mountFlags) - - con.sourcePath = sourcePath - con.targetPath = targetPath - con.mntFlags = mountParam{dashO: strings.TrimSpace(strings.Join(mountFlagsArr, ",")), dashT: plugin.ProtocolNfs} - - log.AddContext(ctx).Infof("parseNFSPlusInfo success, data: %+v", con) - return &con, nil -} - -func checkMountPath(ctx context.Context, targetPath string) error { - if _, err := os.Stat(targetPath); err != nil && os.IsNotExist(err) { - if err := os.MkdirAll(targetPath, 0750); err != nil { - return pkgUtils.Errorln(ctx, "can not create a target path") - } - } - - return nil -} - -func mountNFSPlus(ctx context.Context, conn *connectorInfo) error { - var output string - var err error - err = checkMountPath(ctx, conn.targetPath) - if err != nil { - return pkgUtils.Errorf(ctx, "check mount path failed, err: %v", err) - } - - mountMap, err := connector.ReadMountPoints(ctx) - if err != nil { - return pkgUtils.Errorf(ctx, "get mount point map failed, err: %v", err) - } - - value, exist := mountMap[conn.targetPath] - if exist { - // check the filesystem by comparing the sourcePath and mountPath - if value == conn.sourcePath || path.Base(path.Dir(conn.targetPath)) == path.Base(path.Dir(conn.sourcePath)) || - nfs.ContainSourceDevice(ctx, conn.sourcePath, value) { - log.AddContext(ctx).Infof("Mount %s to %s is already exist", conn.sourcePath, conn.targetPath) - return nil - } - - return pkgUtils.Errorf(ctx, "The mount %s is already exist, source: %s realSource: %s", - conn.targetPath, conn.sourcePath, value) - } - - if conn.mntFlags.dashT != "" { - conn.mntFlags.dashT = fmt.Sprintf("-t %s", conn.mntFlags.dashT) - } - if conn.mntFlags.dashO != "" { - conn.mntFlags.dashO = fmt.Sprintf("-o %s", conn.mntFlags.dashO) - } - - output, err = utils.ExecShellCmd(ctx, fmt.Sprintf(nfsPlusMountCommand, conn.mntFlags.dashT, conn.mntFlags.dashO, - conn.sourcePath, conn.targetPath)) - if err != nil { - log.AddContext(ctx).Errorf("Mount %s to %s failed, error res: %s, error: %s", - conn.sourcePath, conn.targetPath, output, err) - return err - } - - return nil -} - -func tryDisConnectVolume(ctx context.Context, targetPath string) error { - err := unmountUnix(ctx, targetPath) - if err != nil { - return err - } - - return removeTargetPath(targetPath) -} - -func unmountUnix(ctx context.Context, targetPath string) error { - _, err := os.Stat(targetPath) - if err != nil && os.IsNotExist(err) { - return nil - } - - output, err := utils.ExecShellCmd(ctx, "umount %s", targetPath) - if err != nil && !(strings.Contains(output, "not mounted") || - strings.Contains(output, "not found")) { - log.AddContext(ctx).Errorf("Unmount %s error: %s", targetPath, output) - return err - } - - return nil -} - -func removeTargetPath(targetPath string) error { - _, err := os.Stat(targetPath) - if err != nil && os.IsNotExist(err) { - return nil - } - - if err != nil && !os.IsNotExist(err) { - msg := fmt.Sprintf("get target path %s state error %v", targetPath, err) - log.Errorln(msg) - return errors.New(msg) - } - - if err := os.RemoveAll(targetPath); err != nil { - msg := fmt.Sprintf("remove target path %s error %v", targetPath, err) - log.Errorln(msg) - return errors.New(msg) - } - return nil -} diff --git a/csi/driver/node_helper.go b/csi/driver/node_helper.go deleted file mode 100644 index 640803d5..00000000 --- a/csi/driver/node_helper.go +++ /dev/null @@ -1,384 +0,0 @@ -/* - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved. - * - * 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 driver - -import ( - "context" - "errors" - "strings" - - coreV1 "k8s.io/api/core/v1" - k8sError "k8s.io/apimachinery/pkg/api/errors" - metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - xuanwuV1 "huawei-csi-driver/client/apis/xuanwu/v1" - "huawei-csi-driver/csi/app" - "huawei-csi-driver/pkg/constants" - pkgUtils "huawei-csi-driver/pkg/utils" - labelLock "huawei-csi-driver/pkg/utils/label_lock" - "huawei-csi-driver/utils" - "huawei-csi-driver/utils/log" -) - -type deleteTopologiesLabelParam struct { - topo *xuanwuV1.ResourceTopology - pods []coreV1.Pod - pvName string - targetPath string - podName string - namespace string - volumeName string - topoName string -} - -func nodeAddLabel(ctx context.Context, volumeID, targetPath string) { - backendName, _ := utils.SplitVolumeId(volumeID) - backendName = pkgUtils.MakeMetaWithNamespace(app.GetGlobalConfig().Namespace, backendName) - - supportLabel, err := pkgUtils.IsBackendCapabilitySupport(ctx, backendName, constants.SupportLabel) - if err != nil { - log.AddContext(ctx).Errorf("IsBackendCapabilitySupport failed, backendName: %v, label: %v, err: %v", - backendName, supportLabel, err) - return - } - if supportLabel { - if err := addPodLabel(ctx, volumeID, targetPath); err != nil { - log.AddContext(ctx).Errorf("nodeAddLabel failed, err: %v", err) - } - } -} - -func nodeDeleteLabel(ctx context.Context, volumeID, targetPath string) { - backendName, _ := utils.SplitVolumeId(volumeID) - backendName = pkgUtils.MakeMetaWithNamespace(app.GetGlobalConfig().Namespace, backendName) - - supportLabel, err := pkgUtils.IsBackendCapabilitySupport(ctx, backendName, constants.SupportLabel) - if err != nil { - log.AddContext(ctx).Errorf("IsBackendCapabilitySupport failed, backendName: %v, label: %v, err: %v", - backendName, supportLabel, err) - return - } - if supportLabel { - if err := deletePodLabel(ctx, volumeID, targetPath); err != nil { - log.AddContext(ctx).Errorf("nodeDeleteLabel failed, err: %v", err) - } - } -} - -func addPodLabel(ctx context.Context, volumeID, targetPath string) error { - _, volumeName := utils.SplitVolumeId(volumeID) - topoName := pkgUtils.GetTopoName(volumeName) - _, podName, namespace, sc, pvName, err := getTargetPathPodRelateInfo(ctx, targetPath) - if err != nil { - log.AddContext(ctx).Errorf("get podName failed, pvName: %v targetPath: %v err: %v", - pvName, targetPath, err) - return err - } - if podName == "" { - log.AddContext(ctx).Errorf("get podName failed, target pod not exist, targetPath: %v err: %v", - targetPath, err) - return err - } - if sc == "" { - log.AddContext(ctx).Infof("addLabel static pv, volumeID: %v, targetPath: %v", volumeID, targetPath) - return nil - } - - // lock for rt name - if err = labelLock.AcquireCmLock(ctx, labelLock.RTLockConfigMap, topoName); err != nil { - log.AddContext(ctx).Errorf("acquire rt lock failed, key: %s err: %v", topoName, err) - return err - } - defer func(ctx context.Context, lockKey string) { - if err = labelLock.ReleaseCmlock(ctx, labelLock.RTLockConfigMap, lockKey); err != nil { - log.AddContext(ctx).Errorf("release rt lock failed, key: %s err: %v", lockKey, err) - } - }(ctx, topoName) - - return addTopologiesLabel(ctx, volumeID, targetPath, namespace, podName, pvName) -} - -func addTopologiesLabel(ctx context.Context, volumeID, targetPath, namespace, podName, pvName string) error { - _, volumeName := utils.SplitVolumeId(volumeID) - topoName := pkgUtils.GetTopoName(volumeName) - topo, err := app.GetGlobalConfig().BackendUtils.XuanwuV1().ResourceTopologies().Get(ctx, - topoName, metaV1.GetOptions{}) - log.AddContext(ctx).Debugf("get topo info, topo: %+v, err: %v, notFound: %v", topo, - err, k8sError.IsNotFound(err)) - if k8sError.IsNotFound(err) { - _, err = app.GetGlobalConfig().BackendUtils.XuanwuV1().ResourceTopologies().Create(ctx, - formatTopologies(volumeID, namespace, podName, pvName, topoName), metaV1.CreateOptions{}) - if err != nil { - log.AddContext(ctx).Errorf("create label failed, data: %+v volumeName: %v targetPath: %v", - topo, volumeName, targetPath) - return err - } - log.AddContext(ctx).Infof("node create label success, data: %+v volumeName: %v targetPath: %v", - topo, volumeName, targetPath) - return nil - } - if err != nil { - log.AddContext(ctx).Errorf("get topo failed, topoName: %v err: %v", topoName, err) - return err - } - - log.AddContext(ctx).Debugf("before add rt: %s podName: %s len: %v", topoName, podName, len(topo.Spec.Tags)) - // if pvc label not exist then add & add new pod label - addPodTopoItem(&topo.Spec.Tags, podName, namespace, volumeName) - log.AddContext(ctx).Debugf("after add rt: %s podName: %s len: %v", topoName, podName, len(topo.Spec.Tags)) - - // update topo - _, err = app.GetGlobalConfig().BackendUtils.XuanwuV1().ResourceTopologies().Update(ctx, - topo, metaV1.UpdateOptions{}) - if err != nil { - log.AddContext(ctx).Errorf("node add label failed, data:%+v, volumeName: %v targetPath: %v err: %v", - topo, volumeName, targetPath, err) - return err - } - - log.AddContext(ctx).Infof("node add label success, data: %+v volumeName: %v targetPath: %v", - topo, volumeName, targetPath) - return nil -} - -func formatTopologies(volumeID, namespace, podName, pvName, topoName string) *xuanwuV1.ResourceTopology { - topologySpec := xuanwuV1.ResourceTopologySpec{ - Provisioner: constants.DefaultTopoDriverName, - VolumeHandle: volumeID, - Tags: []xuanwuV1.Tag{ - { - ResourceInfo: xuanwuV1.ResourceInfo{ - TypeMeta: metaV1.TypeMeta{Kind: constants.PVKind, APIVersion: constants.KubernetesV1}, - Name: pvName, - }, - }, - { - ResourceInfo: xuanwuV1.ResourceInfo{ - TypeMeta: metaV1.TypeMeta{Kind: constants.PodKind, APIVersion: constants.KubernetesV1}, - Name: podName, - Namespace: namespace, - }, - }, - }, - } - return &xuanwuV1.ResourceTopology{ - TypeMeta: metaV1.TypeMeta{Kind: constants.TopologyKind, APIVersion: constants.XuanwuV1}, - ObjectMeta: metaV1.ObjectMeta{Name: topoName}, - Spec: topologySpec, - } -} - -func addPodTopoItem(tags *[]xuanwuV1.Tag, podName, namespace, volumeName string) { - // if pvc label not exist then add - var existPvLabel bool - currentPodMap := make(map[string]bool) - for _, tag := range *tags { - currentPodMap[tag.Name] = true - if tag.Kind == constants.PVKind { - existPvLabel = true - } - } - if !existPvLabel { - *tags = append(*tags, xuanwuV1.Tag{ - ResourceInfo: xuanwuV1.ResourceInfo{ - TypeMeta: metaV1.TypeMeta{Kind: constants.PVKind, APIVersion: constants.KubernetesV1}, - Name: volumeName, - }, - }) - } - - // add pod label - if _, ok := currentPodMap[podName]; !ok { - *tags = append(*tags, xuanwuV1.Tag{ - ResourceInfo: xuanwuV1.ResourceInfo{ - TypeMeta: metaV1.TypeMeta{Kind: constants.PodKind, APIVersion: constants.KubernetesV1}, - Name: podName, - Namespace: namespace, - }, - }) - } -} - -func deletePodLabel(ctx context.Context, volumeID, targetPath string) error { - var err error - _, volumeName := utils.SplitVolumeId(volumeID) - topoName := pkgUtils.GetTopoName(volumeName) - - // lock for rt name - if err = labelLock.AcquireCmLock(ctx, labelLock.RTLockConfigMap, topoName); err != nil { - log.AddContext(ctx).Errorf("acquire rt lock failed, key: %s err: %v", topoName, err) - return err - } - defer func(ctx context.Context, lockKey string) { - if err = labelLock.ReleaseCmlock(ctx, labelLock.RTLockConfigMap, lockKey); err != nil { - log.AddContext(ctx).Errorf("release rt lock failed, key: %s err: %v", lockKey, err) - } - }(ctx, topoName) - - var topo *xuanwuV1.ResourceTopology - var flag bool - if topo, flag, err = checkRTPodDeletedAndGet(ctx, topoName); err != nil { - log.AddContext(ctx).Infof("check pod tag has been deleted failed, topoName: %s, err: %v, topoName, err") - return err - } - if flag { - log.AddContext(ctx).Infof("topo pod tag has been deleted, topoName: %s", topoName) - return nil - } - - pods, podName, namespace, sc, pvName, err := getTargetPathPodRelateInfo(ctx, targetPath) - if err != nil { - log.AddContext(ctx).Errorf("get targetPath pvRelateInfo failed, targetPath: %v, err: %v", targetPath, err) - return err - } - if sc == "" { - log.AddContext(ctx).Infof("deleteLabel static pv, volumeID: %v, targetPath: %v", volumeID, targetPath) - return nil - } - - return deleteTopologiesLabel(ctx, deleteTopologiesLabelParam{ - topo: topo, - pods: pods, - pvName: pvName, - targetPath: targetPath, - podName: podName, - namespace: namespace, - volumeName: volumeName, - topoName: topoName, - }) -} - -func checkRTPodDeletedAndGet(ctx context.Context, topoName string) (*xuanwuV1.ResourceTopology, bool, error) { - topo, err := app.GetGlobalConfig().BackendUtils.XuanwuV1().ResourceTopologies().Get(ctx, topoName, - metaV1.GetOptions{}) - if k8sError.IsNotFound(err) { - log.AddContext(ctx).Infof("node delete label success, topo not found, "+ - "data: %+v topoName: %s", topo, topoName) - return topo, false, err - } - if err != nil { - log.AddContext(ctx).Errorf("get topo failed, topoName: %v, err: %v", topoName, err) - return topo, false, err - } - if topo == nil { - log.AddContext(ctx).Errorf("get nil topo, topoName: %v", topoName) - return topo, false, err - } - - for _, item := range topo.Spec.Tags { - if item.Kind == constants.PodKind { - return topo, false, nil - } - } - return topo, true, nil -} - -func deleteTopologiesLabel(ctx context.Context, param deleteTopologiesLabelParam) error { - // filter pod - log.AddContext(ctx).Debugf("before delete rt: %s podName: %s len: %v", param.topoName, param.podName, - len(param.topo.Spec.Tags)) - param.topo.Spec.Tags = filterDeleteTopoTag(param) - log.AddContext(ctx).Debugf("after delete rt: %s podName: %s len: %v", param.topoName, param.podName, - len(param.topo.Spec.Tags)) - - // update topo - _, err := app.GetGlobalConfig().BackendUtils.XuanwuV1().ResourceTopologies().Update(ctx, - param.topo, metaV1.UpdateOptions{}) - if err != nil { - log.AddContext(ctx).Errorf("node delete label failed, data:%+v, volumeName: %v targetPath: %v err: %v", - param.topo, param.volumeName, param.targetPath, err) - return err - } - - log.AddContext(ctx).Infof("node delete label success, data: %+v volumeName: %v targetPath: %v", - param.topo, param.volumeName, param.targetPath) - return nil -} - -func filterDeleteTopoTag(param deleteTopologiesLabelParam) []xuanwuV1.Tag { - var newTags []xuanwuV1.Tag - var containsPod = func(tag xuanwuV1.Tag, podItems []coreV1.Pod) bool { - for _, item := range podItems { - if tag.Name == item.Name && tag.Namespace == item.Namespace { - return true - } - } - return false - } - for _, tag := range param.topo.Spec.Tags { - if tag.Kind != constants.PodKind { - newTags = append(newTags, tag) - continue - } - - if tag.Kind == constants.PodKind && tag.Name == param.podName && tag.Namespace == param.namespace { - continue - } - - if containsPod(tag, param.pods) { - newTags = append(newTags, tag) - } - } - - return newTags -} - -// getTargetPathPodRelateInfo get podName nameSpace sc volumeName -func getTargetPathPodRelateInfo(ctx context.Context, targetPath string) ([]coreV1.Pod, - string, string, string, string, error) { - k8sAPI := app.GetGlobalConfig().K8sUtils - - targetPathArr := strings.Split(targetPath, "/") - if len(targetPathArr) < 2 { - return nil, "", "", "", "", pkgUtils.Errorf(ctx, "targetPath: %s is invalid", targetPath) - } - volumeName := targetPathArr[len(targetPathArr)-2] - - log.AddContext(ctx).Debugf("targetPath: %v, volumeName: %v", targetPath, volumeName) - - // get pv info - pv, err := k8sAPI.GetPVByName(ctx, volumeName) - if err != nil { - log.AddContext(ctx).Errorf("get pv failed, pvName: %v, err: %v", volumeName, err) - return nil, "", "", "", volumeName, err - } - if pv == nil { - log.AddContext(ctx).Errorf("get nil pv, pvName: %v", volumeName) - return nil, "", "", "", "", errors.New("pv is nil") - } - if pv.Spec.ClaimRef == nil { - log.AddContext(ctx).Errorf("get nil pv.Spec.ClaimRef, pvName: %v", volumeName) - return nil, "", "", "", "", errors.New("pv.Spec.ClaimRef is nil") - } - - // get all pod in namespace - pods, err := k8sAPI.ListPods(ctx, pv.Spec.ClaimRef.Namespace) - if err != nil { - log.AddContext(ctx).Errorf("list pods failed, namespace: %v, err: %v", pv.Spec.ClaimRef.Namespace, err) - return nil, "", "", "", "", err - } - - // get target pod name - log.AddContext(ctx).Debugf("getPodInfo podList: %+v, targetPath: %v", pods.Items, targetPath) - for _, pod := range pods.Items { - if strings.Contains(targetPath, string(pod.UID)) { - return pods.Items, pod.Name, pv.Spec.ClaimRef.Namespace, pv.Spec.StorageClassName, volumeName, nil - } - } - - return pods.Items, "", pv.Spec.ClaimRef.Namespace, pv.Spec.StorageClassName, volumeName, nil -} diff --git a/helm/esdk/crds/resourcetopologies/xuanwu.huawei.io_resourcetopologies.yaml b/helm/esdk/crds/resourcetopologies/xuanwu.huawei.io_resourcetopologies.yaml deleted file mode 100644 index 74387e6b..00000000 --- a/helm/esdk/crds/resourcetopologies/xuanwu.huawei.io_resourcetopologies.yaml +++ /dev/null @@ -1,174 +0,0 @@ ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.8.0 - creationTimestamp: null - name: resourcetopologies.xuanwu.huawei.io -spec: - group: xuanwu.huawei.io - names: - kind: ResourceTopology - listKind: ResourceTopologyList - plural: resourcetopologies - shortNames: - - rt - singular: resourcetopology - scope: Cluster - versions: - - additionalPrinterColumns: - - jsonPath: .spec.provisioner - name: Provisioner - type: string - - jsonPath: .spec.volumeHandle - name: VolumeHandle - type: string - - jsonPath: .status.status - name: Status - type: string - - jsonPath: .metadata.creationTimestamp - name: Age - type: date - name: v1 - schema: - openAPIV3Schema: - description: ResourceTopology is the Schema for the ResourceTopologys API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - properties: - provisioner: - description: Provisioner is the volume provisioner name - type: string - tags: - description: Tags defines pv and other relationships and ownership - items: - description: Tag defines pv and other relationships and ownership - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this - representation of an object. Servers should convert recognized - schemas to the latest internal value, and may reject unrecognized - values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource - this object represents. Servers may infer this from the endpoint - the client submits requests to. Cannot be updated. In CamelCase. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - name: - description: Name is the name of the resource - type: string - namespace: - description: NameSpace is the namespace of the resource - type: string - owner: - description: Owner defines who does the resource belongs to - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of - this representation of an object. Servers should convert - recognized schemas to the latest internal value, and may - reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST - resource this object represents. Servers may infer this - from the endpoint the client submits requests to. Cannot - be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - name: - description: Name is the name of the resource - type: string - namespace: - description: NameSpace is the namespace of the resource - type: string - type: object - type: object - type: array - volumeHandle: - description: VolumeHandle is the backend name and identity of the - volume, format as . - type: string - required: - - provisioner - - tags - - volumeHandle - type: object - status: - properties: - status: - description: Status is the status of the ResourceTopology - type: string - tags: - description: Tags defines pv and other relationships and ownership - items: - description: Tag defines pv and other relationships and ownership - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this - representation of an object. Servers should convert recognized - schemas to the latest internal value, and may reject unrecognized - values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource - this object represents. Servers may infer this from the endpoint - the client submits requests to. Cannot be updated. In CamelCase. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - name: - description: Name is the name of the resource - type: string - namespace: - description: NameSpace is the namespace of the resource - type: string - owner: - description: Owner defines who does the resource belongs to - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of - this representation of an object. Servers should convert - recognized schemas to the latest internal value, and may - reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST - resource this object represents. Servers may infer this - from the endpoint the client submits requests to. Cannot - be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - name: - description: Name is the name of the resource - type: string - namespace: - description: NameSpace is the namespace of the resource - type: string - type: object - type: object - type: array - type: object - type: object - served: true - storage: true - subresources: - status: {} -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] diff --git a/manual/esdk/deploy/huawei-csi-controller-multi.yaml b/manual/esdk/deploy/huawei-csi-controller-multi.yaml deleted file mode 100644 index a643f313..00000000 --- a/manual/esdk/deploy/huawei-csi-controller-multi.yaml +++ /dev/null @@ -1,944 +0,0 @@ ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: storage-backend-controller-role - labels: - provisioner: csi.huawei.com -rules: - - apiGroups: [ "admissionregistration.k8s.io" ] - resources: [ "validatingwebhookconfigurations" ] - verbs: [ "create", "get", "update", "delete" ] - - apiGroups: [ "" ] - resources: [ "configmaps", "secrets", "events" ] - verbs: [ "create", "get", "update", "delete" ] - - apiGroups: [ "coordination.k8s.io" ] - resources: [ "leases" ] - verbs: [ "create", "get", "update", "delete" ] - - apiGroups: [ "xuanwu.huawei.io" ] - resources: [ "storagebackendclaims", "storagebackendclaims/status", "storagebackendcontents", - "storagebackendcontents/status" ] - verbs: [ "create", "get", "list", "watch", "update", "delete" ] - ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: storage-backend-sidecar-role - labels: - provisioner: csi.huawei.com -rules: - - apiGroups: [ "" ] - resources: [ "events", "configmaps" ] - verbs: [ "create", "get", "update", "delete" ] - - apiGroups: [ "coordination.k8s.io" ] - resources: [ "leases" ] - verbs: [ "create", "get", "update", "delete" ] - - apiGroups: [ "xuanwu.huawei.io" ] - resources: [ "storagebackendcontents", "storagebackendcontents/status" ] - verbs: [ "get", "list", "watch", "update" ] - ---- -kind: ClusterRoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: storage-backend-controller-binding - labels: - app: xuanwu-volume-service - provisioner: csi.huawei.com -subjects: - - kind: ServiceAccount - name: huawei-csi-controller - namespace: huawei-csi -roleRef: - kind: ClusterRole - name: storage-backend-controller-role - apiGroup: rbac.authorization.k8s.io - ---- -kind: ClusterRoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: storage-backend-sidecar-binding - labels: - app: xuanwu-volume-service - provisioner: csi.huawei.com -subjects: - - kind: ServiceAccount - name: huawei-csi-controller - namespace: huawei-csi -roleRef: - kind: ClusterRole - name: storage-backend-sidecar-role - apiGroup: rbac.authorization.k8s.io ---- -apiVersion: v1 -kind: ServiceAccount -metadata: - labels: - provisioner: csi.huawei.com - name: huawei-csi-controller - namespace: huawei-csi ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: RoleBinding -metadata: - labels: - provisioner: csi.huawei.com - name: huawei-csi-attacher-role-cfg - namespace: huawei-csi -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: Role - name: huawei-csi-attacher-cfg -subjects: - - kind: ServiceAccount - name: huawei-csi-controller - namespace: huawei-csi ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - labels: - provisioner: csi.huawei.com - name: huawei-csi-attacher-cfg - namespace: huawei-csi -rules: - - apiGroups: - - coordination.k8s.io - resources: - - leases - verbs: - - get - - watch - - list - - delete - - update - - create ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: RoleBinding -metadata: - labels: - provisioner: csi.huawei.com - name: huawei-csi-provisioner-role-cfg - namespace: huawei-csi -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: Role - name: huawei-csi-provisioner-cfg -subjects: - - kind: ServiceAccount - name: huawei-csi-controller - namespace: huawei-csi ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - labels: - provisioner: csi.huawei.com - name: huawei-csi-provisioner-cfg - namespace: huawei-csi -rules: - - apiGroups: - - "" - resources: - - endpoints - verbs: - - get - - watch - - list - - delete - - update - - create - - apiGroups: - - coordination.k8s.io - resources: - - leases - verbs: - - get - - watch - - list - - delete - - update - - create - - apiGroups: - - storage.k8s.io - resources: - - csistoragecapacities - verbs: - - get - - list - - watch - - create - - update - - patch - - delete - - apiGroups: - - "" - resources: - - pods - verbs: - - get - - apiGroups: - - apps - resources: - - replicasets - verbs: - - get ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - labels: - provisioner: csi.huawei.com - name: huawei-csi-provisioner-role -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: huawei-csi-provisioner-runner -subjects: - - kind: ServiceAccount - name: huawei-csi-controller - namespace: huawei-csi ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - labels: - provisioner: csi.huawei.com - name: huawei-csi-provisioner-runner -rules: - - apiGroups: - - "" - resources: - - persistentvolumes - verbs: - - get - - list - - watch - - create - - delete - - update - - apiGroups: - - "" - resources: - - persistentvolumeclaims - verbs: - - get - - list - - watch - - update - - apiGroups: - - storage.k8s.io - resources: - - storageclasses - verbs: - - get - - list - - watch - - apiGroups: - - "" - resources: - - events - verbs: - - list - - watch - - create - - update - - patch - - apiGroups: - - snapshot.storage.k8s.io - resources: - - volumesnapshots - verbs: - - get - - list - - apiGroups: - - snapshot.storage.k8s.io - resources: - - volumesnapshotcontents - verbs: - - get - - list - - apiGroups: - - storage.k8s.io - resources: - - csinodes - verbs: - - get - - list - - watch - - apiGroups: - - "" - resources: - - nodes - verbs: - - get - - list - - watch - - apiGroups: - - storage.k8s.io - resources: - - volumeattachments - verbs: - - get - - list - - watch - - update ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - labels: - provisioner: csi.huawei.com - name: huawei-csi-attacher-role -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: huawei-csi-attacher-runner -subjects: - - kind: ServiceAccount - name: huawei-csi-controller - namespace: huawei-csi ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - labels: - provisioner: csi.huawei.com - name: huawei-csi-attacher-runner -rules: - - apiGroups: - - "" - resources: - - persistentvolumes - verbs: - - get - - list - - watch - - patch - - update - - apiGroups: - - storage.k8s.io - resources: - - csinodes - verbs: - - get - - list - - watch - - apiGroups: - - storage.k8s.io - resources: - - volumeattachments - verbs: - - get - - list - - watch - - patch - - update - - apiGroups: - - storage.k8s.io - resources: - - volumeattachments/status - verbs: - - patch - ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: RoleBinding -metadata: - labels: - provisioner: csi.huawei.com - name: huawei-csi-csi-resizer-role-cfg - namespace: huawei-csi -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: Role - name: huawei-csi-resizer-cfg -subjects: - - kind: ServiceAccount - name: huawei-csi-controller - namespace: huawei-csi ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - labels: - provisioner: csi.huawei.com - name: huawei-csi-resizer-cfg - namespace: huawei-csi -rules: - - apiGroups: - - coordination.k8s.io - resources: - - leases - verbs: - - get - - watch - - list - - delete - - update - - create ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - labels: - provisioner: csi.huawei.com - name: huawei-csi-csi-resizer-role -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: huawei-csi-resizer-runner -subjects: - - kind: ServiceAccount - name: huawei-csi-controller - namespace: huawei-csi ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - labels: - provisioner: csi.huawei.com - name: huawei-csi-resizer-runner -rules: - - apiGroups: - - "" - resources: - - persistentvolumes - verbs: - - get - - list - - watch - - patch - - update - - apiGroups: - - "" - resources: - - persistentvolumeclaims - verbs: - - get - - list - - watch - - apiGroups: - - "" - resources: - - pods - verbs: - - get - - list - - watch - - apiGroups: - - "" - resources: - - persistentvolumeclaims/status - verbs: - - patch - - update - - apiGroups: - - "" - resources: - - events - verbs: - - list - - watch - - create - - update - - patch - ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - labels: - provisioner: csi.huawei.com - name: huawei-csi-csi-snapshotter-role -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: huawei-csi-snapshotter-runner -subjects: - - kind: ServiceAccount - name: huawei-csi-controller - namespace: huawei-csi ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - labels: - provisioner: csi.huawei.com - name: huawei-csi-snapshotter-runner -rules: - - apiGroups: - - "" - resources: - - events - verbs: - - list - - watch - - create - - update - - patch - - apiGroups: - - snapshot.storage.k8s.io - resources: - - volumesnapshotclasses - verbs: - - get - - list - - watch - - apiGroups: - - snapshot.storage.k8s.io - resources: - - volumesnapshotcontents - verbs: - - create - - get - - list - - watch - - update - - delete - - patch - - apiGroups: - - snapshot.storage.k8s.io - resources: - - volumesnapshotcontents/status - verbs: - - update - - patch ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - labels: - provisioner: csi.huawei.com - name: huawei-csi-snapshot-controller-role -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: huawei-csi-snapshot-controller-runner -subjects: - - kind: ServiceAccount - name: huawei-csi-controller - namespace: huawei-csi ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - labels: - provisioner: csi.huawei.com - name: huawei-csi-snapshot-controller-runner -rules: - - apiGroups: - - "" - resources: - - persistentvolumes - verbs: - - get - - list - - watch - - apiGroups: - - "" - resources: - - persistentvolumeclaims - verbs: - - get - - list - - watch - - update - - apiGroups: - - storage.k8s.io - resources: - - storageclasses - verbs: - - get - - list - - watch - - apiGroups: - - "" - resources: - - events - verbs: - - list - - watch - - create - - update - - patch - - apiGroups: - - snapshot.storage.k8s.io - resources: - - volumesnapshotclasses - verbs: - - get - - list - - watch - - apiGroups: - - snapshot.storage.k8s.io - resources: - - volumesnapshotcontents - verbs: - - create - - get - - list - - watch - - update - - delete - - patch - - apiGroups: - - snapshot.storage.k8s.io - resources: - - volumesnapshotcontents/status - verbs: - - patch - - apiGroups: - - snapshot.storage.k8s.io - resources: - - volumesnapshots - verbs: - - get - - list - - watch - - update - - patch - - apiGroups: - - snapshot.storage.k8s.io - resources: - - volumesnapshots/status - verbs: - - update - - patch - - apiGroups: - - "" - resources: - - nodes - verbs: - - get - - list - - watch ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - labels: - provisioner: csi.huawei.com - name: huawei-csi-controller-runner -rules: - - apiGroups: - - "" - resources: - - secrets - verbs: - - get - - apiGroups: [ "xuanwu.huawei.io" ] - resources: [ "resourcetopologies" ] - verbs: [ "create", "get", "update", "delete" ] ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - labels: - provisioner: csi.huawei.com - name: huawei-csi-controller-role -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: huawei-csi-controller-runner -subjects: - - kind: ServiceAccount - name: huawei-csi-controller - namespace: huawei-csi - ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - labels: - provisioner: csi.huawei.com - name: huawei-csi-controller - namespace: huawei-csi -spec: - replicas: 2 - strategy: - type: Recreate - selector: - matchLabels: - app: huawei-csi-controller - provisioner: csi.huawei.com - template: - metadata: - labels: - app: huawei-csi-controller - provisioner: csi.huawei.com - spec: - hostNetwork: true - serviceAccount: huawei-csi-controller - containers: - - name: liveness-probe - args: - - "--csi-address=/csi/csi.sock" - - "--health-port=9808" - image: k8s.gcr.io/sig-storage/livenessprobe:v2.5.0 - imagePullPolicy: "IfNotPresent" - volumeMounts: - - mountPath: /csi - name: socket-dir - resources: - limits: - cpu: 100m - memory: 128Mi - requests: - cpu: 10m - memory: 128Mi - - name: csi-provisioner - args: - - "--csi-address=$(ADDRESS)" - - "--timeout=6h" - - "--volume-name-prefix=pvc" - - "--leader-election" - env: - - name: ADDRESS - value: /csi/csi.sock - image: k8s.gcr.io/sig-storage/csi-provisioner:v3.0.0 - imagePullPolicy: "IfNotPresent" - volumeMounts: - - mountPath: /csi - name: socket-dir - resources: - limits: - cpu: 300m - memory: 512Mi - requests: - cpu: 50m - memory: 128Mi - # When 'isCreate' is true and 'attachRequired' is false, csi-attacher sidecar will not be deployed - - name: csi-attacher - args: - - "--csi-address=$(ADDRESS)" - - "--leader-election" - env: - - name: ADDRESS - value: /csi/csi.sock - image: k8s.gcr.io/sig-storage/csi-attacher:v3.4.0 - imagePullPolicy: "IfNotPresent" - volumeMounts: - - mountPath: /csi - name: socket-dir - resources: - limits: - cpu: 300m - memory: 512Mi - requests: - cpu: 50m - memory: 128Mi - - name: csi-resizer - args: - - "--v=5" - - "--csi-address=$(ADDRESS)" - - "--handle-volume-inuse-error=false" - - "--leader-election" - env: - - name: ADDRESS - value: /csi/csi.sock - image: k8s.gcr.io/sig-storage/csi-resizer:v1.4.0 - imagePullPolicy: IfNotPresent - volumeMounts: - - mountPath: /csi - name: socket-dir - resources: - limits: - cpu: 300m - memory: 512Mi - requests: - cpu: 50m - memory: 128Mi - - name: csi-snapshotter - args: - - "--v=5" - - "--csi-address=$(ADDRESS)" - - "--leader-election" - env: - - name: ADDRESS - value: /csi/csi.sock - image: k8s.gcr.io/sig-storage/csi-snapshotter:v4.2.1 - imagePullPolicy: "IfNotPresent" - volumeMounts: - - mountPath: /csi - name: socket-dir - resources: - limits: - cpu: 300m - memory: 512Mi - requests: - cpu: 50m - memory: 128Mi - - name: snapshot-controller - args: - - "--v=5" - - "--leader-election" - image: k8s.gcr.io/sig-storage/snapshot-controller:v4.2.1 - imagePullPolicy: "IfNotPresent" - resources: - limits: - cpu: 300m - memory: 512Mi - requests: - cpu: 50m - memory: 128Mi - - name: storage-backend-controller - image: storage-backend-controller:4.3.0 - imagePullPolicy: "IfNotPresent" - env: - - name: CSI_NAMESPACE - valueFrom: - fieldRef: - apiVersion: v1 - fieldPath: metadata.namespace - - name: POD_IP - valueFrom: - fieldRef: - fieldPath: status.podIP - args: - - "--logging-module=file" - - "--log-level=info" - - "--log-file-dir=/var/log/huawei" - - "--log-file-size=20M" - - "--max-backups=9" - - "--web-hook-port=4433" - - "--web-hook-address=$(POD_IP)" - - "--enable-leader-election=true" - - "--leader-lease-duration=8s" - - "--leader-renew-deadline=6s" - - "--leader-retry-period=2s" - ports: - - containerPort: 4433 - volumeMounts: - - mountPath: /var/log - name: log - - mountPath: /etc/localtime - name: host-time - resources: - limits: - cpu: 300m - memory: 512Mi - requests: - cpu: 50m - memory: 128Mi - - name: storage-backend-sidecar - image: storage-backend-sidecar:4.3.0 - imagePullPolicy: "IfNotPresent" - env: - - name: DRCSI_ENDPOINT - value: /csi/dr-csi.sock - - name: CSI_NAMESPACE - valueFrom: - fieldRef: - apiVersion: v1 - fieldPath: metadata.namespace - args: - - "--logging-module=file" - - "--log-level=info" - - "--log-file-dir=/var/log/huawei" - - "--log-file-size=20M" - - "--max-backups=9" - - "--backend-update-interval=60" - - "--dr-endpoint=$(DRCSI_ENDPOINT)" - - "--enable-leader-election=true" - - "--leader-lease-duration=8s" - - "--leader-renew-deadline=6s" - - "--leader-retry-period=2s" - volumeMounts: - - mountPath: /csi - name: socket-dir - - mountPath: /var/log - name: log - - mountPath: /etc/localtime - name: host-time - resources: - limits: - cpu: 300m - memory: 512Mi - requests: - cpu: 50m - memory: 128Mi - - name: huawei-csi-driver - image: huawei-csi:4.3.0 - imagePullPolicy: "IfNotPresent" - args: - - "--endpoint=$(CSI_ENDPOINT)" - - "--dr-endpoint=$(DRCSI_ENDPOINT)" - - "--controller" - - "--backend-update-interval=60" - - "--driver-name=csi.huawei.com" - - "--logging-module=file" - - "--log-level=info" - - "--volume-name-prefix=pvc" - - "--enable-label=false" - - "--log-file-dir=/var/log/huawei" - - "--log-file-size=20M" - - "--max-backups=9" - env: - - name: CSI_ENDPOINT - value: /csi/csi.sock - - name: DRCSI_ENDPOINT - value: /csi/dr-csi.sock - - name: CSI_NAMESPACE - valueFrom: - fieldRef: - apiVersion: v1 - fieldPath: metadata.namespace - livenessProbe: - failureThreshold: 5 - httpGet: - path: /healthz - port: healthz - initialDelaySeconds: 10 - periodSeconds: 60 - timeoutSeconds: 3 - ports: - - containerPort: 9808 - name: healthz - protocol: TCP - volumeMounts: - - mountPath: /csi - name: socket-dir - - mountPath: /var/log - name: log - - mountPath: /etc/localtime - name: host-time - resources: - limits: - cpu: 500m - memory: 1Gi - requests: - cpu: 50m - memory: 128Mi - volumes: - - emptyDir: null - name: socket-dir - - hostPath: - path: /var/log/ - type: Directory - name: log - - hostPath: - path: /etc/localtime - type: File - name: host-time - ---- -apiVersion: v1 -kind: Service -metadata: - name: huawei-csi-controller - namespace: huawei-csi - labels: - app: huawei-csi-controller - provisioner: csi.huawei.com -spec: - selector: - app: huawei-csi-controller - ports: - - name: storage-backend-controller - protocol: TCP - port: 4433 - targetPort: 4433 \ No newline at end of file diff --git a/pkg/client/clientset/versioned/typed/xuanwu/v1/fake/fake_resourcetopology.go b/pkg/client/clientset/versioned/typed/xuanwu/v1/fake/fake_resourcetopology.go deleted file mode 100644 index 7e4cda83..00000000 --- a/pkg/client/clientset/versioned/typed/xuanwu/v1/fake/fake_resourcetopology.go +++ /dev/null @@ -1,130 +0,0 @@ -/* - Copyright (c) Huawei Technologies Co., Ltd. 2022-2023. All rights reserved. - - 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 ( - "context" - xuanwuv1 "huawei-csi-driver/client/apis/xuanwu/v1" - - 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" -) - -// FakeResourceTopologies implements ResourceTopologyInterface -type FakeResourceTopologies struct { - Fake *FakeXuanwuV1 -} - -var resourcetopologiesResource = schema.GroupVersionResource{Group: "xuanwu.huawei.io", Version: "v1", Resource: "resourcetopologies"} - -var resourcetopologiesKind = schema.GroupVersionKind{Group: "xuanwu.huawei.io", Version: "v1", Kind: "ResourceTopology"} - -// Get takes name of the resourceTopology, and returns the corresponding resourceTopology object, and an error if there is any. -func (c *FakeResourceTopologies) Get(ctx context.Context, name string, options v1.GetOptions) (result *xuanwuv1.ResourceTopology, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootGetAction(resourcetopologiesResource, name), &xuanwuv1.ResourceTopology{}) - if obj == nil { - return nil, err - } - return obj.(*xuanwuv1.ResourceTopology), err -} - -// List takes label and field selectors, and returns the list of ResourceTopologies that match those selectors. -func (c *FakeResourceTopologies) List(ctx context.Context, opts v1.ListOptions) (result *xuanwuv1.ResourceTopologyList, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootListAction(resourcetopologiesResource, resourcetopologiesKind, opts), &xuanwuv1.ResourceTopologyList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &xuanwuv1.ResourceTopologyList{ListMeta: obj.(*xuanwuv1.ResourceTopologyList).ListMeta} - for _, item := range obj.(*xuanwuv1.ResourceTopologyList).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 resourceTopologies. -func (c *FakeResourceTopologies) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewRootWatchAction(resourcetopologiesResource, opts)) -} - -// Create takes the representation of a resourceTopology and creates it. Returns the server's representation of the resourceTopology, and an error, if there is any. -func (c *FakeResourceTopologies) Create(ctx context.Context, resourceTopology *xuanwuv1.ResourceTopology, opts v1.CreateOptions) (result *xuanwuv1.ResourceTopology, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootCreateAction(resourcetopologiesResource, resourceTopology), &xuanwuv1.ResourceTopology{}) - if obj == nil { - return nil, err - } - return obj.(*xuanwuv1.ResourceTopology), err -} - -// Update takes the representation of a resourceTopology and updates it. Returns the server's representation of the resourceTopology, and an error, if there is any. -func (c *FakeResourceTopologies) Update(ctx context.Context, resourceTopology *xuanwuv1.ResourceTopology, opts v1.UpdateOptions) (result *xuanwuv1.ResourceTopology, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootUpdateAction(resourcetopologiesResource, resourceTopology), &xuanwuv1.ResourceTopology{}) - if obj == nil { - return nil, err - } - return obj.(*xuanwuv1.ResourceTopology), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeResourceTopologies) UpdateStatus(ctx context.Context, resourceTopology *xuanwuv1.ResourceTopology, opts v1.UpdateOptions) (*xuanwuv1.ResourceTopology, error) { - obj, err := c.Fake. - Invokes(testing.NewRootUpdateSubresourceAction(resourcetopologiesResource, "status", resourceTopology), &xuanwuv1.ResourceTopology{}) - if obj == nil { - return nil, err - } - return obj.(*xuanwuv1.ResourceTopology), err -} - -// Delete takes name of the resourceTopology and deletes it. Returns an error if one occurs. -func (c *FakeResourceTopologies) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewRootDeleteActionWithOptions(resourcetopologiesResource, name, opts), &xuanwuv1.ResourceTopology{}) - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeResourceTopologies) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewRootDeleteCollectionAction(resourcetopologiesResource, listOpts) - - _, err := c.Fake.Invokes(action, &xuanwuv1.ResourceTopologyList{}) - return err -} - -// Patch applies the patch and returns the patched resourceTopology. -func (c *FakeResourceTopologies) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *xuanwuv1.ResourceTopology, err error) { - obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceAction(resourcetopologiesResource, name, pt, data, subresources...), &xuanwuv1.ResourceTopology{}) - if obj == nil { - return nil, err - } - return obj.(*xuanwuv1.ResourceTopology), err -} diff --git a/pkg/client/clientset/versioned/typed/xuanwu/v1/resourcetopology.go b/pkg/client/clientset/versioned/typed/xuanwu/v1/resourcetopology.go deleted file mode 100644 index 47e65408..00000000 --- a/pkg/client/clientset/versioned/typed/xuanwu/v1/resourcetopology.go +++ /dev/null @@ -1,181 +0,0 @@ -/* - Copyright (c) Huawei Technologies Co., Ltd. 2022-2023. All rights reserved. - - 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 v1 - -import ( - "context" - v1 "huawei-csi-driver/client/apis/xuanwu/v1" - scheme "huawei-csi-driver/pkg/client/clientset/versioned/scheme" - "time" - - metav1 "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" -) - -// ResourceTopologiesGetter has a method to return a ResourceTopologyInterface. -// A group's client should implement this interface. -type ResourceTopologiesGetter interface { - ResourceTopologies() ResourceTopologyInterface -} - -// ResourceTopologyInterface has methods to work with ResourceTopology resources. -type ResourceTopologyInterface interface { - Create(ctx context.Context, resourceTopology *v1.ResourceTopology, opts metav1.CreateOptions) (*v1.ResourceTopology, error) - Update(ctx context.Context, resourceTopology *v1.ResourceTopology, opts metav1.UpdateOptions) (*v1.ResourceTopology, error) - UpdateStatus(ctx context.Context, resourceTopology *v1.ResourceTopology, opts metav1.UpdateOptions) (*v1.ResourceTopology, error) - Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error - DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error - Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.ResourceTopology, error) - List(ctx context.Context, opts metav1.ListOptions) (*v1.ResourceTopologyList, error) - Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.ResourceTopology, err error) - ResourceTopologyExpansion -} - -// resourceTopologies implements ResourceTopologyInterface -type resourceTopologies struct { - client rest.Interface -} - -// newResourceTopologies returns a ResourceTopologies -func newResourceTopologies(c *XuanwuV1Client) *resourceTopologies { - return &resourceTopologies{ - client: c.RESTClient(), - } -} - -// Get takes name of the resourceTopology, and returns the corresponding resourceTopology object, and an error if there is any. -func (c *resourceTopologies) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.ResourceTopology, err error) { - result = &v1.ResourceTopology{} - err = c.client.Get(). - Resource("resourcetopologies"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of ResourceTopologies that match those selectors. -func (c *resourceTopologies) List(ctx context.Context, opts metav1.ListOptions) (result *v1.ResourceTopologyList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1.ResourceTopologyList{} - err = c.client.Get(). - Resource("resourcetopologies"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested resourceTopologies. -func (c *resourceTopologies) Watch(ctx context.Context, opts metav1.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("resourcetopologies"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a resourceTopology and creates it. Returns the server's representation of the resourceTopology, and an error, if there is any. -func (c *resourceTopologies) Create(ctx context.Context, resourceTopology *v1.ResourceTopology, opts metav1.CreateOptions) (result *v1.ResourceTopology, err error) { - result = &v1.ResourceTopology{} - err = c.client.Post(). - Resource("resourcetopologies"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(resourceTopology). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a resourceTopology and updates it. Returns the server's representation of the resourceTopology, and an error, if there is any. -func (c *resourceTopologies) Update(ctx context.Context, resourceTopology *v1.ResourceTopology, opts metav1.UpdateOptions) (result *v1.ResourceTopology, err error) { - result = &v1.ResourceTopology{} - err = c.client.Put(). - Resource("resourcetopologies"). - Name(resourceTopology.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(resourceTopology). - Do(ctx). - Into(result) - return -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *resourceTopologies) UpdateStatus(ctx context.Context, resourceTopology *v1.ResourceTopology, opts metav1.UpdateOptions) (result *v1.ResourceTopology, err error) { - result = &v1.ResourceTopology{} - err = c.client.Put(). - Resource("resourcetopologies"). - Name(resourceTopology.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(resourceTopology). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the resourceTopology and deletes it. Returns an error if one occurs. -func (c *resourceTopologies) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - return c.client.Delete(). - Resource("resourcetopologies"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *resourceTopologies) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Resource("resourcetopologies"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched resourceTopology. -func (c *resourceTopologies) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.ResourceTopology, err error) { - result = &v1.ResourceTopology{} - err = c.client.Patch(pt). - Resource("resourcetopologies"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/informers/externalversions/xuanwu/v1/resourcetopology.go b/pkg/client/informers/externalversions/xuanwu/v1/resourcetopology.go deleted file mode 100644 index 3d004a1f..00000000 --- a/pkg/client/informers/externalversions/xuanwu/v1/resourcetopology.go +++ /dev/null @@ -1,86 +0,0 @@ -/* - Copyright (c) Huawei Technologies Co., Ltd. 2022-2023. All rights reserved. - - 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 v1 - -import ( - "context" - xuanwuv1 "huawei-csi-driver/client/apis/xuanwu/v1" - versioned "huawei-csi-driver/pkg/client/clientset/versioned" - internalinterfaces "huawei-csi-driver/pkg/client/informers/externalversions/internalinterfaces" - v1 "huawei-csi-driver/pkg/client/listers/xuanwu/v1" - time "time" - - metav1 "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" -) - -// ResourceTopologyInformer provides access to a shared informer and lister for -// ResourceTopologies. -type ResourceTopologyInformer interface { - Informer() cache.SharedIndexInformer - Lister() v1.ResourceTopologyLister -} - -type resourceTopologyInformer struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc -} - -// NewResourceTopologyInformer constructs a new informer for ResourceTopology 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 NewResourceTopologyInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredResourceTopologyInformer(client, resyncPeriod, indexers, nil) -} - -// NewFilteredResourceTopologyInformer constructs a new informer for ResourceTopology 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 NewFilteredResourceTopologyInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { - return cache.NewSharedIndexInformer( - &cache.ListWatch{ - ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.XuanwuV1().ResourceTopologies().List(context.TODO(), options) - }, - WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.XuanwuV1().ResourceTopologies().Watch(context.TODO(), options) - }, - }, - &xuanwuv1.ResourceTopology{}, - resyncPeriod, - indexers, - ) -} - -func (f *resourceTopologyInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredResourceTopologyInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) -} - -func (f *resourceTopologyInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&xuanwuv1.ResourceTopology{}, f.defaultInformer) -} - -func (f *resourceTopologyInformer) Lister() v1.ResourceTopologyLister { - return v1.NewResourceTopologyLister(f.Informer().GetIndexer()) -} diff --git a/pkg/client/listers/xuanwu/v1/resourcetopology.go b/pkg/client/listers/xuanwu/v1/resourcetopology.go deleted file mode 100644 index 933e349a..00000000 --- a/pkg/client/listers/xuanwu/v1/resourcetopology.go +++ /dev/null @@ -1,66 +0,0 @@ -/* - Copyright (c) Huawei Technologies Co., Ltd. 2022-2023. All rights reserved. - - 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 v1 - -import ( - v1 "huawei-csi-driver/client/apis/xuanwu/v1" - - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" -) - -// ResourceTopologyLister helps list ResourceTopologies. -// All objects returned here must be treated as read-only. -type ResourceTopologyLister interface { - // List lists all ResourceTopologies in the indexer. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1.ResourceTopology, err error) - // Get retrieves the ResourceTopology from the index for a given name. - // Objects returned here must be treated as read-only. - Get(name string) (*v1.ResourceTopology, error) - ResourceTopologyListerExpansion -} - -// resourceTopologyLister implements the ResourceTopologyLister interface. -type resourceTopologyLister struct { - indexer cache.Indexer -} - -// NewResourceTopologyLister returns a new ResourceTopologyLister. -func NewResourceTopologyLister(indexer cache.Indexer) ResourceTopologyLister { - return &resourceTopologyLister{indexer: indexer} -} - -// List lists all ResourceTopologies in the indexer. -func (s *resourceTopologyLister) List(selector labels.Selector) (ret []*v1.ResourceTopology, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.ResourceTopology)) - }) - return ret, err -} - -// Get retrieves the ResourceTopology from the index for a given name. -func (s *resourceTopologyLister) Get(name string) (*v1.ResourceTopology, error) { - obj, exists, err := s.indexer.GetByKey(name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1.Resource("resourcetopology"), name) - } - return obj.(*v1.ResourceTopology), nil -} diff --git a/pkg/utils/label.go b/pkg/utils/label.go deleted file mode 100644 index adc74b24..00000000 --- a/pkg/utils/label.go +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved. - * - * 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 utils is label-related function and method. -package utils - -import ( - "context" - "fmt" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "strings" - - xuanwuv1 "huawei-csi-driver/client/apis/xuanwu/v1" - "huawei-csi-driver/csi/app" - "huawei-csi-driver/pkg/constants" - "huawei-csi-driver/utils" - "huawei-csi-driver/utils/log" -) - -// GetTopoName get topo name -func GetTopoName(pvName string) string { - return fmt.Sprintf("topo-%s", strings.ReplaceAll(pvName, "_", "-")) -} - -// CreatePVLabel create label when create pvc -var CreatePVLabel = func(pvName, volumeId string) { - ctx := utils.NewContextWithRequestID() - backendName, _ := utils.SplitVolumeId(volumeId) - backendName = MakeMetaWithNamespace(app.GetGlobalConfig().Namespace, backendName) - - supportLabel, err := IsBackendCapabilitySupport(ctx, backendName, constants.SupportLabel) - if err != nil { - log.AddContext(ctx).Errorf("CreatePVLabel get backend capability support failed,"+ - " backendName: %v, label: %v, err: %v", backendName, supportLabel, err) - } - if supportLabel { - CreateLabel(pvName, volumeId) - } -} - -// CreateLabel used to create ResourceTopology resource -var CreateLabel = func(pvName, volumeId string) { - ctx := utils.NewContextWithRequestID() - var err error - _, volumeName := utils.SplitVolumeId(volumeId) - topologyName := GetTopoName(volumeName) - - topologySpec := xuanwuv1.ResourceTopologySpec{ - Provisioner: constants.DefaultTopoDriverName, - VolumeHandle: volumeId, - Tags: []xuanwuv1.Tag{ - { - ResourceInfo: xuanwuv1.ResourceInfo{ - TypeMeta: metav1.TypeMeta{Kind: constants.PVKind, APIVersion: constants.KubernetesV1}, - Name: pvName, - }, - }, - }, - } - - _, err = app.GetGlobalConfig().BackendUtils.XuanwuV1().ResourceTopologies().Create(ctx, - &xuanwuv1.ResourceTopology{ - TypeMeta: metav1.TypeMeta{Kind: constants.TopologyKind, APIVersion: constants.XuanwuV1}, - ObjectMeta: metav1.ObjectMeta{Name: topologyName}, - Spec: topologySpec, - }, - metav1.CreateOptions{}) - - if err != nil { - log.AddContext(ctx).Errorf("Create topologies for pv: %s failed. error: %v", volumeName, err) - } else { - log.AddContext(ctx).Infof("Create topologies: %s success.", topologyName) - } -} - -// DeletePVLabel delete label when delete pvc -var DeletePVLabel = func(volumeId string) { - ctx := utils.NewContextWithRequestID() - backendName, volName := utils.SplitVolumeId(volumeId) - - backendName = MakeMetaWithNamespace(app.GetGlobalConfig().Namespace, backendName) - supportLabel, err := IsBackendCapabilitySupport(ctx, backendName, constants.SupportLabel) - if err != nil { - log.AddContext(ctx).Errorf("DeletePVLabel get backend capability support failed,"+ - " backendName: %v, label: %v, err: %v", backendName, supportLabel, err) - } - if supportLabel { - DeleteLabel(volName) - } -} - -// DeleteLabel used to delete label resource -var DeleteLabel = func(volName string) { - err := app.GetGlobalConfig().BackendUtils.XuanwuV1().ResourceTopologies().Delete(context.TODO(), - GetTopoName(volName), metav1.DeleteOptions{}) - if err != nil { - log.Errorf("Delete topologies: %s failed. error: %v", GetTopoName(volName), err) - } else { - log.Infof("Delete topologies: %s success.", GetTopoName(volName)) - } -} diff --git a/pkg/utils/label_lock/label_lock.go b/pkg/utils/label_lock/label_lock.go deleted file mode 100644 index e2cd5220..00000000 --- a/pkg/utils/label_lock/label_lock.go +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved. - * - * 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 labellock to provide utils for label lock -package labellock - -import ( - "context" - "time" - - coreV1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/errors" - metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - "huawei-csi-driver/csi/app" - "huawei-csi-driver/pkg/utils" - "huawei-csi-driver/utils/log" -) - -var rtLockWaitTimeInterval = 1 * time.Second -var rtLockWaitTimeOut = 20 * time.Minute - -// RTLockConfigMap lock for rt -const RTLockConfigMap = "rt-lock-cm" - -// InitCmLock if cm not exist then create or refresh -func InitCmLock(ctx context.Context, cmName string) { - if !app.GetGlobalConfig().EnableLabel { - return - } - configmap, err := app.GetGlobalConfig().K8sUtils.GetConfigmap(ctx, cmName, app.GetGlobalConfig().Namespace) - if errors.IsNotFound(err) { - _, err = app.GetGlobalConfig().K8sUtils.CreateConfigmap(ctx, &coreV1.ConfigMap{ - TypeMeta: metaV1.TypeMeta{}, - ObjectMeta: metaV1.ObjectMeta{ - Name: cmName, - Namespace: app.GetGlobalConfig().Namespace, - }, - Immutable: nil, - Data: make(map[string]string), - BinaryData: nil, - }) - if err != nil { - log.AddContext(ctx).Errorf("create cm for %s failed, err: %v", cmName, err) - return - } - log.AddContext(ctx).Infof("create cm for %s success", cmName) - return - } - if len(configmap.Data) != 0 { - _, err = app.GetGlobalConfig().K8sUtils.UpdateConfigmap(ctx, &coreV1.ConfigMap{ - TypeMeta: metaV1.TypeMeta{}, - ObjectMeta: metaV1.ObjectMeta{ - Name: cmName, - Namespace: app.GetGlobalConfig().Namespace, - }, - Immutable: nil, - Data: make(map[string]string), - BinaryData: nil, - }) - if err != nil { - log.AddContext(ctx).Warningf("clear rt lock configmap failed, key:%s err: %v", cmName, err) - return - } - log.AddContext(ctx).Infof("clear rt lock configmap success, key:%s", cmName) - return - } -} - -// AcquireCmLock acquire lock from configmap -func AcquireCmLock(ctx context.Context, cmName, lockKey string) error { - start := time.Now() - for { - if time.Now().After(start.Add(rtLockWaitTimeOut)) { - return utils.Errorf(ctx, "acquire rt lock timeout, cmName: %s key:%s", cmName, lockKey) - } - - configmap, err := app.GetGlobalConfig().K8sUtils.GetConfigmap(ctx, cmName, app.GetGlobalConfig().Namespace) - if err != nil { - log.AddContext(ctx).Warningf("get rt lock configmap failed, key:%s err: %v", lockKey, err) - time.Sleep(rtLockWaitTimeInterval) - continue - } - - if configmap.Data[lockKey] == "true" { - log.AddContext(ctx).Warningf("acquire rt lock failed, lock is acquired, "+ - " key:%s err: %v", lockKey, err) - time.Sleep(rtLockWaitTimeInterval) - continue - } - if configmap.Data == nil { - configmap.Data = make(map[string]string) - } - configmap.Data[lockKey] = "true" - _, err = app.GetGlobalConfig().K8sUtils.UpdateConfigmap(ctx, configmap) - if err != nil { - log.AddContext(ctx).Warningf("update rt lock failed, key:%s err: %v", lockKey, err) - time.Sleep(rtLockWaitTimeInterval) - continue - } - - log.AddContext(ctx).Infof("acquire rt lock success, key:%s", lockKey) - return nil - } -} - -// ReleaseCmlock release lock from configmap -func ReleaseCmlock(ctx context.Context, cmName, lockKey string) error { - start := time.Now() - for { - if time.Now().After(start.Add(rtLockWaitTimeOut)) { - return utils.Errorf(ctx, "release rt lock timeout, cmName: %s key:%s", cmName, lockKey) - } - - configmap, err := app.GetGlobalConfig().K8sUtils.GetConfigmap(ctx, cmName, app.GetGlobalConfig().Namespace) - if err != nil { - log.AddContext(ctx).Warningf("get release rt lock configmap failed, key:%s err: %v", lockKey, err) - time.Sleep(rtLockWaitTimeInterval) - continue - } - - if configmap.Data == nil { - configmap.Data = make(map[string]string) - } - delete(configmap.Data, lockKey) - _, err = app.GetGlobalConfig().K8sUtils.UpdateConfigmap(ctx, configmap) - if err != nil { - log.AddContext(ctx).Warningf("update release rt lock failed, key:%s err: %v", lockKey, err) - time.Sleep(rtLockWaitTimeInterval) - continue - } - - log.AddContext(ctx).Infof("release rt lock success, key:%s", lockKey) - return nil - } -} diff --git a/storage/oceanstor/client/client_container.go b/storage/oceanstor/client/client_container.go deleted file mode 100644 index 71b3f66c..00000000 --- a/storage/oceanstor/client/client_container.go +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved. - * - * 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 client provide client of storage -package client - -import ( - "context" - "strings" - - "huawei-csi-driver/utils/log" -) - -// Container interface of container service -type Container interface { - IsSupportContainer(ctx context.Context) bool -} - -// IsSupportContainer used to determine whether labels are supported. -// If 404 is returned when a PV label is queried, the container service is not supported. -func (cli *BaseClient) IsSupportContainer(ctx context.Context) bool { - _, err := cli.Get(ctx, "/container_pv", nil) - if err != nil && strings.Contains(err.Error(), UrlNotFound) { - log.AddContext(ctx).Debugf("query container pv failed, error: %v", err) - return false - } - return true -} diff --git a/tools/imageUpload/containerd-upload.sh b/tools/imageUpload/containerd-upload.sh deleted file mode 100644 index dba8c58d..00000000 --- a/tools/imageUpload/containerd-upload.sh +++ /dev/null @@ -1,155 +0,0 @@ -#!/bin/bash - -# -# Copyright (c) Huawei Technologies Co., Ltd. 2020-2023. All rights reserved. -# -# 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. -# - -DEBUG="false" -DEFAULT_IMAGE_LOAD_COMMAND="ctr -n k8s.io i import" -WORKER_LIST_FILE="" -IMAGE_FILE="" -USERNAME="" -PASSWORD="" - -# verificationSupported checks whether necessary tools exist. -function verifySupported() { - local hasExpect="$(type "expect" &>/dev/null && echo true || echo false)" - if [ "${hasExpect}" != "true" ]; then - echo "expect is not installed" - exit 1 - fi - - hasScp="$(type "scp" &>/dev/null && echo true || echo false)" - if [ "${hasScp}" != "true" ]; then - echo "scp is not installed" - exit 1 - fi - - hasSshpass="$(type "sshpass" &>/dev/null && echo true || echo false)" - if [ "${hasSshpass}" != "true" ]; then - echo "sshpass is not installed" - exit 1 - fi -} - -function tryLogin() { - ip=$1 - - password=$(echo ${PASSWORD} | sed 's/[^0-9a-zA-Z]/\\&/g') - - /usr/bin/expect </dev/null && echo true || echo false)" - if [ "${hasExpect}" != "true" ]; then - echo "expect is not installed" - exit 1 - fi - - hasScp="$(type "scp" &>/dev/null && echo true || echo false)" - if [ "${hasScp}" != "true" ]; then - echo "scp is not installed" - exit 1 - fi - - hasSshpass="$(type "sshpass" &>/dev/null && echo true || echo false)" - if [ "${hasSshpass}" != "true" ]; then - echo "sshpass is not installed" - exit 1 - fi -} - -function tryLogin() { - ip=$1 - - password=$(echo ${PASSWORD} | sed 's/[^0-9a-zA-Z]/\\&/g') - - /usr/bin/expect <= 0; i-- { - task := p.tasks[i] - - if task.finish && task.revert != nil { - err := task.revert(p.ctx, p.result) - if err != nil { - log.AddContext(p.ctx).Warningf("Revert task %s of taskflow %s error: %v", task.name, p.name, err) - } - } - } - - log.AddContext(p.ctx).Infof("Taskflow %s is reverted", p.name) -} - -// AddTaskWithOutRevert be used when the task does not need revert function -func (p *TaskFlow) AddTaskWithOutRevert(run TaskWithoutRevert) *TaskFlow { - var buildFun = func(ctx context.Context, params map[string]interface{}, - _ map[string]interface{}) (map[string]interface{}, error) { - if err := run(ctx, params); err != nil { - return nil, err - } - return nil, nil - } - p.AddTask("", buildFun, nil) - return p -} - -// RunWithOutRevert run task without revert function and return only error -func (p *TaskFlow) RunWithOutRevert(params map[string]interface{}) error { - if _, err := p.Run(params); err != nil { - return err - } - return nil -} diff --git a/utils/taskflow/taskflow_test.go b/utils/taskflow/taskflow_test.go deleted file mode 100644 index 92323d9f..00000000 --- a/utils/taskflow/taskflow_test.go +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) Huawei Technologies Co., Ltd. 2020-2023. All rights reserved. - * - * 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 taskflow - -import ( - "context" - "errors" - "reflect" - "testing" - - "huawei-csi-driver/utils/log" -) - -var ( - errMsg = "an error occurred while run mock fun" - - mockFun1 = func(ctx context.Context, params map[string]interface{}) error { - params["key_1"] = "value_1" - return nil - } - mockFun2 = func(ctx context.Context, params map[string]interface{}) error { - params["key_2"] = "value_2" - return nil - } - mockFun3 = func(ctx context.Context, params map[string]interface{}) error { - return errors.New(errMsg) - } -) - -const ( - logName = "taskFlowTest.log" -) - -func TestMain(m *testing.M) { - log.MockInitLogging(logName) - defer log.MockStopLogging(logName) - - m.Run() -} - -func TestAllTaskReturnSuccess(t *testing.T) { - testParams := map[string]interface{}{} - err := NewTaskFlow(context.Background(), "test_all_task_return_success"). - AddTaskWithOutRevert(mockFun1). - AddTaskWithOutRevert(mockFun2). - RunWithOutRevert(testParams) - if err != nil { - t.Errorf("an error occurred while run TestTaskWithOutRevert(), err: %v", err) - } - - result := map[string]interface{}{ - "key_1": "value_1", - "key_2": "value_2", - } - if !reflect.DeepEqual(testParams, result) { - t.Error("got an unexpected value while run TestTaskWithOutRevert()") - } -} - -func TestRunTaskFail(t *testing.T) { - testParams := map[string]interface{}{} - err := NewTaskFlow(context.Background(), "test_run_task_fail"). - AddTaskWithOutRevert(mockFun1). - AddTaskWithOutRevert(mockFun2). - AddTaskWithOutRevert(mockFun3). - RunWithOutRevert(testParams) - if err == nil { - t.Error("an error should be returned while run TestRunTaskFail()") - } - - if err.Error() != errMsg { - t.Error("got an unexpected error while run TestRunTaskFail()") - } -} diff --git a/utils/taskflow/transaction.go b/utils/taskflow/transaction.go deleted file mode 100644 index 6dbc25ee..00000000 --- a/utils/taskflow/transaction.go +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved. - * - * 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 taskflow - -type transactionStep struct { - exec func() error - onRollback func() -} - -// Transaction implements a TCC (Try Confirm Cancel) pattern. -type Transaction struct { - stepAt int - steps []transactionStep -} - -// NewTransaction instantiate a new transaction. -func NewTransaction() *Transaction { - return &Transaction{ - steps: []transactionStep{}, - } -} - -// Then adds a step to the steps chain, and returns the same Transaction, -func (t *Transaction) Then(exec func() error, onRollback func()) *Transaction { - t.steps = append(t.steps, transactionStep{ - exec: exec, - onRollback: onRollback, - }) - return t -} - -// Commit executes the Transaction steps and returns error if any one step returns error. -func (t *Transaction) Commit() error { - var err error - - for t.stepAt < len(t.steps) { - if t.stepAt >= 0 && t.stepAt < len(t.steps) && t.steps[t.stepAt].exec != nil { - if err = t.steps[t.stepAt].exec(); err != nil { - break - } - } - - t.stepAt++ - } - - return err -} - -// Rollback executes the Transaction rollbacks. -func (t *Transaction) Rollback() { - for i := t.stepAt - 1; i >= 0; i-- { - if i < len(t.steps) && t.steps[i].onRollback != nil { - t.steps[i].onRollback() - } - } -} diff --git a/utils/taskflow/transaction_test.go b/utils/taskflow/transaction_test.go deleted file mode 100644 index 6521516e..00000000 --- a/utils/taskflow/transaction_test.go +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved. - * - * 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 taskflow_test - -import ( - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - "huawei-csi-driver/utils/taskflow" -) - -func TestTransaction_NoError(t *testing.T) { - // arrange - var i int - transaction := taskflow.NewTransaction(). - Then( - func() error { - i++ - return nil - }, - func() { i-- }, - ). - Then( - func() error { - i += 2 - return nil - }, - func() { i -= 2 }, - ) - - // act - err := transaction.Commit() - - // assert - require.NoError(t, err) - require.Equal(t, 3, i) -} - -func TestTransaction_WithError(t *testing.T) { - // arrange - var i int - transaction := taskflow.NewTransaction(). - Then( - func() error { - return assert.AnError - }, - func() { i-- }, - ) - - // act - err := transaction.Commit() - - // assert - require.ErrorIs(t, err, assert.AnError) -} - -func TestTransaction_Rollback(t *testing.T) { - // arrange - var i int - transaction := taskflow.NewTransaction(). - Then( - func() error { - i++ - return nil - }, - func() { i-- }, - ). - Then( - func() error { - i += 2 - return nil - }, - func() { i -= 2 }, - ). - Then( - func() error { - return assert.AnError - }, - func() { i-- }, - ) - - // act - err := transaction.Commit() - transaction.Rollback() - - // assert - require.ErrorIs(t, err, assert.AnError) - require.Equal(t, 0, i) -}