Skip to content

Commit

Permalink
feat(registry): 🚀 support custom image registries
Browse files Browse the repository at this point in the history
  • Loading branch information
tunahanertekin authored Aug 15, 2023
2 parents bead2c4 + 4665678 commit 10b594a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 24 deletions.
28 changes: 20 additions & 8 deletions internal/node/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ type ReadyRobotProperties struct {
func GetReadyRobotProperties(robot robotv1alpha1.Robot) ReadyRobotProperties {
labels := robot.GetLabels()

if user, hasUser := labels[internal.ROBOT_IMAGE_USER]; hasUser {
if repository, hasRepository := labels[internal.ROBOT_IMAGE_REPOSITORY]; hasRepository {
if tag, hasTag := labels[internal.ROBOT_IMAGE_TAG]; hasTag {
return ReadyRobotProperties{
Enabled: true,
Image: user + "/" + repository + ":" + tag,
if registry, hasRegistry := labels[internal.ROBOT_IMAGE_REGISTRY_LABEL_KEY]; hasRegistry {
if user, hasUser := labels[internal.ROBOT_IMAGE_USER_LABEL_KEY]; hasUser {
if repository, hasRepository := labels[internal.ROBOT_IMAGE_REPOSITORY_LABEL_KEY]; hasRepository {
if tag, hasTag := labels[internal.ROBOT_IMAGE_TAG_LABEL_KEY]; hasTag {
return ReadyRobotProperties{
Enabled: true,
Image: registry + "/" + user + "/" + repository + ":" + tag,
}
}
}
}
Expand Down Expand Up @@ -99,13 +101,18 @@ func GetImageForRobot(node corev1.Node, robot robotv1alpha1.Robot) (string, erro
return "", err
}

registry, hasRegistry := robot.Labels[internal.ROBOT_IMAGE_REGISTRY_LABEL_KEY]
if !hasRegistry {
return "", errors.New("registry is not found in label with key " + internal.ROBOT_IMAGE_REGISTRY_LABEL_KEY)
}

organization := "robolaunchio"
repository := "devspace-robotics"
tagBuilder.WriteString(imageProps.Application.Name + "-")
tagBuilder.WriteString(imageProps.Application.Version)
tagBuilder.WriteString("-" + imageProps.DevSpaceImage.UbuntuDistro + "-" + imageProps.DevSpaceImage.Desktop)
tagBuilder.WriteString("-" + imageProps.DevSpaceImage.Version)
imageBuilder.WriteString(filepath.Join(organization, repository) + ":")
imageBuilder.WriteString(filepath.Join(registry, organization, repository) + ":")
imageBuilder.WriteString(tagBuilder.String())

}
Expand All @@ -131,6 +138,11 @@ func GetImageForEnvironment(node corev1.Node, robot robotv1alpha1.Robot) (string
return "", err
}

registry, hasRegistry := robot.Labels[internal.ROBOT_IMAGE_REGISTRY_LABEL_KEY]
if !hasRegistry {
return "", errors.New("registry is not found in label with key " + internal.ROBOT_IMAGE_REGISTRY_LABEL_KEY)
}

organization := imageProps.Organization
repository := imageProps.Repository

Expand Down Expand Up @@ -199,7 +211,7 @@ func GetImageForEnvironment(node corev1.Node, robot robotv1alpha1.Robot) (string
tagBuilder.WriteString(chosenElement.DevSpaceImage.Desktop + "-")
tagBuilder.WriteString(chosenElement.DevSpaceImage.Version)

imageBuilder.WriteString(filepath.Join(organization, repository) + ":")
imageBuilder.WriteString(filepath.Join(registry, organization, repository) + ":")
imageBuilder.WriteString(tagBuilder.String())

}
Expand Down
7 changes: 4 additions & 3 deletions internal/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ const (

// Ready robot label
const (
ROBOT_IMAGE_USER = "robolaunch.io/robot-image-user"
ROBOT_IMAGE_REPOSITORY = "robolaunch.io/robot-image-repository"
ROBOT_IMAGE_TAG = "robolaunch.io/robot-image-tag"
ROBOT_IMAGE_REGISTRY_LABEL_KEY = "robolaunch.io/robot-image-registry"
ROBOT_IMAGE_USER_LABEL_KEY = "robolaunch.io/robot-image-user"
ROBOT_IMAGE_REPOSITORY_LABEL_KEY = "robolaunch.io/robot-image-repository"
ROBOT_IMAGE_TAG_LABEL_KEY = "robolaunch.io/robot-image-tag"
)

// Target resource labels
Expand Down
33 changes: 20 additions & 13 deletions pkg/api/roboscale.io/v1alpha1/robot_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,13 @@ var _ webhook.Defaulter = &Robot{}
func (r *Robot) Default() {
robotlog.Info("default", "name", r.Name)

DefaultRepositoryPaths(r)
r.setDefaultLabels()
r.setRepositoryPaths()
_ = r.setRepositoryInfo()
r.setWorkspacesPath()
r.setDiscoveryServerDomainID()
}

func DefaultRepositoryPaths(r *Robot) {
for wsKey := range r.Spec.WorkspaceManagerTemplate.Workspaces {
ws := r.Spec.WorkspaceManagerTemplate.Workspaces[wsKey]
for repoKey := range ws.Repositories {
repo := ws.Repositories[repoKey]
repo.Path = r.Spec.WorkspaceManagerTemplate.WorkspacesPath + "/" + ws.Name + "/src/" + repoKey
ws.Repositories[repoKey] = repo
}
r.Spec.WorkspaceManagerTemplate.Workspaces[wsKey] = ws
}
}

//+kubebuilder:webhook:path=/validate-robot-roboscale-io-v1alpha1-robot,mutating=false,failurePolicy=fail,sideEffects=None,groups=robot.roboscale.io,resources=robots,verbs=create;update,versions=v1alpha1,name=vrobot.kb.io,admissionReviewVersions=v1

var _ webhook.Validator = &Robot{}
Expand Down Expand Up @@ -217,6 +206,24 @@ func (r *Robot) checkRobotDevSuite() error {
return nil
}

func (r *Robot) setDefaultLabels() {
if _, ok := r.Labels[internal.ROBOT_IMAGE_REGISTRY_LABEL_KEY]; !ok {
r.Labels[internal.ROBOT_IMAGE_REGISTRY_LABEL_KEY] = "docker.io"
}
}

func (r *Robot) setRepositoryPaths() {
for wsKey := range r.Spec.WorkspaceManagerTemplate.Workspaces {
ws := r.Spec.WorkspaceManagerTemplate.Workspaces[wsKey]
for repoKey := range ws.Repositories {
repo := ws.Repositories[repoKey]
repo.Path = r.Spec.WorkspaceManagerTemplate.WorkspacesPath + "/" + ws.Name + "/src/" + repoKey
ws.Repositories[repoKey] = repo
}
r.Spec.WorkspaceManagerTemplate.Workspaces[wsKey] = ws
}
}

func (r *Robot) setRepositoryInfo() error {

for k1, ws := range r.Spec.WorkspaceManagerTemplate.Workspaces {
Expand Down

0 comments on commit 10b594a

Please sign in to comment.