Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/fv/auto_deploy_dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ metadata:
The ':latest' tag is mutable and can lead to unexpected errors if the
image changes. A best practice is to use an immutable tag that maps to
a specific version of an application Pod. This policy validates that the image
specifies a tag and that it is not called latest.
specifies a tag and that it is not called latest.
spec:
validationFailureAction: Audit
background: true
Expand Down Expand Up @@ -98,7 +98,7 @@ var _ = Describe("Feature", func() {
It("With AutoDeployDependencies set Sveltos resolves all prerequesities", Label("NEW-FV"), func() {
Byf("Create a ClusterProfile matching NO Cluster") // clusterSelector is not set
helmClusterProfile := getClusterProfile(namePrefix, map[string]string{})
Byf("Update ClusterProfile %s to deploy Kyverno helm chart", helmClusterProfile.Name)
Byf("Create ClusterProfile %s to deploy Kyverno helm chart", helmClusterProfile.Name)
helmClusterProfile.Spec.HelmCharts = []configv1beta1.HelmChart{
{
RepositoryURL: "https://kyverno.github.io/kyverno/",
Expand Down
81 changes: 47 additions & 34 deletions test/fv/autoscaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
rbacv1 "k8s.io/api/rbac/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/retry"

configv1beta1 "github.com/projectsveltos/addon-controller/api/v1beta1"
"github.com/projectsveltos/addon-controller/controllers"
Expand Down Expand Up @@ -72,12 +73,17 @@ var _ = Describe("Feature", func() {

It("Deploy resources in the management cluster and the managed cluster", Label("FV", "EXTENDED"), func() {
Byf("Extend sveltos addon-controller permission in the management cluster")
clusterRole := &rbacv1.ClusterRole{}
Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Name: "addon-controller-role-extra"}, clusterRole)).To(Succeed())
clusterRole.Rules = []rbacv1.PolicyRule{
{Verbs: []string{"*"}, APIGroups: []string{""}, Resources: []string{"serviceaccounts", "secrets"}},
}
Expect(k8sClient.Update(context.TODO(), clusterRole)).To(Succeed())

err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
clusterRole := &rbacv1.ClusterRole{}
Expect(k8sClient.Get(context.TODO(),
types.NamespacedName{Name: "addon-controller-role-extra"}, clusterRole)).To(Succeed())
clusterRole.Rules = []rbacv1.PolicyRule{
{Verbs: []string{"*"}, APIGroups: []string{""}, Resources: []string{"serviceaccounts", "secrets"}},
}
return k8sClient.Update(context.TODO(), clusterRole)
})
Expect(err).To(BeNil())

Byf("Create a ClusterProfile matching Cluster %s/%s", kindWorkloadCluster.Namespace, kindWorkloadCluster.Name)
clusterProfile := getClusterProfile(namePrefix, map[string]string{key: value})
Expand Down Expand Up @@ -116,37 +122,44 @@ var _ = Describe("Feature", func() {
}
Expect(k8sClient.Update(context.TODO(), currentConfigMap)).To(Succeed())

Byf("Update ClusterProfile %s to reference both ConfigMaps", clusterProfile.Name)
currentClusterProfile := &configv1beta1.ClusterProfile{}
Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Name: clusterProfile.Name}, currentClusterProfile)).To(Succeed())
currentClusterProfile.Spec.TemplateResourceRefs = []configv1beta1.TemplateResourceRef{
{
Resource: corev1.ObjectReference{
Kind: "Secret",
Name: autoscaler,

Byf("Update ClusterProfile %s to reference both ConfigMaps", clusterProfile.Name)
err = retry.RetryOnConflict(retry.DefaultRetry, func() error {
Expect(k8sClient.Get(context.TODO(),
types.NamespacedName{Name: clusterProfile.Name}, currentClusterProfile)).To(Succeed())
currentClusterProfile.Spec.TemplateResourceRefs = []configv1beta1.TemplateResourceRef{
{
Resource: corev1.ObjectReference{
Kind: "Secret",
Name: autoscaler,
},
Identifier: "AutoscalerSecret",
Optional: true,
},
Identifier: "AutoscalerSecret",
Optional: true,
},
}
currentClusterProfile.Spec.PolicyRefs = []configv1beta1.PolicyRef{
{
Kind: string(libsveltosv1beta1.ConfigMapReferencedResourceKind),
Namespace: configMapNs,
Name: configMap1Name,
// Deploy content of this configMap into management cluster
DeploymentType: configv1beta1.DeploymentTypeLocal,
},
{
Kind: string(libsveltosv1beta1.ConfigMapReferencedResourceKind),
Namespace: configMapNs,
Name: configMap2Name,
// Deploy content of this configMap into managed cluster
DeploymentType: configv1beta1.DeploymentTypeRemote,
},
}
Expect(k8sClient.Update(context.TODO(), currentClusterProfile)).To(Succeed())
}
currentClusterProfile.Spec.PolicyRefs = []configv1beta1.PolicyRef{
{
Kind: string(libsveltosv1beta1.ConfigMapReferencedResourceKind),
Namespace: configMapNs,
Name: configMap1Name,
// Deploy content of this configMap into management cluster
DeploymentType: configv1beta1.DeploymentTypeLocal,
},
{
Kind: string(libsveltosv1beta1.ConfigMapReferencedResourceKind),
Namespace: configMapNs,
Name: configMap2Name,
// Deploy content of this configMap into managed cluster
DeploymentType: configv1beta1.DeploymentTypeRemote,
},
}
return k8sClient.Update(context.TODO(), currentClusterProfile)
})
Expect(err).To(BeNil())

Expect(k8sClient.Get(context.TODO(),
types.NamespacedName{Name: clusterProfile.Name}, currentClusterProfile)).To(Succeed())
clusterSummary := verifyClusterSummary(controllers.ClusterProfileLabelName, clusterProfile.Name,
&currentClusterProfile.Spec, kindWorkloadCluster.Namespace, kindWorkloadCluster.Name)

Expand Down
103 changes: 56 additions & 47 deletions test/fv/continue_on_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/retry"

configv1beta1 "github.com/projectsveltos/addon-controller/api/v1beta1"
"github.com/projectsveltos/addon-controller/controllers"
Expand Down Expand Up @@ -105,57 +106,65 @@ var _ = Describe("Feature", Serial, func() {

Byf("Update ClusterProfile %s to deploy helm charts and referencing ConfigMap %s/%s",
clusterProfile.Name, configMap.Namespace, configMap.Name)
Byf("Setting ClusterProfile %s Spec.ContinueOnError true", clusterProfile.Name)

currentClusterProfile := &configv1beta1.ClusterProfile{}
Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Name: clusterProfile.Name},
currentClusterProfile)).To(Succeed())

// Cert-manager installation will fails as CRDs are not present and we are not deploying those
// ALso sets timeout otherwise helm takes too long before giving up on cert-manager failures (due to CRDs not being installed)
const two = 2
helmTimeout := metav1.Duration{Duration: two * time.Minute}
currentClusterProfile.Spec.HelmCharts = []configv1beta1.HelmChart{
{
RepositoryURL: "https://charts.konghq.com",
RepositoryName: "kong",
ChartName: "kong/kong",
ChartVersion: "2.46.0",
ReleaseName: "kong",
ReleaseNamespace: "kong",
HelmChartAction: configv1beta1.HelmChartActionInstall,
},
{
RepositoryURL: "https://charts.jetstack.io",
RepositoryName: "jetstack",
ChartName: "jetstack/cert-manager",
ChartVersion: "v1.16.2",
ReleaseName: "cert-manager",
ReleaseNamespace: "cert-manager",
HelmChartAction: configv1beta1.HelmChartActionInstall,
Options: &configv1beta1.HelmOptions{
Timeout: &helmTimeout,
err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Name: clusterProfile.Name},
currentClusterProfile)).To(Succeed())

// Cert-manager installation will fails as CRDs are not present and we are not deploying those
// ALso sets timeout otherwise helm takes too long before giving up on cert-manager failures (due to CRDs not being installed)
const two = 2
helmTimeout := metav1.Duration{Duration: two * time.Minute}
currentClusterProfile.Spec.HelmCharts = []configv1beta1.HelmChart{
{
RepositoryURL: "https://charts.konghq.com",
RepositoryName: "kong",
ChartName: "kong/kong",
ChartVersion: "2.46.0",
ReleaseName: "kong",
ReleaseNamespace: "kong",
HelmChartAction: configv1beta1.HelmChartActionInstall,
},
},
{
RepositoryURL: "https://helm.nginx.com/stable/",
RepositoryName: "nginx-stable",
ChartName: "nginx-stable/nginx-ingress",
ChartVersion: "1.3.1",
ReleaseName: "nginx-latest",
ReleaseNamespace: "nginx",
HelmChartAction: configv1beta1.HelmChartActionInstall,
},
}
currentClusterProfile.Spec.PolicyRefs = []configv1beta1.PolicyRef{
{
Kind: string(libsveltosv1beta1.ConfigMapReferencedResourceKind),
Namespace: configMap.Namespace,
Name: configMap.Name,
},
}
Byf("Setting ClusterProfile %s Spec.ContinueOnError true", clusterProfile.Name)
currentClusterProfile.Spec.ContinueOnError = true
{
RepositoryURL: "https://charts.jetstack.io",
RepositoryName: "jetstack",
ChartName: "jetstack/cert-manager",
ChartVersion: "v1.16.2",
ReleaseName: "cert-manager",
ReleaseNamespace: "cert-manager",
HelmChartAction: configv1beta1.HelmChartActionInstall,
Options: &configv1beta1.HelmOptions{
Timeout: &helmTimeout,
},
},
{
RepositoryURL: "https://helm.nginx.com/stable/",
RepositoryName: "nginx-stable",
ChartName: "nginx-stable/nginx-ingress",
ChartVersion: "1.3.1",
ReleaseName: "nginx-latest",
ReleaseNamespace: "nginx",
HelmChartAction: configv1beta1.HelmChartActionInstall,
},
}
currentClusterProfile.Spec.PolicyRefs = []configv1beta1.PolicyRef{
{
Kind: string(libsveltosv1beta1.ConfigMapReferencedResourceKind),
Namespace: configMap.Namespace,
Name: configMap.Name,
},
}
currentClusterProfile.Spec.ContinueOnError = true

return k8sClient.Update(context.TODO(), currentClusterProfile)
})
Expect(err).To(BeNil())

