Skip to content

Commit aaac3f9

Browse files
author
mgianluc
committed
Introduce v1beta1
Conversion is introduced for ClusterProfile/Profile
1 parent beb8738 commit aaac3f9

File tree

151 files changed

+15553
-4489
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+15553
-4489
lines changed

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ create-cluster: $(KIND) $(CLUSTERCTL) $(KUBECTL) $(ENVSUBST) ## Create a new kin
239239
$(KUBECTL) create configmap kustomize --from-file=test/kustomize.tar.gz
240240

241241
@echo apply reloader CRD to managed cluster
242-
$(KUBECTL) --kubeconfig=./test/fv/workload_kubeconfig apply -f https://raw.githubusercontent.com/projectsveltos/libsveltos/$(TAG)/config/crd/bases/lib.projectsveltos.io_reloaders.yaml
242+
$(KUBECTL) --kubeconfig=./test/fv/workload_kubeconfig apply -f https://raw.githubusercontent.com/projectsveltos/libsveltos/$(TAG)/manifests/apiextensions.k8s.io_v1_customresourcedefinition_reloaders.lib.projectsveltos.io.yaml
243243

244244
.PHONY: delete-cluster
245245
delete-cluster: $(KIND) ## Deletes the kind cluster $(CONTROL_CLUSTER_NAME)
@@ -302,10 +302,10 @@ deploy-projectsveltos: $(KUSTOMIZE)
302302
$(MAKE) load-image
303303

304304
@echo 'Install libsveltos CRDs'
305-
$(KUBECTL) apply -f https://raw.githubusercontent.com/projectsveltos/libsveltos/$(TAG)/config/crd/bases/lib.projectsveltos.io_debuggingconfigurations.yaml
306-
$(KUBECTL) apply -f https://raw.githubusercontent.com/projectsveltos/libsveltos/$(TAG)/config/crd/bases/lib.projectsveltos.io_sveltosclusters.yaml
307-
$(KUBECTL) apply -f https://raw.githubusercontent.com/projectsveltos/libsveltos/$(TAG)/config/crd/bases/lib.projectsveltos.io_clustersets.yaml
308-
$(KUBECTL) apply -f https://raw.githubusercontent.com/projectsveltos/libsveltos/$(TAG)/config/crd/bases/lib.projectsveltos.io_sets.yaml
305+
$(KUBECTL) apply -f https://raw.githubusercontent.com/projectsveltos/libsveltos/$(TAG)/manifests/apiextensions.k8s.io_v1_customresourcedefinition_debuggingconfigurations.lib.projectsveltos.io.yaml
306+
$(KUBECTL) apply -f https://raw.githubusercontent.com/projectsveltos/libsveltos/$(TAG)/manifests/apiextensions.k8s.io_v1_customresourcedefinition_sveltosclusters.lib.projectsveltos.io.yaml
307+
$(KUBECTL) apply -f https://raw.githubusercontent.com/projectsveltos/libsveltos/$(TAG)/manifests/apiextensions.k8s.io_v1_customresourcedefinition_clustersets.lib.projectsveltos.io.yaml
308+
$(KUBECTL) apply -f https://raw.githubusercontent.com/projectsveltos/libsveltos/$(TAG)/manifests/apiextensions.k8s.io_v1_customresourcedefinition_sets.lib.projectsveltos.io.yaml
309309

310310
# Install projectsveltos addon-controller components
311311
@echo 'Install projectsveltos addon-controller components'

PROJECT

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,44 @@ resources:
5959
group: lib
6060
kind: ClusterSet
6161
version: v1alpha1
62+
- api:
63+
crdVersion: v1
64+
namespaced: true
65+
domain: projectsveltos.io
66+
group: config
67+
kind: ClusterProfile
68+
path: github.com/projectsveltos/addon-controller/api/v1beta1
69+
version: v1beta1
70+
- api:
71+
crdVersion: v1
72+
namespaced: true
73+
domain: projectsveltos.io
74+
group: config
75+
kind: ClusterReport
76+
path: github.com/projectsveltos/addon-controller/api/v1beta1
77+
version: v1beta1
78+
- api:
79+
crdVersion: v1
80+
namespaced: true
81+
domain: projectsveltos.io
82+
group: config
83+
kind: ClusterSummary
84+
path: github.com/projectsveltos/addon-controller/api/v1beta1
85+
version: v1beta1
86+
- api:
87+
crdVersion: v1
88+
namespaced: true
89+
domain: projectsveltos.io
90+
group: config
91+
kind: ClusterConfiguration
92+
path: github.com/projectsveltos/addon-controller/api/v1beta1
93+
version: v1beta1
94+
- api:
95+
crdVersion: v1
96+
namespaced: true
97+
domain: projectsveltos.io
98+
group: config
99+
kind: Profile
100+
path: github.com/projectsveltos/addon-controller/api/v1beta1
101+
version: v1beta1
62102
version: "3"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Here is an example of how to require that any CAPI Cluster with label *env: prod
4949
3. kubernetes resource(s) contained in the referenced ConfigMap: *default/contour*.
5050

