|
| 1 | +/* |
| 2 | +Copyright 2024 The Kubernetes 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 config |
| 18 | + |
| 19 | +import ( |
| 20 | + "bytes" |
| 21 | + "io" |
| 22 | + "os" |
| 23 | + |
| 24 | + "sigs.k8s.io/container-object-storage-interface-api/apis/objectstorage/v1alpha1" |
| 25 | + "sigs.k8s.io/yaml" |
| 26 | +) |
| 27 | + |
| 28 | +// Load reads the YAML configuration from the provided file path and unmarshals it into a Config struct. |
| 29 | +// It returns a pointer to the Config struct and any error encountered during the process. |
| 30 | +func Load(path string) (*Config, error) { |
| 31 | + f, err := os.Open(path) |
| 32 | + if err != nil { |
| 33 | + return nil, err |
| 34 | + } |
| 35 | + defer f.Close() |
| 36 | + |
| 37 | + buf := new(bytes.Buffer) |
| 38 | + |
| 39 | + _, err = io.Copy(buf, f) |
| 40 | + if err != nil { |
| 41 | + return nil, err |
| 42 | + } |
| 43 | + |
| 44 | + cfg := &Config{} |
| 45 | + |
| 46 | + err = yaml.Unmarshal(buf.Bytes(), cfg) |
| 47 | + if err != nil { |
| 48 | + return nil, err |
| 49 | + } |
| 50 | + |
| 51 | + return cfg, nil |
| 52 | +} |
| 53 | + |
| 54 | +// Config represents the configuration for generating tests. |
| 55 | +// It includes various fields like driver details, deletion policies, authentication types, protocols, |
| 56 | +// and parameters for BucketClass and BucketAccessClass. |
| 57 | +type Config struct { |
| 58 | + // Templates contains paths to the YAML templates for various resources. |
| 59 | + Templates Templates `json:"templates"` |
| 60 | + |
| 61 | + // Driver is the name of the driver used in the test configuration. |
| 62 | + Driver string `json:"driver"` |
| 63 | + |
| 64 | + // DeletionPolicy is a list of deletion policies to be applied in the tests. |
| 65 | + DeletionPolicy []v1alpha1.DeletionPolicy `json:"deletionPolicy"` |
| 66 | + |
| 67 | + // AuthenticationType is a list of authentication types to be used in the tests. |
| 68 | + AuthenticationType []v1alpha1.AuthenticationType `json:"authenticationType"` |
| 69 | + |
| 70 | + // Protocol is a list of protocols to be used in the tests. |
| 71 | + Protocol []v1alpha1.Protocol `json:"protocol"` |
| 72 | + |
| 73 | + // BucketClassParams is a list of parameters for configuring BucketClass resources. |
| 74 | + BucketClassParams []map[string]string `json:"bucketClassParams"` |
| 75 | + |
| 76 | + // BucketAccessClassParams is a list of parameters for configuring BucketAccessClass resources. |
| 77 | + BucketAccessClassParams []map[string]string `json:"bucketAccessClassParams"` |
| 78 | +} |
| 79 | + |
| 80 | +// Templates represents the file paths to the templates used for generating various Kubernetes resources. |
| 81 | +// These templates are referenced in the test configurations. |
| 82 | +type Templates struct { |
| 83 | + // ChainsawTest is the path to the Chainsaw test YAML template. |
| 84 | + ChainsawTest string `json:"chainsaw-test.yaml"` |
| 85 | + |
| 86 | + // BucketAccess is the path to the BucketAccess YAML template. |
| 87 | + BucketAccess string `json:"BucketAccess.yaml"` |
| 88 | + |
| 89 | + // BucketAccessClass is the path to the BucketAccessClass YAML template. |
| 90 | + BucketAccessClass string `json:"BucketAccessClass.yaml"` |
| 91 | + |
| 92 | + // BucketClaim is the path to the BucketClaim YAML template. |
| 93 | + BucketClaim string `json:"BucketClaim.yaml"` |
| 94 | + |
| 95 | + // BucketClass is the path to the BucketClass YAML template. |
| 96 | + BucketClass string `json:"BucketClass.yaml"` |
| 97 | +} |
0 commit comments