github.com/openebs/node-disk-manager@v1.9.1-0.20230225014141-4531f06ffa1e/db/kubernetes/convert.go (about)

     1  /*
     2  Copyright 2019 The OpenEBS Authors
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package kubernetes
    18  
    19  import (
    20  	api "github.com/openebs/node-disk-manager/api/v1alpha1"
    21  	"github.com/openebs/node-disk-manager/blockdevice"
    22  )
    23  
    24  func convertBlockDeviceAPIListToBlockDeviceList(in *api.BlockDeviceList, out *[]blockdevice.BlockDevice) error {
    25  	var err error
    26  	var bd blockdevice.BlockDevice
    27  	for i := range in.Items {
    28  		err = convertBlockDeviceAPIToBlockDevice(&in.Items[i], &bd)
    29  		if err != nil {
    30  			return err
    31  		}
    32  		*out = append(*out, bd)
    33  	}
    34  	return nil
    35  }
    36  
    37  func convertBlockDeviceAPIToBlockDevice(in *api.BlockDevice, out *blockdevice.BlockDevice) error {
    38  	out.UUID = in.Name
    39  
    40  	//labels
    41  	out.NodeAttributes = make(blockdevice.NodeAttribute)
    42  	out.NodeAttributes[blockdevice.HostName] = in.Labels[KubernetesHostNameLabel]
    43  	out.NodeAttributes[blockdevice.NodeName] = in.Spec.NodeAttributes.NodeName
    44  
    45  	//spec
    46  	out.DevPath = in.Spec.Path
    47  	out.FSInfo.FileSystem = in.Spec.FileSystem.Type
    48  
    49  	// currently only the first mount point is filled in. When API is changed, multiple mount points
    50  	// will be added.
    51  	out.FSInfo.MountPoint = append(out.FSInfo.MountPoint, in.Spec.FileSystem.Mountpoint)
    52  	out.DeviceAttributes.DeviceType = in.Spec.Details.DeviceType
    53  
    54  	//status
    55  	out.Status.State = string(in.Status.State)
    56  	out.Status.ClaimPhase = string(in.Status.ClaimState)
    57  
    58  	return nil
    59  }