volume.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. Copyright 2023 The Rook Authors. All rights reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package v1
  14. import (
  15. "reflect"
  16. corev1 "k8s.io/api/core/v1"
  17. )
  18. func (src *ConfigFileVolumeSource) ToKubernetesVolumeSource() *corev1.VolumeSource {
  19. if src == nil {
  20. return nil
  21. }
  22. dst := &corev1.VolumeSource{}
  23. vDst := reflect.ValueOf(dst).Elem()
  24. tSrc := reflect.TypeOf(*src)
  25. vSrc := reflect.ValueOf(*src)
  26. for _, srcField := range reflect.VisibleFields(tSrc) {
  27. if !srcField.IsExported() {
  28. continue
  29. }
  30. srcVal := vSrc.FieldByName(srcField.Name)
  31. if srcVal.IsNil() {
  32. continue // don't do anything if the src field is a nil ptr
  33. }
  34. dstVal := vDst.FieldByName(srcField.Name)
  35. dstVal.Set(srcVal)
  36. }
  37. return dst
  38. }