Expect(k8sClient.Update(context.TODO(), currentClusterProfile)).To(Succeed())
Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Name: clusterProfile.Name},
currentClusterProfile)).To(Succeed())

clusterSummary := verifyClusterSummary(controllers.ClusterProfileLabelName,
currentClusterProfile.Name, &currentClusterProfile.Spec,
Expand Down
73 changes: 45 additions & 28 deletions test/fv/dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/retry"

configv1beta1 "github.com/projectsveltos/addon-controller/api/v1beta1"
"github.com/projectsveltos/addon-controller/controllers"
Expand Down Expand Up @@ -53,45 +54,61 @@ var _ = Describe("Dependencies", func() {

Byf("Update ClusterProfile %s to deploy helm charts", clusterProfileDependency.Name)
currentClusterProfile := &configv1beta1.ClusterProfile{}
Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Name: clusterProfileDependency.Name}, currentClusterProfile)).To(Succeed())
currentClusterProfile.Spec.HelmCharts = []configv1beta1.HelmChart{
{
RepositoryURL: "https://airflow.apache.org",
RepositoryName: "apache-airflow",
ChartName: "apache-airflow/airflow",
ChartVersion: "1.15.0",
ReleaseName: "airflow",
ReleaseNamespace: "airflow",
HelmChartAction: configv1beta1.HelmChartActionInstall,
Values: `createUserJob:

err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
Expect(k8sClient.Get(context.TODO(),
types.NamespacedName{Name: clusterProfileDependency.Name}, currentClusterProfile)).To(Succeed())
currentClusterProfile.Spec.HelmCharts = []configv1beta1.HelmChart{
{
RepositoryURL: "https://airflow.apache.org",
RepositoryName: "apache-airflow",
ChartName: "apache-airflow/airflow",
ChartVersion: "1.15.0",
ReleaseName: "airflow",
ReleaseNamespace: "airflow",
HelmChartAction: configv1beta1.HelmChartActionInstall,
Values: `createUserJob:
useHelmHooks: false
applyCustomEnv: false
migrateDatabaseJob:
useHelmHooks: false
applyCustomEnv: false`,
},
}
Expect(k8sClient.Update(context.TODO(), currentClusterProfile)).To(Succeed())
},
}
return k8sClient.Update(context.TODO(), currentClusterProfile)
})
Expect(err).To(BeNil())

Expect(k8sClient.Get(context.TODO(),
types.NamespacedName{Name: clusterProfileDependency.Name}, currentClusterProfile)).To(Succeed())

clusterSummaryDependency := verifyClusterSummary(controllers.ClusterProfileLabelName,
currentClusterProfile.Name, &currentClusterProfile.Spec,
kindWorkloadCluster.Namespace, kindWorkloadCluster.Name)

Byf("Update ClusterProfile %s to deploy helm charts", clusterProfile.Name)
Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Name: clusterProfile.Name}, currentClusterProfile)).To(Succeed())
currentClusterProfile.Spec.HelmCharts = []configv1beta1.HelmChart{
{
RepositoryURL: "https://charts.bitnami.com/bitnami",
RepositoryName: "bitnami",
ChartName: "bitnami/flink",
ChartVersion: "1.4.0",
ReleaseName: "flink",
ReleaseNamespace: "flink",
HelmChartAction: configv1beta1.HelmChartActionInstall,
},
}

Expect(k8sClient.Update(context.TODO(), currentClusterProfile)).To(Succeed())
err = retry.RetryOnConflict(retry.DefaultRetry, func() error {
Expect(k8sClient.Get(context.TODO(),
types.NamespacedName{Name: clusterProfile.Name}, currentClusterProfile)).To(Succeed())
currentClusterProfile.Spec.HelmCharts = []configv1beta1.HelmChart{
{
RepositoryURL: "https://charts.bitnami.com/bitnami",
RepositoryName: "bitnami",
ChartName: "bitnami/flink",
ChartVersion: "1.4.0",
ReleaseName: "flink",
ReleaseNamespace: "flink",
HelmChartAction: configv1beta1.HelmChartActionInstall,
},
}

return k8sClient.Update(context.TODO(), currentClusterProfile)
})
Expect(err).To(BeNil())

Expect(k8sClient.Get(context.TODO(),
types.NamespacedName{Name: clusterProfile.Name}, currentClusterProfile)).To(Succeed())

clusterSummary := verifyClusterSummary(controllers.ClusterProfileLabelName,
currentClusterProfile.Name, &currentClusterProfile.Spec,
kindWorkloadCluster.Namespace, kindWorkloadCluster.Name)
Expand Down
Loading