Skip to content

Commit

Permalink
Merge pull request #134 from gianlucam76/release-0.4
Browse files Browse the repository at this point in the history
Release 0.4
  • Loading branch information
gianlucam76 committed Feb 8, 2023
2 parents d7a892a + 7b3c6b1 commit b652a89
Show file tree
Hide file tree
Showing 25 changed files with 400 additions and 125 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ARCH ?= amd64
OS ?= $(shell uname -s | tr A-Z a-z)
K8S_LATEST_VER ?= $(shell curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)
export CONTROLLER_IMG ?= $(REGISTRY)/$(IMAGE_NAME)
TAG ?= v0.4.0
TAG ?= v0.4.1

# Get cluster-api version and build ldflags
clusterapi := $(shell go list -m sigs.k8s.io/cluster-api)
Expand Down Expand Up @@ -244,16 +244,16 @@ deploy-projectsveltos: $(KUSTOMIZE)
$(MAKE) load-image

@echo 'Install libsveltos CRDs'
$(KUBECTL) apply -f https://raw.githubusercontent.com/projectsveltos/libsveltos/v0.4.0/config/crd/bases/lib.projectsveltos.io_debuggingconfigurations.yaml
$(KUBECTL) apply -f https://raw.githubusercontent.com/projectsveltos/libsveltos/v0.4.0/config/crd/bases/lib.projectsveltos.io_sveltosclusters.yaml
$(KUBECTL) apply -f https://raw.githubusercontent.com/projectsveltos/libsveltos/v0.4.1/config/crd/bases/lib.projectsveltos.io_debuggingconfigurations.yaml
$(KUBECTL) apply -f https://raw.githubusercontent.com/projectsveltos/libsveltos/v0.4.1/config/crd/bases/lib.projectsveltos.io_sveltosclusters.yaml

