-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complete operator functionality (#235)
* Make the operator work Signed-off-by: carlosthe19916 <[email protected]> * Upgrade xbuilder version Signed-off-by: carlosthe19916 <[email protected]> * Upgrade xbuilder version Signed-off-by: carlosthe19916 <[email protected]> Signed-off-by: carlosthe19916 <[email protected]>
- Loading branch information
1 parent
bc6997a
commit 6151d9a
Showing
13 changed files
with
277 additions
and
61 deletions.
There are no files selected for viewing
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
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
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
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
78 changes: 78 additions & 0 deletions
78
.../src/main/java/io/github/project/openubl/operator/cdrs/v2alpha1/UblhubFileStoragePVC.java
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,78 @@ | ||
/* | ||
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed 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. | ||
*/ | ||
package io.github.project.openubl.operator.cdrs.v2alpha1; | ||
|
||
import io.fabric8.kubernetes.api.model.PersistentVolumeClaim; | ||
import io.fabric8.kubernetes.api.model.PersistentVolumeClaimBuilder; | ||
import io.fabric8.kubernetes.api.model.PersistentVolumeClaimSpec; | ||
import io.fabric8.kubernetes.api.model.PersistentVolumeClaimSpecBuilder; | ||
import io.fabric8.kubernetes.api.model.Quantity; | ||
import io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder; | ||
import io.github.project.openubl.operator.Constants; | ||
import io.github.project.openubl.operator.utils.CRDUtils; | ||
import io.javaoperatorsdk.operator.api.reconciler.Context; | ||
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; | ||
|
||
import java.util.Map; | ||
|
||
public class UblhubFileStoragePVC extends CRUDKubernetesDependentResource<PersistentVolumeClaim, Ublhub> { | ||
|
||
public UblhubFileStoragePVC() { | ||
super(PersistentVolumeClaim.class); | ||
} | ||
|
||
@Override | ||
public PersistentVolumeClaim desired(Ublhub cr, Context context) { | ||
return newPersistentVolumeClaim(cr, context); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private PersistentVolumeClaim newPersistentVolumeClaim(Ublhub cr, Context context) { | ||
final var labels = (Map<String, String>) context.managedDependentResourceContext() | ||
.getMandatory(Constants.CONTEXT_LABELS_KEY, Map.class); | ||
|
||
PersistentVolumeClaim pvc = new PersistentVolumeClaimBuilder() | ||
.withNewMetadata() | ||
.withName(getPersistentVolumeClaimName(cr)) | ||
.withNamespace(cr.getMetadata().getNamespace()) | ||
.withLabels(labels) | ||
.endMetadata() | ||
.withSpec(getPersistentVolumeClaimSpec(cr)) | ||
.build(); | ||
return pvc; | ||
} | ||
|
||
private PersistentVolumeClaimSpec getPersistentVolumeClaimSpec(Ublhub cr) { | ||
return new PersistentVolumeClaimSpecBuilder() | ||
.withAccessModes("ReadWriteOnce") | ||
.withResources(new ResourceRequirementsBuilder() | ||
.addToRequests("storage", new Quantity(cr.getSpec().getStorageSpec().getFilesystemSpec().getSize())) | ||
.build() | ||
) | ||
.build(); | ||
} | ||
|
||
public static String getPersistentVolumeClaimName(Ublhub cr) { | ||
return cr.getMetadata().getName() + "-filesystem" + Constants.PVC_SUFFIX; | ||
} | ||
|
||
public static boolean isTlsConfigured(Ublhub cr) { | ||
var tlsSecret = CRDUtils.getValueFromSubSpec(cr.getSpec().getHttpSpec(), UblhubSpec.HttpSpec::getTlsSecret); | ||
return tlsSecret.isPresent() && !tlsSecret.get().trim().isEmpty(); | ||
} | ||
|
||
} |
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
Oops, something went wrong.