-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[linting] adding checks for latest usage, warning for not using anti …
…affinity, checks for liveness and readyness presence
- Loading branch information
1 parent
44a2623
commit ce61f41
Showing
13 changed files
with
700 additions
and
51 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
54 changes: 54 additions & 0 deletions
54
bundlebee-core/src/main/java/io/yupiik/bundlebee/core/command/impl/ListLintCommand.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,54 @@ | ||
/* | ||
* Copyright (c) 2021-2023 - Yupiik SAS - https://www.yupiik.com | ||
* 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.yupiik.bundlebee.core.command.impl; | ||
|
||
import io.yupiik.bundlebee.core.command.Executable; | ||
import io.yupiik.bundlebee.core.command.impl.lint.LintingCheck; | ||
import lombok.extern.java.Log; | ||
|
||
import javax.enterprise.context.Dependent; | ||
import javax.enterprise.inject.Any; | ||
import javax.enterprise.inject.Instance; | ||
import javax.inject.Inject; | ||
import java.util.concurrent.CompletionStage; | ||
|
||
import static java.util.concurrent.CompletableFuture.completedFuture; | ||
import static java.util.stream.Collectors.joining; | ||
|
||
@Log | ||
@Dependent | ||
public class ListLintCommand implements Executable { | ||
@Inject | ||
@Any | ||
private Instance<LintingCheck> checks; | ||
|
||
@Override | ||
public String name() { | ||
return "list-lint-rules"; | ||
} | ||
|
||
@Override | ||
public String description() { | ||
return "List available linting rules (ease exclusions for ex)."; | ||
} | ||
|
||
@Override | ||
public CompletionStage<?> execute() { | ||
return completedFuture(checks.stream() | ||
.map(c -> " *" + c.name()) | ||
.collect(joining("\n"))); | ||
} | ||
} |
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
53 changes: 53 additions & 0 deletions
53
...main/java/io/yupiik/bundlebee/core/command/impl/lint/builtin/ContainerValueValidator.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,53 @@ | ||
/* | ||
* Copyright (c) 2021-2023 - Yupiik SAS - https://www.yupiik.com | ||
* 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.yupiik.bundlebee.core.command.impl.lint.builtin; | ||
|
||
import io.yupiik.bundlebee.core.command.impl.lint.LintError; | ||
|
||
import javax.json.JsonObject; | ||
import javax.json.JsonValue; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
|
||
import static java.util.function.Function.identity; | ||
import static java.util.stream.Collectors.toMap; | ||
|
||
public abstract class ContainerValueValidator extends CheckValue { | ||
private static final Set<String> RUNNABLE_TYPES = Set.of("Deployment", "CronJob", "Pod", "Job"); | ||
private static final Map<String, String> RUNNABLE_CONTAINERS_POINTERS = Map.of( | ||
"Deployment", "/spec/template/spec/containers", | ||
"CronJob", "/spec/jobTemplate/template/spec/containers", | ||
"Job", "/spec/template/spec/containers", | ||
"Pod", "/spec/containers"); | ||
|
||
protected ContainerValueValidator() { | ||
super(RUNNABLE_TYPES, RUNNABLE_CONTAINERS_POINTERS, null); | ||
} | ||
|
||
protected ContainerValueValidator(final Set<String> types) { | ||
super(types, types.stream().collect(toMap(identity(), RUNNABLE_CONTAINERS_POINTERS::get)), null); | ||
} | ||
|
||
@Override | ||
protected Stream<LintError> doValidate(final LintableDescriptor descriptor, final JsonValue containers) { | ||
return containers.asJsonArray().stream() | ||
.map(JsonValue::asJsonObject) | ||
.flatMap(it -> validate(it, descriptor)); | ||
} | ||
|
||
protected abstract Stream<LintError> validate(final JsonObject container, final LintableDescriptor descriptor); | ||
} |
54 changes: 54 additions & 0 deletions
54
.../src/main/java/io/yupiik/bundlebee/core/command/impl/lint/builtin/LivenessProbeImage.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,54 @@ | ||
/* | ||
* Copyright (c) 2021-2023 - Yupiik SAS - https://www.yupiik.com | ||
* 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.yupiik.bundlebee.core.command.impl.lint.builtin; | ||
|
||
import io.yupiik.bundlebee.core.command.impl.lint.LintError; | ||
|
||
import javax.enterprise.context.Dependent; | ||
import javax.json.JsonObject; | ||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
|
||
@Dependent | ||
public class LivenessProbeImage extends ContainerValueValidator { | ||
public LivenessProbeImage() { | ||
super(Set.of("Deployment")); | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return "no-liveness-probe"; | ||
} | ||
|
||
@Override | ||
public String description() { | ||
return "Ensures a liveness probe is defined."; | ||
} | ||
|
||
@Override | ||
public String remediation() { | ||
return "Any container (from containers array) should have a liveness probe."; | ||
} | ||
|
||
@Override | ||
protected Stream<LintError> validate(final JsonObject container, final LintableDescriptor descriptor) { | ||
final var probe = container.getJsonObject("livenessProbe"); | ||
if (probe == null) { | ||
return Stream.of(new LintError(LintError.LintLevel.ERROR, "No liveness probe")); | ||
} | ||
return Stream.empty(); | ||
} | ||
} |
Oops, something went wrong.