-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Kind extension to generate manifests (#1072)
* Fix Kind extension to generate manifests Plus, add the Kind page into the dekorate site. This pull request is related to quarkusio/quarkus#28078 * Include ports and service type into the kind annotations * changes in documentation
- Loading branch information
Showing
20 changed files
with
583 additions
and
36 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
44 changes: 44 additions & 0 deletions
44
...annotations/src/main/java/io/dekorate/kind/decorator/ApplyPortToKindServiceDecorator.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,44 @@ | ||
/** | ||
* Copyright 2018 The original authors. | ||
* | ||
* 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.dekorate.kind.decorator; | ||
|
||
import io.dekorate.kubernetes.config.Port; | ||
import io.dekorate.kubernetes.decorator.NamedResourceDecorator; | ||
import io.dekorate.utils.Ports; | ||
import io.fabric8.kubernetes.api.model.ObjectMeta; | ||
import io.fabric8.kubernetes.api.model.ServicePortFluent; | ||
|
||
public class ApplyPortToKindServiceDecorator extends NamedResourceDecorator<ServicePortFluent> { | ||
|
||
private final Port port; | ||
|
||
public ApplyPortToKindServiceDecorator(String name, Port port) { | ||
super(name); | ||
this.port = port; | ||
} | ||
|
||
@Override | ||
public void andThenVisit(ServicePortFluent servicePort, ObjectMeta resourceMeta) { | ||
if (port.getNodePort() > 0) { | ||
servicePort.withNodePort(port.getNodePort()); | ||
} else { | ||
servicePort.withNodePort(Ports.calculateNodePort(getName(), port)); | ||
} | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
...ions/src/main/java/io/dekorate/kind/decorator/ApplyServiceTypeToKindServiceDecorator.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,38 @@ | ||
/** | ||
* Copyright 2018 The original authors. | ||
* | ||
* 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.dekorate.kind.decorator; | ||
|
||
import io.dekorate.kind.config.KindConfig; | ||
import io.dekorate.kubernetes.decorator.NamedResourceDecorator; | ||
import io.fabric8.kubernetes.api.model.ObjectMeta; | ||
import io.fabric8.kubernetes.api.model.ServiceSpecFluent; | ||
|
||
public class ApplyServiceTypeToKindServiceDecorator extends NamedResourceDecorator<ServiceSpecFluent> { | ||
|
||
private final KindConfig config; | ||
|
||
public ApplyServiceTypeToKindServiceDecorator(String name, KindConfig config) { | ||
super(name); | ||
this.config = config; | ||
} | ||
|
||
@Override | ||
public void andThenVisit(ServiceSpecFluent spec, ObjectMeta resourceMeta) { | ||
spec.withType(config.getServiceType() != null ? config.getServiceType().name() : "NodePort"); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...tions/kind-annotations/src/main/java/io/dekorate/kind/manifest/KindManifestGenerator.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,65 @@ | ||
package io.dekorate.kind.manifest; | ||
|
||
import java.util.Arrays; | ||
|
||
import io.dekorate.ConfigurationRegistry; | ||
import io.dekorate.ResourceRegistry; | ||
import io.dekorate.kind.config.KindConfig; | ||
import io.dekorate.kind.decorator.ApplyPortToKindServiceDecorator; | ||
import io.dekorate.kind.decorator.ApplyServiceTypeToKindServiceDecorator; | ||
import io.dekorate.kubernetes.config.KubernetesConfig; | ||
import io.dekorate.kubernetes.decorator.AddServiceResourceDecorator; | ||
import io.dekorate.kubernetes.decorator.ApplyImagePullPolicyDecorator; | ||
import io.dekorate.kubernetes.manifest.KubernetesManifestGenerator; | ||
|
||
public class KindManifestGenerator extends KubernetesManifestGenerator { | ||
|
||
private static final String KIND = "kind"; | ||
|
||
public KindManifestGenerator() { | ||
this(new ResourceRegistry(), new ConfigurationRegistry()); | ||
} | ||
|
||
public KindManifestGenerator(ResourceRegistry resourceRegistry, ConfigurationRegistry configurationRegistry) { | ||
super(resourceRegistry, configurationRegistry); | ||
} | ||
|
||
@Override | ||
public int order() { | ||
return 400; | ||
} | ||
|
||
@Override | ||
public String getKey() { | ||
return KIND; | ||
} | ||
|
||
@Override | ||
protected void addDecorators(String group, KubernetesConfig config) { | ||
super.addDecorators(group, config); | ||
if (config.getPorts().length > 0) { | ||
resourceRegistry.decorate(group, new AddServiceResourceDecorator(config)); | ||
} | ||
} | ||
|
||
@Override | ||
public void generate(KubernetesConfig kubernetesConfig) { | ||
initializeRegistry(kubernetesConfig); | ||
addDecorators(KIND, kubernetesConfig); | ||
|
||
configurationRegistry.get(KindConfig.class).ifPresent(c -> { | ||
resourceRegistry.decorate(KIND, new ApplyImagePullPolicyDecorator(kubernetesConfig.getName(), c.getImagePullPolicy())); | ||
resourceRegistry.decorate(KIND, new ApplyServiceTypeToKindServiceDecorator(kubernetesConfig.getName(), c)); | ||
// Check if MinikubeConfig defines port, else fallback to KubernetesConfig | ||
if (c.getPorts().length > 0) { | ||
Arrays.stream(c.getPorts()).forEach(p -> { | ||
resourceRegistry.decorate(KIND, new ApplyPortToKindServiceDecorator(kubernetesConfig.getName(), p)); | ||
}); | ||
} else { | ||
Arrays.stream(kubernetesConfig.getPorts()).forEach(p -> { | ||
resourceRegistry.decorate(KIND, new ApplyPortToKindServiceDecorator(kubernetesConfig.getName(), p)); | ||
}); | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.