Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
30 changes: 28 additions & 2 deletions pkg/controllers/cluster-policy-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
clusterpolicycontroller "github.com/openshift/cluster-policy-controller/pkg/cmd/cluster-policy-controller"
"github.com/openshift/library-go/pkg/controller/controllercmd"
"github.com/openshift/library-go/pkg/operator/events"
"github.com/openshift/microshift/pkg/assets"
"github.com/openshift/microshift/pkg/config"
corev1 "k8s.io/api/core/v1"
unstructuredv1 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand All @@ -32,6 +33,7 @@ import (

type ClusterPolicyController struct {
run func(context.Context) error
applyRBAC func(context.Context) error
Comment thread
pacevedom marked this conversation as resolved.
Outdated
kubeconfig string

configErr error
Expand All @@ -45,11 +47,31 @@ func NewClusterPolicyController(cfg *config.Config) *ClusterPolicyController {

func (s *ClusterPolicyController) Name() string { return "cluster-policy-controller" }
func (s *ClusterPolicyController) Dependencies() []string {
return []string{"kube-apiserver", "infrastructure-services-manager"}
return []string{"kube-apiserver"}
}

func (s *ClusterPolicyController) configure(cfg *config.Config) error {
s.kubeconfig = cfg.KubeConfigPath(config.ClusterPolicyController)
s.applyRBAC = func(ctx context.Context) error {
kubeconfigPath := cfg.KubeConfigPath(config.KubeAdmin)
cr := []string{
"controllers/cluster-policy-controller/namespace-security-allocation-controller-clusterrole.yaml",
"controllers/cluster-policy-controller/podsecurity-admission-label-syncer-controller-clusterrole.yaml",
"controllers/cluster-policy-controller/podsecurity-admission-label-privileged-namespaces-syncer-controller-clusterrole.yaml",
}
crb := []string{
"controllers/cluster-policy-controller/namespace-security-allocation-controller-clusterrolebinding.yaml",
"controllers/cluster-policy-controller/podsecurity-admission-label-syncer-controller-clusterrolebinding.yaml",
"controllers/cluster-policy-controller/podsecurity-admission-label-privileged-namespaces-syncer-controller-clusterrolebinding.yaml",
}
if err := assets.ApplyClusterRoles(ctx, cr, kubeconfigPath); err != nil {
return fmt.Errorf("failed to apply cluster-policy-controller RBAC: %w", err)
}
if err := assets.ApplyClusterRoleBindings(ctx, crb, kubeconfigPath); err != nil {
return fmt.Errorf("failed to apply cluster-policy-controller RBAC: %w", err)
}
return nil
}

scheme := runtime.NewScheme()
if err := openshiftcontrolplanev1.AddToScheme(scheme); err != nil {
Expand Down Expand Up @@ -101,6 +123,10 @@ func (s *ClusterPolicyController) Run(ctx context.Context, ready chan<- struct{}
return fmt.Errorf("configuration failed: %w", s.configErr)
}

close(ready) // todo
if err := s.applyRBAC(ctx); err != nil {
return err
}

close(ready)
return s.run(ctx)
}
33 changes: 0 additions & 33 deletions pkg/controllers/infra-services-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,48 +44,15 @@ func (s *InfrastructureServicesManager) Run(ctx context.Context, ready chan<- st
defer close(stopped)
defer close(ready)

if err := applyDefaultRBACs(ctx, s.cfg); err != nil {
klog.Errorf("%s unable to apply default RBACs: %v", s.Name(), err)
return err
}

priorityClasses := []string{"core/priority-class-openshift-user-critical.yaml"}
if err := assets.ApplyPriorityClasses(ctx, priorityClasses, s.cfg.KubeConfigPath(config.KubeAdmin)); err != nil {
klog.Errorf("%s unable to apply PriorityClasses: %v", s.Name(), err)
return err
}

// TO-DO add readiness check
if err := components.StartComponents(s.cfg, ctx); err != nil {
return err
}
klog.Infof("%s launched ocp componets", s.Name())
return ctx.Err()
}

func applyDefaultRBACs(ctx context.Context, cfg *config.Config) error {
kubeconfigPath := cfg.KubeConfigPath(config.KubeAdmin)
var (
cr = []string{
"controllers/kube-controller-manager/csr_approver_clusterrole.yaml",
"controllers/cluster-policy-controller/namespace-security-allocation-controller-clusterrole.yaml",
"controllers/cluster-policy-controller/podsecurity-admission-label-syncer-controller-clusterrole.yaml",
"controllers/cluster-policy-controller/podsecurity-admission-label-privileged-namespaces-syncer-controller-clusterrole.yaml",
}
crb = []string{
"controllers/kube-controller-manager/csr_approver_clusterrolebinding.yaml",
"controllers/cluster-policy-controller/namespace-security-allocation-controller-clusterrolebinding.yaml",
"controllers/cluster-policy-controller/podsecurity-admission-label-syncer-controller-clusterrolebinding.yaml",
"controllers/cluster-policy-controller/podsecurity-admission-label-privileged-namespaces-syncer-controller-clusterrolebinding.yaml",
}
)
if err := assets.ApplyClusterRoles(ctx, cr, kubeconfigPath); err != nil {
klog.Warningf("failed to apply cluster roles %v", err)
return err
}
if err := assets.ApplyClusterRoleBindings(ctx, crb, kubeconfigPath); err != nil {
klog.Warningf("failed to apply cluster roles %v", err)
return err
}
return nil
}
20 changes: 17 additions & 3 deletions pkg/controllers/kube-controller-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,24 @@ func configure(ctx context.Context, cfg *config.Config) (args []string, applyFn

args, err = mergeAndConvertToArgs(overrides)
applyFn = func() error {
return assets.ApplyNamespaces(ctx, []string{
kubeconfigPath := cfg.KubeConfigPath(config.KubeAdmin)
if err := assets.ApplyNamespaces(ctx, []string{
"controllers/kube-controller-manager/namespace-openshift-kube-controller-manager.yaml",
"core/namespace-openshift-infra.yaml",
}, cfg.KubeConfigPath(config.KubeAdmin))
}, kubeconfigPath); err != nil {
return fmt.Errorf("failed to apply kube-controller-manager namespaces: %w", err)
}
if err := assets.ApplyClusterRoles(ctx, []string{
"controllers/kube-controller-manager/csr_approver_clusterrole.yaml",
}, kubeconfigPath); err != nil {
return fmt.Errorf("failed to apply kube-controller-manager RBAC: %w", err)
}
if err := assets.ApplyClusterRoleBindings(ctx, []string{
"controllers/kube-controller-manager/csr_approver_clusterrolebinding.yaml",
}, kubeconfigPath); err != nil {
return fmt.Errorf("failed to apply kube-controller-manager RBAC: %w", err)
}
return nil
}
return args, applyFn, err
}
Expand Down Expand Up @@ -157,7 +171,7 @@ func (s *KubeControllerManager) Run(ctx context.Context, ready chan<- struct{},
}()

if err := s.applyFn(); err != nil {
return fmt.Errorf("failed to apply openshift namespaces: %w", err)
return err
}

select {
Expand Down