# Install projectsveltos controller-manager components
@echo 'Install projectsveltos controller-manager components'
cd config/manager && ../../$(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | $(ENVSUBST) | $(KUBECTL) apply -f-

# Install sveltoscluster-manager
$(KUBECTL) apply -f https://raw.githubusercontent.com/projectsveltos/sveltoscluster-manager/v0.4.0/manifest/manifest.yaml
$(KUBECTL) apply -f https://raw.githubusercontent.com/projectsveltos/sveltoscluster-manager/v0.4.1/manifest/manifest.yaml

@echo "Waiting for projectsveltos controller-manager to be available..."
$(KUBECTL) wait --for=condition=Available deployment/fm-controller-manager -n projectsveltos --timeout=$(TIMEOUT)
Expand All @@ -270,7 +270,7 @@ set-manifest-pull-policy:

drift-detection-manager:
@echo "Downloading drift detection manager yaml"
curl -L https://raw.githubusercontent.com/projectsveltos/drift-detection-manager/v0.4.0/manifest/manifest.yaml -o ./pkg/drift-detection/drift-detection-manager.yaml
curl -L https://raw.githubusercontent.com/projectsveltos/drift-detection-manager/v0.4.1/manifest/manifest.yaml -o ./pkg/drift-detection/drift-detection-manager.yaml
cd pkg/drift-detection; go generate

.PHONY: build
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ To see the full demo, have a look at this [youtube video](https://youtu.be/Ai5Mr
If you have questions, noticed any bug or want to get the latest project news, you can connect with us in the following ways:
1. Open a bug/feature enhancement on github;
2. Chat with us on the Slack in the [#projectsveltos](https://join.slack.com/t/projectsveltos/shared_invite/zt-1hraownbr-W8NTs6LTimxLPB8Erj8Q6Q) channel;
3. Submit a pull request.
3. Submit a pull request;
4. [Contact Us](mailto:support@projectsveltos.io)

## License

Expand Down
3 changes: 1 addition & 2 deletions api/v1alpha1/clusterprofile_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,10 @@ type HelmChart struct {
// Values holds the values for this Helm release.
// Go templating with the values from the referenced CAPI Cluster.
// Currently following can be referenced:
// - Cluster => CAPI Cluster for instance {{ index .Cluster.Spec.ClusterNetwork.Pods.CIDRBlocks 0 }}
// - Cluster => CAPI Cluster for instance
// - KubeadmControlPlane => the CAPI Cluster controlPlaneRef
// - InfrastructureProvider => the CAPI cluster infrastructure provider
// - SecretRef => store any confindetial information in a Secret, set SecretRef then reference it
// for instance password: "{{ printf "%s" .SecretRef.Data.password | b64dec }}"
// +optional
Values string `json:"values,omitempty"`

Expand Down
5 changes: 3 additions & 2 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions config/crd/bases/config.projectsveltos.io_clusterprofiles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,10 @@ spec:
description: 'Values holds the values for this Helm release.
Go templating with the values from the referenced CAPI Cluster.
Currently following can be referenced: - Cluster => CAPI Cluster
for instance {{ index .Cluster.Spec.ClusterNetwork.Pods.CIDRBlocks
0 }} - KubeadmControlPlane => the CAPI Cluster controlPlaneRef
for instance - KubeadmControlPlane => the CAPI Cluster controlPlaneRef
- InfrastructureProvider => the CAPI cluster infrastructure
provider - SecretRef => store any confindetial information
in a Secret, set SecretRef then reference it for instance
password: "{{ printf "%s" .SecretRef.Data.password | b64dec
}}"'
in a Secret, set SecretRef then reference it'
type: string
required:
- chartName
Expand Down Expand Up @@ -154,8 +151,9 @@ spec:
minLength: 1
type: string
namespace:
description: Namespace of the referenced resource.
minLength: 1
description: Namespace of the referenced resource. Namespace
can be left empty. In such a case, namespace will be implicit
set to cluster's namespace.
type: string
required:
- kind
Expand Down
17 changes: 8 additions & 9 deletions config/crd/bases/config.projectsveltos.io_clustersummaries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,11 @@ spec:
description: 'Values holds the values for this Helm release.
Go templating with the values from the referenced CAPI
Cluster. Currently following can be referenced: - Cluster
=> CAPI Cluster for instance {{ index .Cluster.Spec.ClusterNetwork.Pods.CIDRBlocks
0 }} - KubeadmControlPlane => the CAPI Cluster controlPlaneRef
- InfrastructureProvider => the CAPI cluster infrastructure
provider - SecretRef => store any confindetial information
in a Secret, set SecretRef then reference it for instance
password: "{{ printf "%s" .SecretRef.Data.password | b64dec
}}"'
=> CAPI Cluster for instance - KubeadmControlPlane =>
the CAPI Cluster controlPlaneRef - InfrastructureProvider
=> the CAPI cluster infrastructure provider - SecretRef
=> store any confindetial information in a Secret, set
SecretRef then reference it'
type: string
required:
- chartName
Expand Down Expand Up @@ -168,8 +166,9 @@ spec:
minLength: 1
type: string
namespace:
description: Namespace of the referenced resource.
minLength: 1
description: Namespace of the referenced resource. Namespace
can be left empty. In such a case, namespace will be implicit
set to cluster's namespace.
type: string
required:
- kind
Expand Down
2 changes: 1 addition & 1 deletion config/default/manager_image_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ spec:
spec:
containers:
# Change the value of image field below to your controller image URL
- image: gianlucam76/sveltos-manager-amd64:v0.4.0
- image: gianlucam76/sveltos-manager-amd64:v0.4.1
name: manager
2 changes: 1 addition & 1 deletion config/rbac/auth_proxy_service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Service
metadata:
labels:
control-plane: controller-manager
name: controller-manager-metrics-service
name: manager-metrics-service
namespace: projectsveltos
spec:
ports:
Expand Down
5 changes: 4 additions & 1 deletion controllers/clustersummary_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,10 +648,13 @@ func (r *ClusterSummaryReconciler) getCurrentReferences(clusterSummaryScope *sco
for i := range clusterSummaryScope.ClusterSummary.Spec.ClusterProfileSpec.PolicyRefs {
referencedNamespace := clusterSummaryScope.ClusterSummary.Spec.ClusterProfileSpec.PolicyRefs[i].Namespace
referencedName := clusterSummaryScope.ClusterSummary.Spec.ClusterProfileSpec.PolicyRefs[i].Name

namespace := getReferenceResourceNamespace(clusterSummaryScope.Namespace(), referencedNamespace)

currentReferences.Insert(&corev1.ObjectReference{
APIVersion: corev1.SchemeGroupVersion.String(), // the only resources that can be referenced are Secret and ConfigMap
Kind: clusterSummaryScope.ClusterSummary.Spec.ClusterProfileSpec.PolicyRefs[i].Kind,
Namespace: referencedNamespace,
Namespace: namespace,
Name: referencedName,
})
}
Expand Down
35 changes: 35 additions & 0 deletions controllers/clustersummary_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,41 @@ var _ = Describe("ClustersummaryController", func() {
// Because CAPI cluster does not exist and ClusterSummary is marked for deletion, finalizer can be removed
Expect(controllers.CanRemoveFinalizer(reconciler, context.TODO(), clusterSummaryScope, klogr.New())).To(BeTrue())
})

It("getCurrentReferences collects all ClusterSummary referenced objects", func() {
referencedResourceNamespace := randomString()
clusterSummary.Spec.ClusterProfileSpec.PolicyRefs = []libsveltosv1alpha1.PolicyRef{
{
Namespace: referencedResourceNamespace,
Name: randomString(),
Kind: string(libsveltosv1alpha1.ConfigMapReferencedResourceKind),
},
}

c := fake.NewClientBuilder().WithScheme(scheme).Build()

clusterSummaryScope := getClusterSummaryScope(c, klogr.New(), clusterProfile, clusterSummary)
reconciler := getClusterSummaryReconciler(nil, nil)
set := controllers.GetCurrentReferences(reconciler, clusterSummaryScope)
Expect(set.Len()).To(Equal(1))
items := set.Items()
Expect(items[0].Namespace).To(Equal(referencedResourceNamespace))
})

It("getCurrentReferences collects all ClusterSummary referenced objects using cluster namespace when not set", func() {
clusterSummary.Spec.ClusterProfileSpec.PolicyRefs = []libsveltosv1alpha1.PolicyRef{
{Namespace: "", Name: randomString(), Kind: string(libsveltosv1alpha1.ConfigMapReferencedResourceKind)},
}

c := fake.NewClientBuilder().WithScheme(scheme).Build()

clusterSummaryScope := getClusterSummaryScope(c, klogr.New(), clusterProfile, clusterSummary)
reconciler := getClusterSummaryReconciler(nil, nil)
set := controllers.GetCurrentReferences(reconciler, clusterSummaryScope)
Expect(set.Len()).To(Equal(1))
items := set.Items()
Expect(items[0].Namespace).To(Equal(clusterSummary.Namespace))
})
})

