Skip to content

Commit df4bbf5

Browse files
committed
SCC bootstrapping must not return until it has created all defaults
1 parent 9cf4d51 commit df4bbf5

3 files changed

Lines changed: 36 additions & 28 deletions

File tree

hack/local-up-master/lib.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ function localup::start_kubeapiserver() {
220220
for filename in ${OS_ROOT}/hack/local-up-master/kube-apiserver-manifests/*.yaml; do
221221
oc --config=${LOCALUP_CONFIG}/kube-apiserver/admin.kubeconfig apply -f ${filename}
222222
done
223+
224+
NON_LOOPBACK_IPV4=$(ip -o -4 addr show up primary scope global | awk '{print $4}' | cut -f1 -d'/' | head -n1)
225+
for filename in ${OS_ROOT}/hack/local-up-master/openshift-apiserver-manifests/*.yaml; do
226+
sed "s/NON_LOOPBACK_HOST/${NON_LOOPBACK_IPV4}/g" ${filename} | oc --config=${LOCALUP_CONFIG}/kube-apiserver/admin.kubeconfig apply -f -
227+
done
223228
}
224229

225230
function localup::start_kubecontrollermanager() {
@@ -264,10 +269,6 @@ function localup::start_openshiftapiserver() {
264269
kube::util::wait_for_url "https://${API_HOST_IP}:8444/healthz" "openshift-apiserver: " 1 ${WAIT_FOR_URL_API_SERVER} ${MAX_TIME_FOR_URL_API_SERVER} \
265270
|| { os::log::error "check kube-apiserver logs: ${OPENSHIFT_APISERVER_LOG}" ; exit 1 ; }
266271

267-
NON_LOOPBACK_IPV4=$(ip -o -4 addr show up primary scope global | awk '{print $4}' | cut -f1 -d'/' | head -n1)
268-
for filename in ${OS_ROOT}/hack/local-up-master/openshift-apiserver-manifests/*.yaml; do
269-
sed "s/NON_LOOPBACK_HOST/${NON_LOOPBACK_IPV4}/g" ${filename} | oc --config=${LOCALUP_CONFIG}/openshift-apiserver/openshift-apiserver.kubeconfig apply -f -
270-
done
271272
}
272273

273274
function localup::start_openshiftcontrollermanager() {

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

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -580,42 +580,48 @@ 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
583+
// SCC is served using CRD resource any status update must use JSON
584584
jsonLoopbackClientConfig := rest.CopyConfig(c.ExtraConfig.KubeAPIServerClientConfig)
585585
jsonLoopbackClientConfig.ContentConfig.AcceptContentTypes = "application/json"
586586
jsonLoopbackClientConfig.ContentConfig.ContentType = "application/json"
587-
588-
var securityClient securityv1client.SecurityV1Interface
589-
err := wait.Poll(1*time.Second, 30*time.Second, func() (bool, error) {
590-
var err error
591-
securityClient, err = securityv1client.NewForConfig(jsonLoopbackClientConfig)
592-
if err != nil {
593-
utilruntime.HandleError(fmt.Errorf("unable to initialize client: %v", err))
594-
return false, nil
595-
}
596-
return true, nil
597-
})
587+
securityClient, err := securityv1client.NewForConfig(jsonLoopbackClientConfig)
598588
if err != nil {
599589
utilruntime.HandleError(fmt.Errorf("error getting client: %v", err))
600590
return err
601591
}
602592

603-
for _, scc := range bootstrappolicy.GetBootstrapSecurityContextConstraints(bootstrapSCCGroups, bootstrapSCCUsers) {
604-
_, err := securityClient.SecurityContextConstraints().Create(scc)
605-
if kapierror.IsAlreadyExists(err) {
593+
// all SCC must exist before we report success
594+
err = wait.PollUntil(1*time.Second, func() (bool, error) {
595+
anySCCMissing := false
596+
for _, scc := range bootstrappolicy.GetBootstrapSecurityContextConstraints(bootstrapSCCGroups, bootstrapSCCUsers) {
597+
_, err := securityClient.SecurityContextConstraints().Create(scc)
598+
if err == nil {
599+
klog.Infof("Created default security context constraint %s", scc.Name)
600+
continue
601+
}
602+
if kapierror.IsAlreadyExists(err) {
603+
klog.V(4).Infof("default security context constraint %s, already exists", scc.Name)
604+
continue
605+
}
606+
anySCCMissing = true
607+
utilruntime.HandleError(fmt.Errorf("unable to create default security context constraint %s; %v", scc.Name, err))
606608
continue
607609
}
608-
if err != nil {
609-
utilruntime.HandleError(fmt.Errorf("unable to create default security context constraint %s. Got error: %v", scc.Name, err))
610-
continue
610+
if anySCCMissing {
611+
return false, nil
611612
}
612-
klog.Infof("Created default security context constraint %s", scc.Name)
613+
614+
return true, nil
615+
}, context.StopCh)
616+
if err != nil {
617+
utilruntime.HandleError(fmt.Errorf("error creating SCC: %v", err))
618+
return err
613619
}
614620

615621
// 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
616622
// switch
617623
go func() {
618-
wait.PollUntil(10*time.Second, func() (bool, error) {
624+
wait.PollUntil(5*time.Second, func() (bool, error) {
619625
for _, scc := range bootstrappolicy.GetBootstrapSecurityContextConstraints(bootstrapSCCGroups, bootstrapSCCUsers) {
620626
_, err := securityClient.SecurityContextConstraints().Create(scc)
621627
if kapierror.IsAlreadyExists(err) {

test/util/server/server.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,8 @@ func startOpenShiftAPIServer(masterConfig *configapi.MasterConfig, clientConfig
515515
if err != nil {
516516
return err
517517
}
518-
if err := waitForServerHealthy(openshiftAddr); err != nil {
519-
return fmt.Errorf("Waiting for OpenShift API /healthz failed with: %v", err)
520-
}
521-
522518
targetPort := intstr.Parse(openshiftAddr.Port())
519+
523520
kubeClient, err := kubernetes.NewForConfig(clientConfig)
524521
if err != nil {
525522
return err
@@ -598,6 +595,10 @@ func startOpenShiftAPIServer(masterConfig *configapi.MasterConfig, clientConfig
598595
}
599596
}
600597

598+
if err := waitForServerHealthy(openshiftAddr); err != nil {
599+
return fmt.Errorf("Waiting for OpenShift API /healthz failed with: %v", err)
600+
}
601+
601602
err = wait.Poll(time.Second, 3*time.Minute, func() (bool, error) {
602603
discoveryClient, err := discovery.NewDiscoveryClientForConfig(clientConfig)
603604
if err != nil {

0 commit comments

Comments
 (0)