Skip to content

Commit

Permalink
Merge "sfconfig prepare dev - use in CI jobs"
Browse files Browse the repository at this point in the history
  • Loading branch information
Microzuul CI authored and Gerrit Code Review committed Nov 17, 2023
2 parents 55dbc70 + 87a664f commit b6e6139
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 47 deletions.
16 changes: 13 additions & 3 deletions cli/sfconfig/cmd/dev/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ func Run() {
Cli: cli,
}
// TODO: only do gerrit when provision demo is on?
EnsureNamespacePermissions(&env)
EnsureNamespaces(&env)
EnsureMicroshiftWorkarounds(&env)
EnsureCertManager(&env)
EnsurePrometheusOperator(&env)
gerrit.EnsureGerrit(&env, sfconfig.FQDN)
Expand Down Expand Up @@ -131,12 +132,21 @@ func EnsureRepo(sfconfig *config.SFConfig, apiKey string, name string) {
utils.RunCmd("git", "-C", path, "reset", "--hard", "origin/master")
}

func EnsureNamespacePermissions(env *utils.ENV) {
func EnsureNamespaces(env *utils.ENV) {
// TODO: implement natively
// TODO: ensure setup-namespaces role use this to avoid duplication
utils.EnsureNamespace(env, env.Ns)
utils.RunCmd("kubectl", "config", "set-context", "microshift", "--namespace="+env.Ns)
utils.RunCmd("kubectl", "label", "--overwrite", "ns", env.Ns, "pod-security.kubernetes.io/enforce=privileged")
utils.RunCmd("kubectl", "label", "--overwrite", "ns", env.Ns, "pod-security.kubernetes.io/enforce-version=v1.24")
utils.RunCmd("oc", "adm", "policy", "add-scc-to-user", "privileged", "-z", "default")

utils.EnsureNamespace(env, "operators")
utils.RunCmd("oc", "adm", "policy", "add-scc-to-user", "privileged", "system:serviceaccount:operators:default")
}

func EnsureMicroshiftWorkarounds(env *utils.ENV) {
// TODO: migrate from Makefile to here
utils.RunCmd("make", "setup-prometheus-operator-serviceaccount", "OPERATOR_NAMESPACE=operators")
}

func EnsureCRD() {
Expand Down
14 changes: 1 addition & 13 deletions cli/sfconfig/cmd/nodepool/create_namespace_for_nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,12 @@ import (
"github.com/softwarefactory-project/sf-operator/controllers"
apiv1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/client-go/tools/clientcmd"
cliapi "k8s.io/client-go/tools/clientcmd/api"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/softwarefactory-project/sf-operator/cli/sfconfig/cmd/utils"
)

func ensureNamespace(env *utils.ENV, name string) {
var ns apiv1.Namespace
if err := env.Cli.Get(env.Ctx, client.ObjectKey{Name: name}, &ns); errors.IsNotFound(err) {
ns.Name = name
utils.CreateR(env, &ns)
} else if err != nil {
panic(fmt.Errorf("could not get namespace: %s", err))
}
}

func ensureRole(env *utils.ENV, sa string) {
var role rbacv1.Role
if !utils.GetM(env, "nodepool-role", &role) {
Expand Down Expand Up @@ -189,7 +177,7 @@ func CreateNamespaceForNodepool(sfEnv *utils.ENV, nodepoolContext string, nodepo
sa := "nodepool-sa"

// Ensure resources exists
ensureNamespace(&nodepoolEnv, nodepoolNamespace)
utils.EnsureNamespace(&nodepoolEnv, nodepoolNamespace)
utils.EnsureServiceAccount(&nodepoolEnv, sa)
ensureRole(&nodepoolEnv, sa)
token := ensureServiceAccountSecret(&nodepoolEnv, sa)
Expand Down
10 changes: 10 additions & 0 deletions cli/sfconfig/cmd/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ func RunCmd(cmdName string, args ...string) {
}
}

func EnsureNamespace(env *ENV, name string) {
var ns apiv1.Namespace
if err := env.Cli.Get(env.Ctx, client.ObjectKey{Name: name}, &ns); errors.IsNotFound(err) {
ns.Name = name
CreateR(env, &ns)
} else if err != nil {
panic(fmt.Errorf("could not get namespace: %s", err))
}
}

func EnsureServiceAccount(env *ENV, name string) {
var sa apiv1.ServiceAccount
if !GetM(env, name, &sa) {
Expand Down
18 changes: 1 addition & 17 deletions playbooks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,15 @@
- setup-variables
- setup-env
- sanity-check
- setup-namespaces
- start-gerrit
- sfconfig-dev-prepare
tasks:
- name: CI process(standalone)
block:
- community.general.make:
target: "{{ item }}"
chdir: "{{ zuul.project.src_dir }}"
loop:
- install-cert-manager
- install-prometheus-operator
- ansible.builtin.include_role:
name: start-prometheus
when: mode == 'standalone'

- name: CI process(OLM install)
ansible.builtin.include_role:
name: "{{ item }}"
loop:
- microshift-workarounds
- build-operator-assets
- clean-installations
- install-operator
# we start prometheus after installing the operator, to ensure the prometheus-operator dependency was installed properly.
- start-prometheus
- apply-custom-resources
when: mode == 'olm'

Expand Down
5 changes: 1 addition & 4 deletions playbooks/upgrade.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
- setup-variables
- setup-env
- sanity-check
- setup-namespaces
- microshift-workarounds
- start-gerrit
- sfconfig-dev-prepare
- role: build-operator-assets
vars:
build_bundle: false
Expand All @@ -20,5 +18,4 @@
build_bundle: true
ci_bundle_img: localhost:5000/sf-operator-bundle:latest
- upgrade-operator
- start-prometheus
- run-tests
File renamed without changes.
5 changes: 5 additions & 0 deletions roles/sfconfig-dev-prepare/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: Run the sfconfig dev prepare
command: "tools/sfconfig dev prepare"
args:
chdir: "{{ zuul.project.src_dir }}"
5 changes: 0 additions & 5 deletions roles/start-gerrit/tasks/main.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions roles/start-prometheus/tasks/main.yaml

This file was deleted.

0 comments on commit b6e6139

Please sign in to comment.