Skip to content

Commit

Permalink
refactor: openshift-model-monitoring generated from OpenAPI schemas
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Nuri <[email protected]>
  • Loading branch information
manusa committed Oct 2, 2024
1 parent 6452f8c commit 68fc9b4
Show file tree
Hide file tree
Showing 147 changed files with 33,690 additions and 1,294 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ openapi-generate-java-classes:
cd kubernetes-model-generator/openshift-model-autoscaling && mvn -Pgenerate clean install
cd kubernetes-model-generator/openshift-model-machine && mvn -Pgenerate clean install
cd kubernetes-model-generator/openshift-model-machineconfiguration && mvn -Pgenerate clean install
cd kubernetes-model-generator/openshift-model-monitoring && mvn -Pgenerate clean install

# Legacy generation of the model: TODO: remove
.PHONY: generate-model-legacy
Expand Down
1 change: 0 additions & 1 deletion kubernetes-model-generator/generateModel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ ABSOLUTE_BASEDIR=$(realpath "$BASEDIR")
declare -a modules=(
"openshift-model-hive"
"openshift-model-installer"
"openshift-model-monitoring"
"openshift-model-tuned"
"openshift-model-whereabouts"
"openshift-model-storageversionmigrator"
Expand Down
9 changes: 5 additions & 4 deletions kubernetes-model-generator/kubernetes-model-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,23 @@
io.fabric8.kubernetes.api.model.storage,
io.fabric8.kubernetes.api.model.storage.v1beta1,
io.fabric8.openshift.api.model;resolution:=optional,
io.fabric8.openshift.api.model.clusterautoscaling.v1;resolution:=optional,
io.fabric8.openshift.api.model.clusterautoscaling.v1beta1;resolution:=optional,
io.fabric8.openshift.api.model.autoscaling.v1;resolution:=optional,
io.fabric8.openshift.api.model.autoscaling.v1beta1;resolution:=optional,
io.fabric8.openshift.api.model.runtime;resolution:=optional,
io.fabric8.openshift.api.model.console.v1;resolution:=optional,
io.fabric8.openshift.api.model.console.v1alpha1;resolution:=optional,
io.fabric8.openshift.api.model.machine.v1beta1;resolution:=optional,
io.fabric8.openshift.api.model.machineconfiguration.v1;resolution:=optional,
io.fabric8.openshift.api.model.monitoring.v1;resolution:=optional,
io.fabric8.openshift.api.model.monitoring.v1alpha1;resolution:=optional,
io.fabric8.openshift.api.model.monitoring.v1beta1;resolution:=optional,
io.fabric8.openshift.api.model.operator;resolution:=optional,
io.fabric8.openshift.api.model.operator.v1;resolution:=optional,
io.fabric8.openshift.api.model.operator.v1alpha1;resolution:=optional,
io.fabric8.openshift.api.model.operator.controlplane.v1alpha1;resolution:=optional,
io.fabric8.openshift.api.model.operatorhub.manifests;resolution:=optional,
io.fabric8.openshift.api.model.operatorhub.v1;resolution:=optional,
io.fabric8.openshift.api.model.operatorhub.v1alpha1;resolution:=optional,
io.fabric8.openshift.api.model.machineconfig.v1;resolution:=optional,
io.fabric8.openshift.api.model.machine.v1beta1;resolution:=optional,
io.fabric8.openshift.api.model.tuned.v1;resolution:=optional,
io.fabric8.openshift.api.model.whereabouts.v1alpha1;resolution:=optional,
io.fabric8.openshift.api.model.storageversionmigrator.v1alpha1;resolution:=optional,
Expand Down
7 changes: 4 additions & 3 deletions kubernetes-model-generator/openapi/generator/cmd/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ import (
"github.com/fabric8io/kubernetes-client/kubernetes-model-generator/openapi/generator/pkg/openshift"
"github.com/fabric8io/kubernetes-client/kubernetes-model-generator/openapi/generator/pkg/parser"
//openshiftbaremetaloperatorv1alpha1 "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1"
openshiftconfigv1 "github.com/openshift/api/config/v1"
openshiftcloudcredentialoperatorv1 "github.com/openshift/cloud-credential-operator/pkg/apis/cloudcredential/v1"
openshiftclusternetworkoperatorv1 "github.com/openshift/cluster-network-operator/pkg/apis/network/v1"
operatorframeworkv1 "github.com/operator-framework/api/pkg/operators/v1"
operatorframeworkv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
olm "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/apis/operators/v1"
"time"

openshiftconfigv1 "github.com/openshift/api/config/v1"
prometheusoperatorv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
"github.com/spf13/cobra"
"k8s.io/kube-openapi/pkg/common"
"k8s.io/kube-openapi/pkg/validation/spec"
"time"
)

var openApi = &cobra.Command{
Expand All @@ -57,6 +57,7 @@ var openApiRun = func(cobraCmd *cobra.Command, args []string) {
openshiftclusternetworkoperatorv1.GroupVersion.String(),
openshiftcloudcredentialoperatorv1.GroupVersion.String(),
olm.SchemeGroupVersion.String(),
prometheusoperatorv1.SchemeGroupVersion.String(),
})
var targetDirectory string
if len(args) > 0 {
Expand Down
9 changes: 6 additions & 3 deletions kubernetes-model-generator/openapi/generator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ replace github.com/operator-framework/api => github.com/marcnuri-forks/operator-
// TODO: WIP while this gets merged or fixed https://github.com/operator-framework/operator-lifecycle-manager/pull/3406
replace github.com/operator-framework/operator-lifecycle-manager => github.com/marcnuri-forks/operator-lifecycle-manager v0.0.0-20241002090802-7539192fbf96

require github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.77.1

require (
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
Expand All @@ -44,6 +46,7 @@ require (
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-test/deep v1.1.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
Expand All @@ -67,10 +70,10 @@ require (
github.com/spf13/pflag v1.0.6-0.20210604193023-d5e0c0615ace // indirect
github.com/stoewer/go-strcase v1.3.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/term v0.24.0 // indirect
Expand All @@ -85,7 +88,7 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
k8s.io/utils v0.0.0-20240902221715-702e33fdd3c3 // indirect
sigs.k8s.io/controller-runtime v0.19.0 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/kyaml v0.17.1 // indirect
Expand Down
18 changes: 10 additions & 8 deletions kubernetes-model-generator/openapi/generator/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+Gr
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/go-test/deep v1.1.1 h1:0r/53hagsehfO4bzD2Pgr/+RgHqhmf+k1Bpse2cTu1U=
github.com/go-test/deep v1.1.1/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-migrate/migrate/v4 v4.17.1 h1:4zQ6iqL6t6AiItphxJctQb3cFqWiSpMnX7wLTPnnYO4=
Expand Down Expand Up @@ -213,6 +213,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.77.1 h1:XGoEXT6WTTihO+MD8MAao+YaQIH905HbK0WK2lyo28k=
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.77.1/go.mod h1:D0KY8md81DQKdaR/cXwnhoWB3MYYyc/UjvqE8GFkIvA=
github.com/prometheus/client_golang v1.20.4 h1:Tgh3Yr67PaOv/uTqloMsCEdeuFTatm5zIq5+qNN23vI=
github.com/prometheus/client_golang v1.20.4/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
Expand Down Expand Up @@ -300,8 +302,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk=
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
Expand All @@ -312,8 +314,8 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA=
golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -385,8 +387,8 @@ k8s.io/kube-openapi v0.0.0-20240903163716-9e1beecbcb38 h1:1dWzkmJrrprYvjGwh9kEUx
k8s.io/kube-openapi v0.0.0-20240903163716-9e1beecbcb38/go.mod h1:coRQXBK9NxO98XUv3ZD6AK3xzHCxV6+b7lrquKwaKzA=
k8s.io/metrics v0.30.2 h1:zj4kIPTCfEbY0RHEogpA7QtlItU7xaO11+Gz1zVDxlc=
k8s.io/metrics v0.30.2/go.mod h1:GpoO5XTy/g8CclVLtgA5WTrr2Cy5vCsqr5Xa/0ETWIk=
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 h1:pUdcCO1Lk/tbT5ztQWOBi5HBgbBP1J8+AsQnQCKsi8A=
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
k8s.io/utils v0.0.0-20240902221715-702e33fdd3c3 h1:b2FmK8YH+QEwq/Sy2uAEhmqL5nPfGYbJOcaqjeYYZoA=
k8s.io/utils v0.0.0-20240902221715-702e33fdd3c3/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3 h1:2770sDpzrjjsAtVhSeUFseziht227YAWYHLGNM8QPwY=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3/go.mod h1:Ve9uj1L+deCXFrPOk1LpFXqTg7LCFzFso6PA48q/XZw=
sigs.k8s.io/controller-runtime v0.19.0 h1:nWVM7aq+Il2ABxwiCizrVDSlmDcshi9llbaFbC0ji/Q=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ var PackagePatterns = []string{
"github.com/openshift/api/.../v...",
// CRDs don't provide info for reused types
//"github.com/metal3-io/baremetal-operator/apis/metal3.io/v...",
"github.com/operator-framework/api/pkg/operators/v...",
"github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/apis/operators/v...",
"github.com/openshift/cluster-network-operator/pkg/apis/.../v...",
"github.com/openshift/cloud-credential-operator/pkg/apis/.../v...",
"github.com/operator-framework/api/pkg/operators/v...",
"github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/apis/operators/v...",
"github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v...",
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
operatorframeworkv1 "github.com/operator-framework/api/pkg/operators/v1"
operatorframeworkv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
olm "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/apis/operators/v1"
prometheusoperatorv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
"k8s.io/kube-openapi/cmd/openapi-gen/args"
"time"
)
Expand All @@ -42,6 +43,7 @@ func main() {
openshiftclusternetworkoperatorv1.GroupVersion.String(),
openshiftcloudcredentialoperatorv1.GroupVersion.String(),
olm.SchemeGroupVersion.String(),
prometheusoperatorv1.SchemeGroupVersion.String(),
})
err := (&openapi.GoGenerator{
Args: args.Args{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ private Map<String, List<String>> buildableReferences(TemplateContext templateCo
if (templateContext.getClassSimpleName().equals(referenceSimpleClass)) {
return r;
}
// Don't add import if there's an import for a class with the same name e.g. ObjectReference in k8s core and monitoring
if (!templateContext.getImports().contains(r) && templateContext.hasSimpleClassName(referenceSimpleClass)) {
return r;
}
templateContext.addImport(r);
return referenceSimpleClass;
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,23 @@ public class SchemaUtils {

private static final Set<String> PROTECTED_WORDS = new HashSet<>(Arrays.asList(
"abstract",
"class",
"continue",
"default",
"enum",
"class",
"for",
"import",
"int",
"package",
"private",
"for",
"return",
"package"));
"short",
"static"));

private static final Map<String, String> MAPPED_WORDS = new LinkedHashMap<>();
static {
MAPPED_WORDS.put("class", "className");
}

private final GeneratorSettings settings;

Expand Down Expand Up @@ -356,15 +363,20 @@ public static String removeDashes(String variable) {

public static String sanitizeVariable(String variable) {
final String sanitized = uncapitalize(removeDashes(variable));
return PROTECTED_WORDS.contains(sanitized) ? "_" + sanitized : sanitized;
final String mapped = MAPPED_WORDS.getOrDefault(sanitized, sanitized);
return PROTECTED_WORDS.contains(mapped) ? "_" + mapped : mapped;
}

public static String getterName(String variable) {
return "get".concat(capitalize(removeDashes(variable)));
final String property = removeDashes(variable);
final String mapped = MAPPED_WORDS.getOrDefault(property, property);
return "get".concat(capitalize(mapped));
}

public static String setterName(String variable) {
return "set".concat(capitalize(removeDashes(variable)));
final String property = removeDashes(variable);
final String mapped = MAPPED_WORDS.getOrDefault(property, property);
return "set".concat(capitalize(mapped));
}

public Map<String, Schema<?>> extractComponentSchemas() {
Expand Down
Loading

0 comments on commit 68fc9b4

Please sign in to comment.