-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make registry installation a component
- Loading branch information
Showing
4 changed files
with
159 additions
and
100 deletions.
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
pkg/oc/bootstrap/clusterup/components/registry/registry_install.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package registry | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path" | ||
|
||
"github.com/golang/glog" | ||
|
||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/rest" | ||
|
||
"github.com/openshift/origin/pkg/oc/bootstrap/clusterup/componentinstall" | ||
"github.com/openshift/origin/pkg/oc/bootstrap/docker/dockerhelper" | ||
"github.com/openshift/origin/pkg/oc/bootstrap/docker/openshift" | ||
"github.com/openshift/origin/pkg/oc/bootstrap/docker/run" | ||
"github.com/openshift/origin/pkg/oc/errors" | ||
securityclient "github.com/openshift/origin/pkg/security/generated/internalclientset/typed/security/internalversion" | ||
) | ||
|
||
const ( | ||
DefaultNamespace = "default" | ||
SvcDockerRegistry = "docker-registry" | ||
masterConfigDir = "/var/lib/origin/openshift.local.config/master" | ||
RegistryServiceIP = "172.30.1.1" | ||
) | ||
|
||
type RegistryComponentOptions struct { | ||
ClusterAdminKubeConfig *rest.Config | ||
|
||
OCImage string | ||
MasterConfigDir string | ||
Images string | ||
PVDir string | ||
} | ||
|
||
func (r *RegistryComponentOptions) Name() string { | ||
return "openshift-image-registry" | ||
} | ||
|
||
func (r *RegistryComponentOptions) Install(dockerClient dockerhelper.Interface, logdir string) error { | ||
kubeClient, err := kubernetes.NewForConfig(r.ClusterAdminKubeConfig) | ||
_, err = kubeClient.Core().Services(DefaultNamespace).Get(SvcDockerRegistry, metav1.GetOptions{}) | ||
if err == nil { | ||
// If there's no error, the registry already exists | ||
return nil | ||
} | ||
if !apierrors.IsNotFound(err) { | ||
return errors.NewError("error retrieving docker registry service").WithCause(err) | ||
} | ||
|
||
imageRunHelper := run.NewRunHelper(dockerhelper.NewHelper(dockerClient)).New() | ||
glog.Infof("Running %q", r.Name()) | ||
|
||
securityClient, err := securityclient.NewForConfig(r.ClusterAdminKubeConfig) | ||
if err != nil { | ||
return err | ||
} | ||
err = openshift.AddSCCToServiceAccount(securityClient, "privileged", "registry", "default", os.Stdout) | ||
if err != nil { | ||
return errors.NewError("cannot add privileged SCC to registry service account").WithCause(err) | ||
} | ||
|
||
// Obtain registry markup. The reason it is not created outright is because | ||
// we need to modify the ClusterIP of the registry service. The command doesn't | ||
// have an option to set it. | ||
flags := []string{ | ||
"adm", | ||
"registry", | ||
"--loglevel=8", | ||
"--config=" + masterConfigDir + "/admin.kubeconfig", | ||
fmt.Sprintf("--images=%s", r.Images), | ||
fmt.Sprintf("--mount-host=%s", path.Join(r.PVDir, "registry")), | ||
} | ||
_, stdout, stderr, rc, err := imageRunHelper.Image(r.OCImage). | ||
Privileged(). | ||
DiscardContainer(). | ||
HostNetwork(). | ||
HostPid(). | ||
Bind(r.MasterConfigDir + ":" + masterConfigDir). | ||
Entrypoint("oc"). | ||
Command(flags...).Output() | ||
|
||
if err := componentinstall.LogContainer(logdir, r.Name(), stdout, stderr); err != nil { | ||
glog.Errorf("error logging %q: %v", r.Name(), err) | ||
} | ||
if err != nil { | ||
return errors.NewError("could not run %q: %v", r.Name(), err).WithCause(err) | ||
} | ||
if rc != 0 { | ||
return errors.NewError("could not run %q: rc==%v", r.Name(), rc) | ||
} | ||
|
||
svc, err := kubeClient.Core().Services(DefaultNamespace).Get(SvcDockerRegistry, metav1.GetOptions{}) | ||
if err != nil { | ||
return err | ||
} | ||
svc.ResourceVersion = "" | ||
svc.Spec.ClusterIP = RegistryServiceIP | ||
if err := kubeClient.Core().Services(DefaultNamespace).Delete(svc.Name, nil); err != nil { | ||
return err | ||
} | ||
if _, err := kubeClient.Core().Services(DefaultNamespace).Create(svc); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
vendor/k8s.io/kubernetes/staging/src/k8s.io/client-go/tools/clientcmd/client_config.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.