diff --git a/.github/workflows/nightly.yaml b/.github/workflows/nightly.yaml index 9925252..b462b43 100644 --- a/.github/workflows/nightly.yaml +++ b/.github/workflows/nightly.yaml @@ -122,10 +122,9 @@ jobs: flux reconcile kustomization violating-podinfo -n default --with-source || true kubectl get pods -A - - name: Wait 3 minutes for the App reconciliation - uses: jakejarvis/wait-action@master - with: - time: '3m' + - name: Install gitopsset-configmaps + run: | + kubectl apply -f ./utils/data/gitops-sets-kustomization.yaml - name: run tests if: success() diff --git a/README.md b/README.md index 7ad1450..dfd782b 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,11 @@ It is recommended to install latest and stable version of these tools. All tools flux reconcile kustomization violating-podinfo -n default --with-source || true kubectl get pods -A ``` + +11. Install gitopsset. + ```bash + kubectl apply -f ./utils/data/gitops-sets-kustomization.yaml + ``` ## Run Tests diff --git a/gitops-sets/config-map-generator.yaml b/gitops-sets/config-map-generator.yaml new file mode 100644 index 0000000..8dca592 --- /dev/null +++ b/gitops-sets/config-map-generator.yaml @@ -0,0 +1,30 @@ +apiVersion: templates.weave.works/v1alpha1 +kind: GitOpsSet +metadata: + labels: + kustomize.toolkit.fluxcd.io/name: flux-system + kustomize.toolkit.fluxcd.io/namespace: flux-system + name: gitopsset-configmaps + namespace: default +spec: + generators: + - list: + elements: + - env: dev + team: dev-team + - env: production + team: ops-team + - env: staging + team: ops-team + templates: + - content: + apiVersion: v1 + kind: ConfigMap + metadata: + name: "{{ .Element.env }}-info-configmap" + namespace: default + spec: + data: + description: This is a configmap for the {{ .Element.env }} environment + env: "{{ .Element.env }}" + team: "{{ .Element.team }}" diff --git a/gitops-sets/dev-info-configmap.yaml b/gitops-sets/dev-info-configmap.yaml new file mode 100644 index 0000000..b1e89a4 --- /dev/null +++ b/gitops-sets/dev-info-configmap.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + labels: + templates.weave.works/name: gitopsset-configmaps + templates.weave.works/namespace: default + name: dev-info-configmap + namespace: default diff --git a/gitops-sets/kustomization.yaml b/gitops-sets/kustomization.yaml new file mode 100644 index 0000000..e3b7334 --- /dev/null +++ b/gitops-sets/kustomization.yaml @@ -0,0 +1,8 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - config-map-generator.yaml + - dev-info-configmap.yaml + - production-info-configmap.yaml + - staging-info-configmap.yaml + - role.yaml diff --git a/gitops-sets/production-info-configmap.yaml b/gitops-sets/production-info-configmap.yaml new file mode 100644 index 0000000..a764621 --- /dev/null +++ b/gitops-sets/production-info-configmap.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + labels: + templates.weave.works/name: gitopsset-configmaps + templates.weave.works/namespace: default + name: production-info-configmap + namespace: default diff --git a/gitops-sets/role.yaml b/gitops-sets/role.yaml new file mode 100644 index 0000000..52f5981 --- /dev/null +++ b/gitops-sets/role.yaml @@ -0,0 +1,62 @@ +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: demo-role +rules: +- apiGroups: + - kustomize.toolkit.fluxcd.io + resources: + - kustomizations + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: demo-role-binding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: demo-role +subjects: +- kind: ServiceAccount + name: gitopssets-controller-manager + namespace: flux-system +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: configmaps-demo-role +rules: +- apiGroups: + - "" + resources: + - configmaps + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: configmaps-role-binding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: configmaps-demo-role +subjects: +- kind: ServiceAccount + name: gitopssets-controller-manager + namespace: flux-system diff --git a/gitops-sets/staging-info-configmap.yaml b/gitops-sets/staging-info-configmap.yaml new file mode 100644 index 0000000..0ad8e63 --- /dev/null +++ b/gitops-sets/staging-info-configmap.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + labels: + templates.weave.works/name: gitopsset-configmaps + templates.weave.works/namespace: default + name: staging-info-configmap + namespace: default diff --git a/pages/gitopssets_page.py b/pages/gitopssets_page.py new file mode 100644 index 0000000..c54fc22 --- /dev/null +++ b/pages/gitopssets_page.py @@ -0,0 +1,21 @@ +class GitopsSets: + def __init__(self, page): + self.page = page + + def open_gitopssets_page(self): + self.page.get_by_role("link", name="GitOpsSets").click() + + def open_gitopssets_details_page(self): + self.page.get_by_role("link", name="gitopsset-configmaps").click() + + def open_gitopssets_events_tab(self): + self.page.get_by_role("tab", name="Events").click() + + def open_gitopssets_graph_tab(self): + self.page.get_by_role("tab", name="Graph").click() + + def open_gitopssets_yaml_tab(self): + self.page.get_by_role("tab", name="Yaml").click() + + def back_to_gitopssets_list(self): + self.page.get_by_test_id("link-GitOpsSet").click() diff --git a/test_weave_gitops_enterprise/test_policies_applications.py b/test_weave_gitops_enterprise/test_applications.py similarity index 61% rename from test_weave_gitops_enterprise/test_policies_applications.py rename to test_weave_gitops_enterprise/test_applications.py index 991d88b..0d1d8db 100644 --- a/test_weave_gitops_enterprise/test_policies_applications.py +++ b/test_weave_gitops_enterprise/test_applications.py @@ -1,32 +1,10 @@ import os from playwright.sync_api import Playwright, sync_playwright, expect -from pages.policies_page import Policies from pages.application_page import Applications import pytest -@pytest.mark.usefixtures("login") -class TestPolicies: - - @pytest.fixture(autouse=True) - def _obj(self, login): - self.page = login - self.policies_page = Policies(self.page) - self.URL = os.getenv("URL") - - def test_open_policies_page(self): - self.policies_page.open_policies_page() - expect(self.page).to_have_url(f"{self.URL}/policies/list") - - def test_open_policy_details_page(self): - self.policies_page.open_policy_details_page() - expect(self.page).to_have_url(f"{self.URL}/policy_details/" - f"details?clusterName=management" - f"&id=weave.policies.containers-minimum-replica-count" - f"&name=Containers%20Minimum%20Replica%20Count") - - @pytest.mark.usefixtures("login") class TestApplications: @pytest.fixture(autouse=True) @@ -36,15 +14,16 @@ def _create_obj(self, login): self.URL = os.getenv("URL") def test_open_applications_page(self): + self.page.reload() self.applications_page.open_application_page() expect(self.page).to_have_url(f"{self.URL}/applications") + expect(self.page.locator("//table")).to_contain_text("violating-podinfo") def test_open_application_details_page(self): - self.page.reload() self.applications_page.open_application_details_page() expect(self.page).to_have_url(f"{self.URL}/kustomization/" - f"details?clusterName=management" - f"&name=violating-podinfo&namespace=default") + "details?clusterName=management" + "&name=violating-podinfo&namespace=default") def test_open_application_more_info(self): self.applications_page.open_application_more_info() @@ -53,35 +32,35 @@ def test_open_application_more_info(self): def test_open_application_events_tab(self): self.applications_page.open_application_events_tab() expect(self.page).to_have_url(f"{self.URL}/kustomization/" - f"events?clusterName=management" - f"&name=violating-podinfo&namespace=default") + "events?clusterName=management" + "&name=violating-podinfo&namespace=default") def test_open_application_graph_tab(self): self.applications_page.open_application_graph_tab() expect(self.page).to_have_url(f"{self.URL}/kustomization/" - f"graph?clusterName=management" - f"&name=violating-podinfo&namespace=default") + "graph?clusterName=management" + "&name=violating-podinfo&namespace=default") def test_open_application_dependencies_tab(self): self.applications_page.open_application_dependencies_tab() expect(self.page).to_have_url(f"{self.URL}/kustomization/" - f"dependencies?clusterName=management" - f"&name=violating-podinfo&namespace=default") + "dependencies?clusterName=management" + "&name=violating-podinfo&namespace=default") expect(self.page.get_by_text("What are dependencies for?")).to_be_visible() def test_open_application_yaml(self): self.applications_page.open_application_yaml_tab() - expect (self.page).to_have_url (f"{self.URL}/kustomization/" - f"yaml?clusterName=management" - f"&name=violating-podinfo&namespace=default") + expect (self.page).to_have_url(f"{self.URL}/kustomization/" + "yaml?clusterName=management" + "&name=violating-podinfo&namespace=default") expect(self.page.get_by_text("kubectl get kustomization violating-podinfo -n default -o yaml")).to_be_visible() # page.pause() def test_open_application_violations_page(self): self.applications_page.open_application_violations_tab() expect(self.page).to_have_url(f"{self.URL}/kustomization/" - f"violations?clusterName=management" - f"&name=violating-podinfo&namespace=default") + "violations?clusterName=management" + "&name=violating-podinfo&namespace=default") def test_open_application_violations_details(self): self.applications_page.open_application_violations_details() @@ -97,8 +76,8 @@ def test_open_policy_details_from_app_violations_details_page(self): def test_open_policy_violations_page(self): self.applications_page.open_policy_violations_page() expect(self.page).to_have_url(f"{self.URL}/policy_details/violations?clusterName=management" - f"&id=weave.policies.container-image-pull-policy" - f"&name=Container%20Image%20Pull%20Policy") + "&id=weave.policies.container-image-pull-policy" + "&name=Container%20Image%20Pull%20Policy") def test_open_policy_violations_details_page(self): self.applications_page.open_policy_violations_details_page() diff --git a/test_weave_gitops_enterprise/test_gitopssets.py b/test_weave_gitops_enterprise/test_gitopssets.py new file mode 100644 index 0000000..0f4d452 --- /dev/null +++ b/test_weave_gitops_enterprise/test_gitopssets.py @@ -0,0 +1,52 @@ +import os + +from playwright.sync_api import Playwright, sync_playwright, expect +from pages.gitopssets_page import GitopsSets +import pytest + + +@pytest.mark.usefixtures("login") +class TestGitopsSets: + @pytest.fixture(autouse=True) + def _create_obj(self, login): + self.page = login + self.gitopssets_page = GitopsSets(self.page) + self.URL = os.getenv("URL") + + def test_open_gitopssets_page(self): + self.gitopssets_page.open_gitopssets_page() + expect(self.page).to_have_url(f"{self.URL}/gitopssets") + + def test_open_gitopssets_details_page(self): + self.gitopssets_page.open_gitopssets_details_page() + expect(self.page).to_have_url(f"{self.URL}/gitopssets/object/details?" + "clusterName=management" + "&name=gitopsset-configmaps" + "&namespace=default") + + def test_open_gitopssets_events_tab(self): + self.gitopssets_page.open_gitopssets_events_tab() + expect(self.page).to_have_url(f"{self.URL}/gitopssets/object/events?" + "clusterName=management" + "&name=gitopsset-configmaps" + "&namespace=default") + + def test_open_gitopssets_graph_tab(self): + self.gitopssets_page.open_gitopssets_graph_tab() + expect(self.page).to_have_url(f"{self.URL}/gitopssets/object/graph?" + "clusterName=management" + "&name=gitopsset-configmaps" + "&namespace=default") + + def test_open_gitopssets_yaml_tab(self): + self.gitopssets_page.open_gitopssets_yaml_tab() + expect(self.page).to_have_url(f"{self.URL}/gitopssets/object/yaml?" + "clusterName=management" + "&name=gitopsset-configmaps" + "&namespace=default") + expect(self.page.get_by_text("kubectl get gitopsset gitopsset-configmaps -n default -o yaml")).to_be_visible() + + def test_back_to_gitopssets_list(self): + self.gitopssets_page.back_to_gitopssets_list() + expect(self.page).to_have_url(f"{self.URL}/gitopssets") + expect(self.page.locator("tbody")).to_contain_text("gitopsset-configmaps") diff --git a/test_weave_gitops_enterprise/test_policies.py b/test_weave_gitops_enterprise/test_policies.py new file mode 100644 index 0000000..3c5e291 --- /dev/null +++ b/test_weave_gitops_enterprise/test_policies.py @@ -0,0 +1,26 @@ +import os + +from playwright.sync_api import Playwright, sync_playwright, expect +from pages.policies_page import Policies +import pytest + + +@pytest.mark.usefixtures("login") +class TestPolicies: + + @pytest.fixture(autouse=True) + def _obj(self, login): + self.page = login + self.policies_page = Policies(self.page) + self.URL = os.getenv("URL") + + def test_open_policies_page(self): + self.policies_page.open_policies_page() + expect(self.page).to_have_url(f"{self.URL}/policies/list") + + def test_open_policy_details_page(self): + self.policies_page.open_policy_details_page() + expect(self.page).to_have_url(f"{self.URL}/policy_details/" + "details?clusterName=management" + "&id=weave.policies.containers-minimum-replica-count" + "&name=Containers%20Minimum%20Replica%20Count") diff --git a/utils/data/gitops-sets-kustomization.yaml b/utils/data/gitops-sets-kustomization.yaml new file mode 100644 index 0000000..4371782 --- /dev/null +++ b/utils/data/gitops-sets-kustomization.yaml @@ -0,0 +1,15 @@ +apiVersion: kustomize.toolkit.fluxcd.io/v1 +kind: Kustomization +metadata: + name: gitopsset-configmaps + namespace: default +spec: + interval: 10m + targetNamespace: default + sourceRef: + kind: GitRepository + name: flux-system + namespace: flux-system + path: ./gitops-sets + prune: true + timeout: 1m