Skip to content

Commit

Permalink
refactor(image): add registry to image selector function
Browse files Browse the repository at this point in the history
  • Loading branch information
tunahanertekin committed Aug 15, 2023
1 parent 4af759d commit 4665678
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
22 changes: 16 additions & 6 deletions internal/node/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ type ReadyRobotProperties struct {
func GetReadyRobotProperties(robot robotv1alpha1.Robot) ReadyRobotProperties {
labels := robot.GetLabels()

if registry, hasRegistry := labels[internal.ROBOT_IMAGE_REGISTRY]; hasRegistry {
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 {
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 @@ -101,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 @@ -133,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 @@ -201,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
8 changes: 4 additions & 4 deletions internal/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ const (

// Ready robot label
const (
ROBOT_IMAGE_REGISTRY = "docker.io"
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
4 changes: 2 additions & 2 deletions pkg/api/roboscale.io/v1alpha1/robot_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ func (r *Robot) checkRobotDevSuite() error {
}

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

Expand Down

0 comments on commit 4665678

Please sign in to comment.