Skip to content
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

feat(k8s): Add MinIO as internal(default) storage #272

Merged
merged 2 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,15 @@ public static synchronized ComputerOptions instance() {
"snapshot.minio_access_key",
"The access key of MinIO.",
null,
""
"minioadmin"
);

public static final ConfigOption<String> SNAPSHOT_MINIO_SECRET_KEY =
new ConfigOption<>(
"snapshot.minio_secret_key",
"The secret key of MinIO.",
null,
""
"minioadmin"
);

public static final ConfigOption<String> SNAPSHOT_MINIO_BUCKET_NAME =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

package org.apache.hugegraph.computer.core.snapshot;

import io.minio.BucketExistsArgs;
import io.minio.DownloadObjectArgs;
import io.minio.ListObjectsArgs;
import io.minio.MakeBucketArgs;
import io.minio.MinioClient;
import io.minio.RemoveObjectsArgs;
import io.minio.Result;
Expand Down Expand Up @@ -89,14 +91,29 @@
@Override
public void init(Config config) {
String endpoint = config.get(ComputerOptions.SNAPSHOT_MINIO_ENDPOINT);
String accessKey = config.get(ComputerOptions.SNAPSHOT_MINIO_ACCESS_KEY);
String secretKey = config.get(ComputerOptions.SNAPSHOT_MINIO_SECRET_KEY);
this.bucketName = config.get(ComputerOptions.SNAPSHOT_MINIO_BUCKET_NAME);
if (StringUtils.isNotEmpty(endpoint)) {

if (StringUtils.isNotEmpty(endpoint) && StringUtils.isNotEmpty(this.bucketName)) {
String accessKey = config.get(ComputerOptions.SNAPSHOT_MINIO_ACCESS_KEY);
String secretKey = config.get(ComputerOptions.SNAPSHOT_MINIO_SECRET_KEY);

Check warning on line 98 in computer-core/src/main/java/org/apache/hugegraph/computer/core/snapshot/SnapshotManager.java

View check run for this annotation

Codecov / codecov/patch

computer-core/src/main/java/org/apache/hugegraph/computer/core/snapshot/SnapshotManager.java#L97-L98

Added lines #L97 - L98 were not covered by tests
this.minioClient = MinioClient.builder()
.endpoint(endpoint)
.credentials(accessKey, secretKey)
.build();

try {
boolean bucketExist = this.minioClient.bucketExists(
BucketExistsArgs.builder()
.bucket(this.bucketName)
.build());

Check warning on line 108 in computer-core/src/main/java/org/apache/hugegraph/computer/core/snapshot/SnapshotManager.java

View check run for this annotation

Codecov / codecov/patch

computer-core/src/main/java/org/apache/hugegraph/computer/core/snapshot/SnapshotManager.java#L105-L108

Added lines #L105 - L108 were not covered by tests
if (!bucketExist) {
this.minioClient.makeBucket(MakeBucketArgs.builder()
.bucket(this.bucketName)
.build());

Check warning on line 112 in computer-core/src/main/java/org/apache/hugegraph/computer/core/snapshot/SnapshotManager.java

View check run for this annotation

Codecov / codecov/patch

computer-core/src/main/java/org/apache/hugegraph/computer/core/snapshot/SnapshotManager.java#L110-L112

Added lines #L110 - L112 were not covered by tests
}
} catch (Exception e) {
throw new ComputerException("Failed to initialize bucket %s", this.bucketName, e);
}

Check warning on line 116 in computer-core/src/main/java/org/apache/hugegraph/computer/core/snapshot/SnapshotManager.java

View check run for this annotation

Codecov / codecov/patch

computer-core/src/main/java/org/apache/hugegraph/computer/core/snapshot/SnapshotManager.java#L114-L116

Added lines #L114 - L116 were not covered by tests
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ resources:
- ../rbac
- ../etcd
- ../manager
- ../minio
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
- ../webhook
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ spec:
value: "6"
- name: INTERNAL_ETCD_URL
value: "http://hugegraph-computer-operator-etcd.hugegraph-computer-operator-system:2379"
- name: INTERNAL_MINIO_URL
value: "http://hugegraph-computer-operator-minio.hugegraph-computer-operator-system:9000"
- name: LOG_LEVEL
value: "INFO"
- name: AUTO_DESTROY_POD
Expand Down
27 changes: 27 additions & 0 deletions computer-k8s-operator/crd-generate/config/minio/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
resources:
- minio_server.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: minio
newName: quay.io/minio/minio
newTag: RELEASE.2023-10-16T04-13-43Z
commonLabels:
app.kubernetes.io/name: hugegraph-computer-operator-minio
app.kubernetes.io/version: v1
108 changes: 108 additions & 0 deletions computer-k8s-operator/crd-generate/config/minio/minio_server.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: local-storage
namespace: system
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
---
apiVersion: v1
kind: Service
metadata:
labels:
service.app: hugegraph-computer-operator-minio
name: minio
namespace: system
annotations:
service.alpha.kubernetes.io/tolerate-unready-endpoints: 'true'
spec:
ports:
- name: client
port: 9000
protocol: TCP
targetPort: 9090
selector:
service.app: hugegraph-computer-operator-minio
clusterIP: None
type: ClusterIP
sessionAffinity: None
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: minio
namespace: system
spec:
replicas: 1
selector:
matchLabels:
service.app: hugegraph-computer-operator-minio
template:
metadata:
labels:
service.app: hugegraph-computer-operator-minio
spec:
hostname: hugegraph-computer-operator-minio-0
subdomain: hugegraph-computer-operator-minio
containers:
- name: hugegraph-computer-operator-minio
image: minio:latest
command:
- /bin/bash
- -c
args:
- minio server /data --console-address :9090
env:
# MinIO access key and secret key
- name: MINIO_ACCESS_KEY
value: "minioadmin"
- name: MINIO_SECRET_KEY
value: "minioadmin"
ports:
- name: client
containerPort: 9090
volumeMounts:
- mountPath: /data
name: localvolume # Corresponds to the `spec.volumes` Persistent Volume
livenessProbe:
httpGet:
path: /minio/health/live
port: 9000
scheme: HTTP
initialDelaySeconds: 120
periodSeconds: 30
timeoutSeconds: 10
successThreshold: 1
failureThreshold: 3
readinessProbe:
httpGet:
path: /minio/health/ready
# TODO: check the port
port: 9000
scheme: HTTP
initialDelaySeconds: 120
periodSeconds: 15
timeoutSeconds: 10
successThreshold: 1
failureThreshold: 3
volumes:
- name: localvolume
hostPath: # MinIO generally recommends using locally-attached volumes
path: /mnt/disk1/data # Specify a path to a local drive or volume on the Kubernetes worker node
type: DirectoryOrCreate # The path to the last directory must exist
107 changes: 107 additions & 0 deletions computer-k8s-operator/manifest/hugegraph-computer-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ metadata:
control-plane: controller-manager
name: hugegraph-computer-operator-system
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
labels:
app.kubernetes.io/name: hugegraph-computer-operator-minio
app.kubernetes.io/version: v1
name: hugegraph-computer-operator-local-storage
namespace: system
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
---
apiVersion: v1
kind: ServiceAccount
metadata:
Expand Down Expand Up @@ -436,6 +447,31 @@ spec:
---
apiVersion: v1
kind: Service
metadata:
annotations:
service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
labels:
app.kubernetes.io/name: hugegraph-computer-operator-minio
app.kubernetes.io/version: v1
service.app: hugegraph-computer-operator-minio
name: hugegraph-computer-operator-minio
namespace: hugegraph-computer-operator-system
spec:
clusterIP: None
ports:
- name: client
port: 9000
protocol: TCP
targetPort: 9090
selector:
app.kubernetes.io/name: hugegraph-computer-operator-minio
app.kubernetes.io/version: v1
service.app: hugegraph-computer-operator-minio
sessionAffinity: None
type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
name: hugegraph-computer-operator-webhook-service
namespace: hugegraph-computer-operator-system
Expand Down Expand Up @@ -525,6 +561,8 @@ spec:
value: "6"
- name: INTERNAL_ETCD_URL
value: http://hugegraph-computer-operator-etcd.hugegraph-computer-operator-system:2379
- name: INTERNAL_MINIO_URL
value: http://hugegraph-computer-operator-minio.hugegraph-computer-operator-system:9000
- name: LOG_LEVEL
value: INFO
- name: AUTO_DESTROY_POD
Expand Down Expand Up @@ -620,6 +658,75 @@ spec:
hostname: hugegraph-computer-operator-etcd-0
subdomain: hugegraph-computer-operator-etcd
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app.kubernetes.io/name: hugegraph-computer-operator-minio
app.kubernetes.io/version: v1
name: hugegraph-computer-operator-minio
namespace: hugegraph-computer-operator-system
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: hugegraph-computer-operator-minio
app.kubernetes.io/version: v1
service.app: hugegraph-computer-operator-minio
template:
metadata:
labels:
app.kubernetes.io/name: hugegraph-computer-operator-minio
app.kubernetes.io/version: v1
service.app: hugegraph-computer-operator-minio
spec:
containers:
- args:
- minio server /data --console-address :9090
command:
- /bin/bash
- -c
env:
- name: MINIO_ACCESS_KEY
value: minioadmin
- name: MINIO_SECRET_KEY
value: minioadmin
image: quay.io/minio/minio:RELEASE.2023-10-16T04-13-43Z
livenessProbe:
failureThreshold: 3
httpGet:
path: /minio/health/live
port: 9000
scheme: HTTP
initialDelaySeconds: 120
periodSeconds: 30
successThreshold: 1
timeoutSeconds: 10
name: hugegraph-computer-operator-minio
ports:
- containerPort: 9090
name: client
readinessProbe:
failureThreshold: 3
httpGet:
path: /minio/health/ready
port: 9000
scheme: HTTP
initialDelaySeconds: 120
periodSeconds: 15
successThreshold: 1
timeoutSeconds: 10
volumeMounts:
- mountPath: /data
name: localvolume
hostname: hugegraph-computer-operator-minio-0
subdomain: hugegraph-computer-operator-minio
volumes:
- hostPath:
path: /mnt/disk1/data
type: DirectoryOrCreate
name: localvolume
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ public static synchronized OperatorOptions instance() {
"http://127.0.0.1:2379"
);

public static final ConfigOption<String> INTERNAL_MINIO_URL =
new ConfigOption<>(
"k8s.internal_minio_url",
"The internal minio url for operator system.",
disallowEmpty(),
"http://127.0.0.1:9000"
);

public static final ConfigOption<Boolean> AUTO_DESTROY_POD =
new ConfigOption<>(
"k8s.auto_destroy_pod",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,14 @@ public class ComputerJobDeployer {
private static final Long TERMINATION_GRACE_PERIOD = 180L;

private final String internalEtcdUrl;
private final String internalMinIOUrl;
private final String timezone;

public ComputerJobDeployer(NamespacedKubernetesClient kubeClient,
HugeConfig config) {
this.kubeClient = kubeClient;
this.internalEtcdUrl = config.get(OperatorOptions.INTERNAL_ETCD_URL);
this.internalMinIOUrl = config.get(OperatorOptions.INTERNAL_MINIO_URL);
this.timezone = config.get(OperatorOptions.TIMEZONE);
}

Expand Down Expand Up @@ -186,6 +188,8 @@ private Set<ContainerPort> handleConfig(ComputerJobSpec spec) {
config.put(ComputerOptions.RPC_SERVER_HOST_NAME, ip);
config.putIfAbsent(ComputerOptions.BSP_ETCD_ENDPOINTS.name(),
this.internalEtcdUrl);
config.putIfAbsent(ComputerOptions.SNAPSHOT_MINIO_ENDPOINT.name(),
this.internalMinIOUrl);

String transportPort = config.get(
ComputerOptions.TRANSPORT_SERVER_PORT.name());
Expand Down
Loading