Skip to content

Commit

Permalink
Use enum generator for ops types (#1031)
Browse files Browse the repository at this point in the history
Use https://github.com/abice/go-enum

```sh
go install github.com/abice/go-enum@latest

go generate ./apis/ops/...
```

Co-authored-by: ArnobKumarSaha <arnobkumarsaha00@gmail.com>
Signed-off-by: Tamal Saha <tamal@appscode.com>
  • Loading branch information
tamalsaha and ArnobKumarSaha committed Mar 16, 2023
1 parent d08e21e commit 3f1adae
Show file tree
Hide file tree
Showing 25 changed files with 1,261 additions and 217 deletions.
20 changes: 19 additions & 1 deletion Makefile
Expand Up @@ -259,11 +259,29 @@ gen-crd-protos-ui-v1alpha1:
--apimachinery-packages=-k8s.io/apimachinery/pkg/api/resource,-k8s.io/apimachinery/pkg/apis/meta/v1,-k8s.io/apimachinery/pkg/apis/meta/v1beta1,-k8s.io/apimachinery/pkg/runtime,-k8s.io/apimachinery/pkg/runtime/schema,-k8s.io/apimachinery/pkg/util/intstr \
--packages=+sigs.k8s.io/controller-runtime/pkg/scheme,-k8s.io/api/core/v1,-k8s.io/api/apps/v1,-k8s.io/api/autoscaling/v2beta2,-kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1,-kmodules.xyz/monitoring-agent-api/api/v1,-kmodules.xyz/objectstore-api/api/v1,-kmodules.xyz/offshoot-api/api/v1,-kmodules.xyz/client-go/api/v1,kubedb.dev/apimachinery/apis/ui/v1alpha1,kubedb.dev/apimachinery/apis/kubedb/v1alpha2

.PHONY: gen-enum
gen-enum:
@docker run \
-i \
--rm \
-u $$(id -u):$$(id -g) \
-v $$(pwd):/src \
-w /src \
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin \
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \
-v $$(pwd)/.go/cache:/.cache \
--env HTTP_PROXY=$(HTTP_PROXY) \
--env HTTPS_PROXY=$(HTTPS_PROXY) \
$(BUILD_IMAGE) \
/bin/bash -c " \
go generate ./apis/... \
"

.PHONY: manifests
manifests: gen-crds patch-crds label-crds

.PHONY: gen
gen: clientset manifests openapi #gen-crd-protos
gen: clientset gen-enum manifests openapi #gen-crd-protos

fmt: $(BUILD_DIRS)
@docker run \
Expand Down
21 changes: 2 additions & 19 deletions apis/ops/v1alpha1/elasticsearch_ops_types.go
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

//go:generate go-enum --mustparse --names --values
package v1alpha1

import (
Expand Down Expand Up @@ -79,27 +80,9 @@ type ElasticsearchOpsRequestSpec struct {
}

// +kubebuilder:validation:Enum=Upgrade;UpdateVersion;HorizontalScaling;VerticalScaling;VolumeExpansion;Restart;Reconfigure;ReconfigureTLS
// ENUM(Upgrade, UpdateVersion, HorizontalScaling, VerticalScaling, VolumeExpansion, Restart, Reconfigure, ReconfigureTLS)
type ElasticsearchOpsRequestType string

const (
// Deprecated. Use UpdateVersion
ElasticsearchOpsRequestTypeUpgrade ElasticsearchOpsRequestType = "Upgrade"
// used for UpdateVersion operation
ElasticsearchOpsRequestTypeUpdateVersion ElasticsearchOpsRequestType = "UpdateVersion"
// used for HorizontalScaling operation
ElasticsearchOpsRequestTypeHorizontalScaling ElasticsearchOpsRequestType = "HorizontalScaling"
// used for VerticalScaling operation
ElasticsearchOpsRequestTypeVerticalScaling ElasticsearchOpsRequestType = "VerticalScaling"
// used for VolumeExpansion operation
ElasticsearchOpsRequestTypeVolumeExpansion ElasticsearchOpsRequestType = "VolumeExpansion"
// used for Restart operation
ElasticsearchOpsRequestTypeRestart ElasticsearchOpsRequestType = "Restart"
// used for Reconfigure operation
ElasticsearchOpsRequestTypeReconfigure ElasticsearchOpsRequestType = "Reconfigure"
// used for ReconfigureTLS operation
ElasticsearchOpsRequestTypeReconfigureTLSs ElasticsearchOpsRequestType = "ReconfigureTLS"
)

// ElasticsearchReplicaReadinessCriteria is the criteria for checking readiness of an Elasticsearch database
type ElasticsearchReplicaReadinessCriteria struct{}

Expand Down
104 changes: 104 additions & 0 deletions apis/ops/v1alpha1/elasticsearch_ops_types_enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 2 additions & 17 deletions apis/ops/v1alpha1/etcd_ops_types.go
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

//go:generate go-enum --mustparse --names --values
package v1alpha1

import (
Expand Down Expand Up @@ -73,25 +74,9 @@ type EtcdOpsRequestSpec struct {
}

// +kubebuilder:validation:Enum=UpdateVersion;HorizontalScaling;VerticalScaling;VolumeExpansion;Restart;Reconfigure;ReconfigureTLS
// ENUM(UpdateVersion, HorizontalScaling, VerticalScaling, VolumeExpansion, Restart, Reconfigure, ReconfigureTLS)
type EtcdOpsRequestType string

const (
// used for UpdateVersion operation
EtcdOpsRequestTypeUpdateVersion EtcdOpsRequestType = "UpdateVersion"
// used for HorizontalScaling operation
EtcdOpsRequestTypeHorizontalScaling EtcdOpsRequestType = "HorizontalScaling"
// used for VerticalScaling operation
EtcdOpsRequestTypeVerticalScaling EtcdOpsRequestType = "VerticalScaling"
// used for VolumeExpansion operation
EtcdOpsRequestTypeVolumeExpansion EtcdOpsRequestType = "VolumeExpansion"
// used for Restart operation
EtcdOpsRequestTypeRestart EtcdOpsRequestType = "Restart"
// used for Reconfigure operation
EtcdOpsRequestTypeReconfigure EtcdOpsRequestType = "Reconfigure"
// used for ReconfigureTLS operation
EtcdOpsRequestTypeReconfigureTLSs EtcdOpsRequestType = "ReconfigureTLS"
)

// EtcdReplicaReadinessCriteria is the criteria for checking readiness of a Etcd pod
// after updating, horizontal scaling etc.
type EtcdReplicaReadinessCriteria struct{}
Expand Down
99 changes: 99 additions & 0 deletions apis/ops/v1alpha1/etcd_ops_types_enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 2 additions & 19 deletions apis/ops/v1alpha1/mariadb_ops_types.go
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

//go:generate go-enum --mustparse --names --values
package v1alpha1

import (
Expand Down Expand Up @@ -79,27 +80,9 @@ type MariaDBOpsRequestSpec struct {
}

// +kubebuilder:validation:Enum=Upgrade;UpdateVersion;HorizontalScaling;VerticalScaling;VolumeExpansion;Restart;Reconfigure;ReconfigureTLS
// ENUM(Upgrade, UpdateVersion, HorizontalScaling, VerticalScaling, VolumeExpansion, Restart, Reconfigure, ReconfigureTLS)
type MariaDBOpsRequestType string

const (
// Deprecated. Use UpdateVersion
MariaDBOpsRequestTypeUpgrade MariaDBOpsRequestType = "Upgrade"
// used for UpdateVersion operation
MariaDBOpsRequestTypeUpdateVersion MariaDBOpsRequestType = "UpdateVersion"
// used for HorizontalScaling operation
MariaDBOpsRequestTypeHorizontalScaling MariaDBOpsRequestType = "HorizontalScaling"
// used for VerticalScaling operation
MariaDBOpsRequestTypeVerticalScaling MariaDBOpsRequestType = "VerticalScaling"
// used for VolumeExpansion operation
MariaDBOpsRequestTypeVolumeExpansion MariaDBOpsRequestType = "VolumeExpansion"
// used for Restart operation
MariaDBOpsRequestTypeRestart MariaDBOpsRequestType = "Restart"
// used for Reconfigure operation
MariaDBOpsRequestTypeReconfigure MariaDBOpsRequestType = "Reconfigure"
// used for ReconfigureTLS operation
MariaDBOpsRequestTypeReconfigureTLSs MariaDBOpsRequestType = "ReconfigureTLS"
)

// MariaDBReplicaReadinessCriteria is the criteria for checking readiness of an MariaDB database
type MariaDBReplicaReadinessCriteria struct{}

Expand Down

0 comments on commit 3f1adae

Please sign in to comment.