|
4 | 4 | "context" |
5 | 5 | "fmt" |
6 | 6 | "io" |
7 | | - "os" |
8 | 7 |
|
9 | 8 | fluxk "github.com/fluxcd/kustomize-controller/api/v1" |
10 | 9 | "github.com/openmcp-project/controller-utils/pkg/clusters" |
@@ -100,77 +99,3 @@ func (k *FluxKustomization) ApplyToCluster(ctx context.Context, cluster *cluster |
100 | 99 |
|
101 | 100 | return util.ApplyManifests(ctx, cluster, kMarshaled) |
102 | 101 | } |
103 | | - |
104 | | -/////////////////========================================================================================== |
105 | | - |
106 | | -func ParseKustomization(path string) (*ktypes.Kustomization, error) { |
107 | | - kustomizationRaw, err := os.ReadFile(path) |
108 | | - if err != nil { |
109 | | - return nil, fmt.Errorf("failed to read kustomization file: %w", err) |
110 | | - } |
111 | | - |
112 | | - kustomization := &ktypes.Kustomization{} |
113 | | - err = yaml.Unmarshal(kustomizationRaw, kustomization) |
114 | | - if err != nil { |
115 | | - return nil, fmt.Errorf("failed to unmarshal kustomization file: %w", err) |
116 | | - } |
117 | | - |
118 | | - return kustomization, nil |
119 | | -} |
120 | | - |
121 | | -func ParseKustomizationFromFile(file io.Reader) (*ktypes.Kustomization, error) { |
122 | | - kustomizationRaw, err := io.ReadAll(file) |
123 | | - if err != nil { |
124 | | - return nil, fmt.Errorf("failed to read kustomization file: %w", err) |
125 | | - } |
126 | | - |
127 | | - kustomization := &ktypes.Kustomization{} |
128 | | - err = yaml.Unmarshal(kustomizationRaw, kustomization) |
129 | | - if err != nil { |
130 | | - return nil, fmt.Errorf("failed to unmarshal kustomization file: %w", err) |
131 | | - } |
132 | | - |
133 | | - return kustomization, nil |
134 | | -} |
135 | | - |
136 | | -func AddResourceToKustomization(kustomization *ktypes.Kustomization, resource string) { |
137 | | - if len(kustomization.Resources) == 0 { |
138 | | - kustomization.Resources = make([]string, 0, 1) |
139 | | - } |
140 | | - kustomization.Resources = append(kustomization.Resources, resource) |
141 | | -} |
142 | | - |
143 | | -func AddResourcesToKustomization(kustomization *ktypes.Kustomization, resources []string) { |
144 | | - if len(kustomization.Resources) == 0 { |
145 | | - kustomization.Resources = make([]string, 0, len(resources)) |
146 | | - } |
147 | | - kustomization.Resources = append(kustomization.Resources, resources...) |
148 | | -} |
149 | | - |
150 | | -func WriteKustomization(path string, kustomization *ktypes.Kustomization) error { |
151 | | - kustomizationRaw, err := yaml.Marshal(kustomization) |
152 | | - if err != nil { |
153 | | - return fmt.Errorf("failed to marshal kustomization file: %w", err) |
154 | | - } |
155 | | - |
156 | | - err = os.WriteFile(path, kustomizationRaw, 0644) |
157 | | - if err != nil { |
158 | | - return fmt.Errorf("failed to write kustomization file: %w", err) |
159 | | - } |
160 | | - |
161 | | - return nil |
162 | | -} |
163 | | - |
164 | | -func WriteKustomizationToFile(file io.Writer, kustomization *ktypes.Kustomization) error { |
165 | | - kustomizationRaw, err := yaml.Marshal(kustomization) |
166 | | - if err != nil { |
167 | | - return fmt.Errorf("failed to marshal kustomization file: %w", err) |
168 | | - } |
169 | | - |
170 | | - _, err = file.Write(kustomizationRaw) |
171 | | - if err != nil { |
172 | | - return fmt.Errorf("failed to write kustomization file: %w", err) |
173 | | - } |
174 | | - |
175 | | - return nil |
176 | | -} |
0 commit comments