var _ = Describe("ClusterSummaryReconciler: requeue methods", func() {
Expand Down
10 changes: 4 additions & 6 deletions controllers/clustersummary_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ func (r *ClusterSummaryReconciler) updateDeployedGroupVersionKind(ctx context.Co

logger.V(logs.LogDebug).Info("update status with deployed GroupVersionKinds")
// Collect all referenced configMaps/secrets.
referencedObjects, err := collectReferencedObjects(ctx, r.Client, references, logger)
referencedObjects, err := collectReferencedObjects(ctx, r.Client, clusterSummaryScope.Namespace(),
references, logger)
if err != nil {
logger.V(logs.LogDebug).Info(fmt.Sprintf("failed to collect referenced configMaps/secrets. Err: %v", err))
return err
Expand All @@ -409,12 +410,9 @@ func (r *ClusterSummaryReconciler) updateDeployedGroupVersionKind(ctx context.Co
data = cm.Data
} else {
secret := referencedObjects[i].(*corev1.Secret)
data = make(map[string]string)
data = map[string]string{}
for key, value := range secret.Data {
data[key], err = decode(value)
if err != nil {
return err
}
data[key] = string(value)
}
}
policies, err := collectContent(ctx, clusterSummaryScope.ClusterSummary, data, logger)
Expand Down
14 changes: 0 additions & 14 deletions controllers/clustersummary_deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,20 +573,6 @@ var _ = Describe("ClustersummaryDeployer", func() {
Expect(cs.Status.FeatureSummaries[0].FeatureID).To(Equal(configv1alpha1.FeatureResources))
Expect(cs.Status.FeatureSummaries[0].DeployedGroupVersionKind).To(ContainElement("ClusterRole.v1.rbac.authorization.k8s.io"))
})

It("getCurrentReferences collects all ClusterSummary referenced objects", func() {
clusterSummary.Spec.ClusterProfileSpec.PolicyRefs = []libsveltosv1alpha1.PolicyRef{
{Namespace: randomString(), Name: randomString(), Kind: string(libsveltosv1alpha1.ConfigMapReferencedResourceKind)},
}

c := fake.NewClientBuilder().WithScheme(scheme).Build()

clusterSummaryScope := getClusterSummaryScope(c, logger, clusterProfile, clusterSummary)
reconciler := getClusterSummaryReconciler(nil, nil)
set := controllers.GetCurrentReferences(reconciler, clusterSummaryScope)
expectedLength := len(clusterSummary.Spec.ClusterProfileSpec.PolicyRefs)
Expect(set.Len()).To(Equal(expectedLength))
})
})

var _ = Describe("Convert result", func() {
Expand Down
32 changes: 17 additions & 15 deletions controllers/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,23 @@ var (
GenericDeploy = genericDeploy
GenericUndeploy = genericUndeploy

GetClusterSummary = getClusterSummary
AddLabel = addLabel
CreateNamespace = createNamespace
GetEntryKey = getEntryKey
DeployContentOfConfigMap = deployContentOfConfigMap
DeployContentOfSecret = deployContentOfSecret
DeployContent = deployContent
GetClusterSummaryAdmin = getClusterSummaryAdmin
AddAnnotation = addAnnotation
ComputePolicyHash = computePolicyHash
GetPolicyInfo = getPolicyInfo
UndeployStaleResources = undeployStaleResources
GetDeployedGroupVersionKinds = getDeployedGroupVersionKinds
CanDelete = canDelete
HandleResourceDelete = handleResourceDelete
GetClusterSummary = getClusterSummary
AddLabel = addLabel
CreateNamespace = createNamespace
GetEntryKey = getEntryKey
DeployContentOfConfigMap = deployContentOfConfigMap
DeployContentOfSecret = deployContentOfSecret
DeployContent = deployContent
GetClusterSummaryAdmin = getClusterSummaryAdmin
AddAnnotation = addAnnotation
ComputePolicyHash = computePolicyHash
GetPolicyInfo = getPolicyInfo
UndeployStaleResources = undeployStaleResources
GetDeployedGroupVersionKinds = getDeployedGroupVersionKinds
CanDelete = canDelete
HandleResourceDelete = handleResourceDelete
GetSecret = getSecret
GetReferenceResourceNamespace = getReferenceResourceNamespace

ResourcesHash = resourcesHash
GetResourceRefs = getResourceRefs
Expand Down
5 changes: 3 additions & 2 deletions controllers/handlers_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,17 @@ func resourcesHash(ctx context.Context, c client.Client, clusterSummaryScope *sc
clusterSummary := clusterSummaryScope.ClusterSummary
for i := range clusterSummary.Spec.ClusterProfileSpec.PolicyRefs {
reference := &clusterSummary.Spec.ClusterProfileSpec.PolicyRefs[i]
namespace := getReferenceResourceNamespace(clusterSummaryScope.Namespace(), reference.Namespace)
var err error
if reference.Kind == string(libsveltosv1alpha1.ConfigMapReferencedResourceKind) {
configmap := &corev1.ConfigMap{}
err = c.Get(ctx, types.NamespacedName{Namespace: reference.Namespace, Name: reference.Name}, configmap)
err = c.Get(ctx, types.NamespacedName{Namespace: namespace, Name: reference.Name}, configmap)
if err == nil {
config += render.AsCode(configmap.Data)
}
} else {
secret := &corev1.Secret{}
err = c.Get(ctx, types.NamespacedName{Namespace: reference.Namespace, Name: reference.Name}, secret)
err = c.Get(ctx, types.NamespacedName{Namespace: namespace, Name: reference.Name}, secret)
if err == nil {
config += render.AsCode(secret.Data)
}
Expand Down

0 comments on commit b652a89

Please sign in to comment.