-
Notifications
You must be signed in to change notification settings - Fork 1
Added Harbor config to platform-operator #1099
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 6 commits
83497bd
306d01d
ca90786
4e72682
74b7675
424e640
5e7fc46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| from .models import ( | ||
| BucketsProvider, | ||
| DockerRegistryStorageDriver, | ||
| DockerRegistryType, | ||
| HelmChartNames, | ||
| IngressServiceType, | ||
| LabelsConfig, | ||
|
|
@@ -61,7 +62,10 @@ def create_platform_values(self, platform: PlatformConfig) -> dict[str, Any]: | |
| result: dict[str, Any] = { | ||
| "traefikEnabled": platform.ingress_controller_install, | ||
| "acmeEnabled": platform.ingress_acme_enabled, | ||
| "dockerRegistryEnabled": platform.registry.docker_registry_install, | ||
| "dockerRegistryEnabled": platform.registry.docker_registry_install | ||
| and platform.registry.docker_registry_type == DockerRegistryType.DOCKER, | ||
| "harborEnabled": platform.registry.docker_registry_install | ||
| and platform.registry.docker_registry_type == DockerRegistryType.HARBOR, | ||
jordyantunes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "appsPostgresOperatorEnabled": ( | ||
| platform.apps_operator_config.postgres_operator_enabled | ||
| ), | ||
|
|
@@ -198,9 +202,13 @@ def create_platform_values(self, platform: PlatformConfig) -> dict[str, Any]: | |
| else: | ||
| result["dockerHubConfigSecret"] = {"create": False} | ||
| if platform.registry.docker_registry_install: | ||
| result[HelmChartNames.docker_registry] = self.create_docker_registry_values( | ||
| platform | ||
| ) | ||
| if platform.registry.docker_registry_type == DockerRegistryType.DOCKER: | ||
| result[HelmChartNames.docker_registry] = ( | ||
| self.create_docker_registry_values(platform) | ||
| ) | ||
| elif platform.registry.docker_registry_type == DockerRegistryType.HARBOR: | ||
| result[HelmChartNames.harbor] = self.create_harbor_values(platform) | ||
|
|
||
| if platform.buckets.minio_install: | ||
| assert platform.buckets.minio_public_url | ||
| result["ingress"]["minioHost"] = platform.buckets.minio_public_url.host | ||
|
|
@@ -411,6 +419,73 @@ def create_docker_registry_values(self, platform: PlatformConfig) -> dict[str, A | |
| } | ||
| return result | ||
|
|
||
| def create_harbor_values(self, platform: PlatformConfig) -> dict[str, Any]: | ||
| docker_registry_credentials_secret_name = ( | ||
| f"{platform.release_name}-docker-registry" | ||
| ) | ||
| harbor_external_host = f"harbor.apps.{platform.ingress_dns_name}" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why harbor.apps...? It's not an app |
||
| result: dict[str, Any] = { | ||
| "expose": { | ||
| "tls": {"enabled": False}, | ||
| "ingress": { | ||
| "hosts": {"core": harbor_external_host}, | ||
| "className": "traefik", | ||
| "annotations": None, | ||
| }, | ||
| }, | ||
| "persistence": { | ||
| "persistentVolumeClaim": { | ||
| "registry": {}, | ||
| }, | ||
| "imageChartStorage": {}, | ||
| }, | ||
| "externalURL": harbor_external_host, | ||
| } | ||
|
|
||
| if ( | ||
| platform.registry.docker_registry_username | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to save images to docker registry? |
||
| and platform.registry.docker_registry_password | ||
| ): | ||
| assert platform.registry.docker_registry_username == "admin" | ||
| result["existingSecretAdminPassword"] = ( | ||
| docker_registry_credentials_secret_name | ||
| ) | ||
| result["existingSecretAdminPasswordKey"] = "password" | ||
|
|
||
| if ( | ||
| platform.registry.docker_registry_storage_driver | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you need to support persistence to disk? |
||
| == DockerRegistryStorageDriver.FILE_SYSTEM | ||
| ): | ||
| result["persistence"]["imageChartStorage"]["type"] = "filesystem" | ||
| result["persistence"]["persistentVolumeClaim"]["registry"] = { | ||
| "storageClass": ( | ||
| platform.registry.docker_registry_file_system_storage_class_name | ||
| ), | ||
| "size": platform.registry.docker_registry_file_system_storage_size, | ||
| } | ||
| elif ( | ||
| platform.registry.docker_registry_storage_driver | ||
| == DockerRegistryStorageDriver.S3 | ||
| ): | ||
| assert platform.registry.docker_registry_s3_endpoint | ||
| result["persistence"]["imageChartStorage"]["type"] = "s3" | ||
| result["persistence"]["imageChartStorage"]["s3"] = { | ||
| "bucket": str(platform.registry.docker_registry_s3_bucket), | ||
| "region": platform.registry.docker_registry_s3_region, | ||
| "regionendpoint": self._get_url_authority( | ||
| platform.registry.docker_registry_s3_endpoint | ||
| ), | ||
| "accesskey": platform.registry.docker_registry_s3_access_key, | ||
| "secretkey": platform.registry.docker_registry_s3_secret_key, | ||
| "secure": platform.registry.docker_registry_s3_endpoint.scheme | ||
| == "https", | ||
| "rootdirectory": "/harbor", | ||
| } | ||
| result["persistence"]["imageChartStorage"]["disableredirect"] = ( | ||
| platform.registry.docker_registry_s3_disable_redirect | ||
| ) | ||
| return result | ||
|
|
||
| def create_minio_values(self, platform: PlatformConfig) -> dict[str, Any]: | ||
| assert platform.buckets.minio_public_url | ||
| return { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,6 +106,7 @@ class HelmReleaseNames: | |
|
|
||
| class HelmChartNames: | ||
| docker_registry: str = "docker-registry" | ||
| harbor: str = "harbor" | ||
| minio: str = "minio" | ||
| minio_gateway: str = "minio-gateway" | ||
| traefik: str = "traefik" | ||
|
|
@@ -596,6 +597,11 @@ class DockerRegistryStorageDriver(str, Enum): | |
| S3 = "s3" | ||
|
|
||
|
|
||
| class DockerRegistryType(str, Enum): | ||
| DOCKER = "docker" | ||
| HARBOR = "harbor" | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class RegistryConfig: | ||
| provider: RegistryProvider | ||
|
|
@@ -610,6 +616,7 @@ class RegistryConfig: | |
| azure_password: str = "" | ||
|
|
||
| docker_registry_install: bool = False | ||
| docker_registry_type: DockerRegistryType = DockerRegistryType.DOCKER | ||
| docker_registry_url: URL | None = None | ||
| docker_registry_username: str = "" | ||
| docker_registry_password: str = "" | ||
|
|
@@ -1035,7 +1042,7 @@ def create(self, platform_body: kopf.Body, cluster: Cluster) -> PlatformConfig: | |
| idle_jobs=cluster.orchestrator.idle_jobs, | ||
| buckets=buckets_config, | ||
| registry=self._create_registry( | ||
| spec.registry, buckets_config=buckets_config | ||
| spec.registry, buckets_config=buckets_config, cluster=cluster | ||
| ), | ||
| monitoring=self._create_monitoring(spec.monitoring), | ||
| disks_storage_limit_per_user=cluster.disks.storage_limit_per_user, | ||
|
|
@@ -1222,7 +1229,7 @@ def _create_buckets(self, spec: BlobStorageSpec, cluster: Cluster) -> BucketsCon | |
| raise ValueError("Bucket provider is not supported") | ||
|
|
||
| def _create_registry( | ||
| self, spec: RegistrySpec, *, buckets_config: BucketsConfig | ||
| self, spec: RegistrySpec, *, buckets_config: BucketsConfig, cluster: Cluster | ||
| ) -> RegistryConfig: | ||
| if not spec: | ||
| raise ValueError("Registry spec is empty") | ||
|
|
@@ -1256,14 +1263,24 @@ def _create_registry( | |
| docker_registry_password=spec.docker_password, | ||
| ) | ||
| if "kubernetes" in spec: | ||
| return RegistryConfig( | ||
| provider=RegistryProvider.DOCKER, | ||
| docker_registry_install=True, | ||
| docker_registry_url=URL.build( | ||
| reg_type = DockerRegistryType( | ||
| spec.get("kubernetes", {}).get("registry_type", "docker") | ||
| ) | ||
| if reg_type == DockerRegistryType.HARBOR: | ||
| docker_registry_url = URL.build( | ||
| scheme="https", host=f"harbor.apps.{cluster.dns.name}" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not in-cluster service hostname? |
||
| ) | ||
| else: | ||
| docker_registry_url = URL.build( | ||
| scheme="http", | ||
| host=f"{self._config.helm_release_names.platform}-docker-registry", | ||
| port=5000, | ||
| ), | ||
| ) | ||
| return RegistryConfig( | ||
| provider=RegistryProvider.DOCKER, | ||
| docker_registry_install=True, | ||
| docker_registry_type=reg_type, | ||
| docker_registry_url=docker_registry_url, | ||
| docker_registry_storage_driver=DockerRegistryStorageDriver.FILE_SYSTEM, | ||
| docker_registry_file_system_storage_class_name=( | ||
| spec.kubernetes_storage_class_name | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need a condition for harbor?