Skip to content

Commit

Permalink
Enable to run in both namespace- and cluster-scope
Browse files Browse the repository at this point in the history
  • Loading branch information
mareklibra committed May 13, 2019
1 parent ace45af commit c7dfacf
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
| {{ openshift_client_binary }} apply -f -
- name: Add service-ca ConfigMap
shell: "{{ openshift_client_binary }} apply -f {{ __service_ca_config_file }}"
shell: "{{ openshift_client_binary }} apply -f {{ __service_ca_config_file }} -n {{ kubevirt_web_ui_namespace }}"

- name: Add V2VVmware Custom Resource Definition
shell: "{{ openshift_client_binary }} apply -f {{ __v2vvmware_crd_file }}"
Expand Down
11 changes: 5 additions & 6 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import (
"os"
"runtime"

"github.com/operator-framework/operator-sdk/pkg/k8sutil"
"github.com/kubevirt/web-ui-operator/pkg/apis"
"github.com/kubevirt/web-ui-operator/pkg/controller"
"github.com/operator-framework/operator-sdk/pkg/leader"
"github.com/operator-framework/operator-sdk/pkg/ready"
sdkVersion "github.com/operator-framework/operator-sdk/version"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"github.com/kubevirt/web-ui-operator/pkg/apis"
"github.com/kubevirt/web-ui-operator/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
Expand All @@ -39,13 +38,13 @@ func main() {
logf.SetLogger(logf.ZapLogger(false))

printVersion()

/*
namespace, err := k8sutil.GetWatchNamespace()
if err != nil {
log.Error(err, "failed to get watch namespace")
os.Exit(1)
}

*/
// Get a config to talk to the apiserver
cfg, err := config.GetConfig()
if err != nil {
Expand All @@ -67,7 +66,7 @@ func main() {
defer r.Unset()

// Create a new Cmd to provide shared dependencies and start components
mgr, err := manager.New(cfg, manager.Options{Namespace: namespace})
mgr, err := manager.New(cfg, manager.Options{Namespace: ""}) // Resources will be watched in all namespaces to support even the cluster-scoped deployment (HCO)
if err != nil {
log.Error(err, "")
os.Exit(1)
Expand Down
4 changes: 4 additions & 0 deletions pkg/components/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ func GetDeployment(namespace string, repository string, tag string, imagePullPol
return deployment
}


// The GetRole() is probably not needed since the use of `components.go` implicates operator's deployment for cluster-scope (within HCO).
// To avoid confusion: If deployed independently using the deploy/*.yaml files, the operator is namespace-scoped.
// TODO: validate the statement above and optionally remove this GetRole() function.
func GetRole(namespace string) *rbacv1.Role {
role := &rbacv1.Role{
TypeMeta: metav1.TypeMeta{
Expand Down
11 changes: 11 additions & 0 deletions pkg/controller/kwebui/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@ func loginClient(namespace string) (string, error) {
}
err = RunCommand(cmd, args, env, args)
if err != nil {
log.Error(err, "Failed to switch to the project. Trying to create it.", "Namespace", namespace)

cmd, args = "oc", []string{
"new-project",
namespace,
}
err = RunCommand(cmd, args, env, args)
if err != nil {
log.Error(err, "Failed to create project for the web-ui.", "Namespace", namespace)
}

return "", err
}

Expand Down

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

0 comments on commit c7dfacf

Please sign in to comment.