5151
```yaml
52-
apiVersion: config.projectsveltos.io/v1alpha1
52+
apiVersion: config.projectsveltos.io/v1beta1
5353
kind: ClusterProfile
5454
metadata:
5555
name: deploy-kyverno
@@ -83,7 +83,7 @@ As soon as a cluster is a match for above ClusterProfile instance, all reference
8383
Here is an example using Kustomize:
8484
8585
```yaml
86-
apiVersion: config.projectsveltos.io/v1alpha1
86+
apiVersion: config.projectsveltos.io/v1beta1
8787
kind: ClusterProfile
8888
metadata:
8989
name: flux-system
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
Copyright 2024. projectsveltos.io. All rights reserved.
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 v1alpha1
18+
19+
import (
20+
"encoding/json"
21+
"fmt"
22+
23+
"sigs.k8s.io/controller-runtime/pkg/conversion"
24+
logf "sigs.k8s.io/controller-runtime/pkg/log"
25+
26+
configv1beta1 "github.com/projectsveltos/addon-controller/api/v1beta1"
27+
libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1"
28+
logs "github.com/projectsveltos/libsveltos/lib/logsettings"
29+
)
30+
31+
var (
32+
configlog = logf.Log.WithName("conversion")
33+
)
34+
35+
// ConvertTo converts v1alpha1 to the Hub version (v1beta1).
36+
func (src *ClusterProfile) ConvertTo(dstRaw conversion.Hub) error {
37+
dst := dstRaw.(*configv1beta1.ClusterProfile)
38+
39+
configlog.V(logs.LogInfo).Info("convert ClusterProfile from v1alpha1 to v1beta1")
40+
41+
dst.ObjectMeta = src.ObjectMeta
42+
43+
var err error
44+
dst.Spec, err = convertV1Alpha1SpecToV1Beta1(&src.Spec)
45+
if err != nil {
46+
configlog.V(logs.LogInfo).Info(fmt.Sprintf("failed to convert Spec: %v", err))
47+
return err
48+
}
49+
50+
jsonData, err := json.Marshal(src.Status) // Marshal the Status field
51+
if err != nil {
52+
return fmt.Errorf("error marshaling Status: %w", err)
53+
}
54+
55+
err = json.Unmarshal(jsonData, &dst.Status) // Unmarshal to v1beta1 type
56+
if err != nil {
57+
return fmt.Errorf("error unmarshaling JSON: %w", err)
58+
}
59+
60+
return nil
61+
}
62+
63+
// ConvertFrom converts from the Hub version (v1beta1) to this v1alpha1.
64+
func (dst *ClusterProfile) ConvertFrom(srcRaw conversion.Hub) error {
65+
src := srcRaw.(*configv1beta1.ClusterProfile)
66+
67+
configlog.V(logs.LogInfo).Info("convert ClusterProfile from v1beta1 to v1alpha1")
68+
69+
dst.ObjectMeta = src.ObjectMeta
70+
71+
var err error
72+
dst.Spec, err = convertV1Beta1SpecToV1Alpha1(&src.Spec)
73+
if err != nil {
74+
configlog.V(logs.LogInfo).Info(fmt.Sprintf("failed to convert Spec: %v", err))
75+
return err
76+
}
77+
78+
labelSelector, err := src.Spec.ClusterSelector.ToSelector()
79+
if err != nil {
80+
return fmt.Errorf("failed to convert : %w", err)
81+
}
82+
83+
dst.Spec.ClusterSelector = libsveltosv1alpha1.Selector(labelSelector.String())
84+
85+
jsonData, err := json.Marshal(src.Status) // Marshal the Status field
86+
if err != nil {
87+
return fmt.Errorf("error marshaling Spec: %w", err)
88+
}
89+
90+
err = json.Unmarshal(jsonData, &dst.Status) // Unmarshal to v1beta1 type
91+
if err != nil {
92+
return fmt.Errorf("error unmarshaling JSON: %w", err)
93+
}
94+
95+
return nil
96+
}

api/v1alpha1/clustersummary_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"k8s.io/apimachinery/pkg/types"
2828
"sigs.k8s.io/controller-runtime/pkg/client"
2929

30-
libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1"
30+
libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1beta1"
3131
)
3232

3333
const (

0 commit comments

Comments
 (0)