Skip to content

Commit 076f78d

Browse files
authored
Merge pull request #22709 from deads2k/scc-client
SCC must use json or it cannot bootstrap
2 parents 921eb33 + 8bd8449 commit 076f78d

1 file changed

Lines changed: 29 additions & 4 deletions

File tree

pkg/cmd/openshift-apiserver/openshiftapiserver/openshift_apiserver.go

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"time"
88

99
restful "github.com/emicklei/go-restful"
10-
"k8s.io/klog"
1110

1211
kapierror "k8s.io/apimachinery/pkg/api/errors"
1312
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -17,8 +16,9 @@ import (
1716
genericapiserver "k8s.io/apiserver/pkg/server"
1817
genericmux "k8s.io/apiserver/pkg/server/mux"
1918
kubeinformers "k8s.io/client-go/informers"
20-
restclient "k8s.io/client-go/rest"
19+
"k8s.io/client-go/rest"
2120
"k8s.io/client-go/restmapper"
21+
"k8s.io/klog"
2222
openapicontroller "k8s.io/kube-aggregator/pkg/controllers/openapi"
2323
openapiaggregator "k8s.io/kube-aggregator/pkg/controllers/openapi/aggregator"
2424
"k8s.io/kubernetes/pkg/api/legacyscheme"
@@ -61,7 +61,7 @@ type OpenshiftAPIExtraConfig struct {
6161
// we phrase it like this so we can build the post-start-hook, but no one can take more indirect dependencies on informers
6262
InformerStart func(stopCh <-chan struct{})
6363

64-
KubeAPIServerClientConfig *restclient.Config
64+
KubeAPIServerClientConfig *rest.Config
6565
KubeInformers kubeinformers.SharedInformerFactory
6666

6767
QuotaInformers quotainformer.SharedInformerFactory
@@ -580,10 +580,15 @@ func (c *completedConfig) bootstrapSCC(context genericapiserver.PostStartHookCon
580580
ns := bootstrappolicy.DefaultOpenShiftInfraNamespace
581581
bootstrapSCCGroups, bootstrapSCCUsers := bootstrappolicy.GetBoostrapSCCAccess(ns)
582582

583+
// ClusterResourceQuota is served using CRD resource any status update must use JSON
584+
jsonLoopbackClientConfig := rest.CopyConfig(c.ExtraConfig.KubeAPIServerClientConfig)
585+
jsonLoopbackClientConfig.ContentConfig.AcceptContentTypes = "application/json"
586+
jsonLoopbackClientConfig.ContentConfig.ContentType = "application/json"
587+
583588
var securityClient securityv1client.SecurityV1Interface
584589
err := wait.Poll(1*time.Second, 30*time.Second, func() (bool, error) {
585590
var err error
586-
securityClient, err = securityv1client.NewForConfig(context.LoopbackClientConfig)
591+
securityClient, err = securityv1client.NewForConfig(jsonLoopbackClientConfig)
587592
if err != nil {
588593
utilruntime.HandleError(fmt.Errorf("unable to initialize client: %v", err))
589594
return false, nil
@@ -606,6 +611,26 @@ func (c *completedConfig) bootstrapSCC(context genericapiserver.PostStartHookCon
606611
}
607612
klog.Infof("Created default security context constraint %s", scc.Name)
608613
}
614+
615+
// until we only use the CRD, this has to be done twice. Once for CRD creation, once when aggregated APIs take over. Remove after we
616+
// switch
617+
go func() {
618+
wait.PollUntil(10*time.Second, func() (bool, error) {
619+
for _, scc := range bootstrappolicy.GetBootstrapSecurityContextConstraints(bootstrapSCCGroups, bootstrapSCCUsers) {
620+
_, err := securityClient.SecurityContextConstraints().Create(scc)
621+
if kapierror.IsAlreadyExists(err) {
622+
continue
623+
}
624+
if err != nil {
625+
utilruntime.HandleError(fmt.Errorf("unable to create default security context constraint %s. Got error: %v", scc.Name, err))
626+
continue
627+
}
628+
klog.Infof("Created default security context constraint %s", scc.Name)
629+
}
630+
return false, nil
631+
}, context.StopCh)
632+
}()
633+
609634
return nil
610635
}
611636

0 commit comments

Comments
 (0)