Skip to content

Commit

Permalink
Merge pull request #74 from vshn/Opensearch/refactor-version
Browse files Browse the repository at this point in the history
on behalf of component-appcat refactor, I switched version variable n…
  • Loading branch information
TheBigLee authored Dec 16, 2022
2 parents 99044d7 + 1e6d43d commit a3183b0
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 16 deletions.
6 changes: 3 additions & 3 deletions apis/exoscale/v1/opensearch_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ type OpenSearchParameters struct {
// +kubebuilder:validation:Required
// Zone is the datacenter identifier in which the instance runs in.
Zone Zone `json:"zone"`
// Version - supported versions are "1" and "2" (string)
Version string `json:"version,omitempty"`
// majorVersion - supported versions are "1" and "2" (string)
MajorVersion string `json:"majorVersion,omitempty"`
OpenSearchSettings runtime.RawExtension `json:"openSearchSettings,omitempty"`
}

Expand All @@ -31,7 +31,7 @@ type OpenSearchSpec struct {

// OpenSearchObservation are the observable fields of a OpenSearch.
type OpenSearchObservation struct {
Version string `json:"version,omitempty"`
MajorVersion string `json:"majorVersion,omitempty"`
// OpenSearchSettings contains additional OpenSearch settings as set by the provider.
OpenSearchSettings runtime.RawExtension `json:"openSearchSettings,omitempty"`

Expand Down
2 changes: 1 addition & 1 deletion generate_sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func newOpensearchSample() *exoscalev1.OpenSearch {
IPFilter: exoscalev1.IPFilter{"0.0.0.0/0"},
},
Zone: "ch-dk-2",
Version: "2",
MajorVersion: "2",
OpenSearchSettings: runtime.RawExtension{},
},
},
Expand Down
4 changes: 2 additions & 2 deletions operator/opensearchcontroller/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func (p *pipeline) Create(ctx context.Context, mg resource.Managed) (managed.Ext
},
OpensearchSettings: &settings,
TerminationProtection: &forProvider.TerminationProtection,
// Version can be only major: ['1','2']
Version: &forProvider.Version,
// majorVersion can be only major: ['1','2']
Version: &forProvider.MajorVersion,
}
resp, err := p.exo.CreateDbaasServiceOpensearchWithResponse(ctx, oapi.DbaasServiceName(openSearch.GetInstanceName()), body)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions operator/opensearchcontroller/observe.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ func isUpToDate(current, external *exoscalev1.OpenSearchParameters, log logr.Log

func mapObservation(instance oapi.DbaasServiceOpensearch) (exoscalev1.OpenSearchObservation, error) {
observation := exoscalev1.OpenSearchObservation{
Version: pointer.StringDeref(instance.Version, ""),
NodeStates: mapper.ToNodeStates(instance.NodeStates),
MajorVersion: pointer.StringDeref(instance.Version, ""),
NodeStates: mapper.ToNodeStates(instance.NodeStates),
}

settings, err := mapper.ToRawExtension(instance.OpensearchSettings)
Expand Down
4 changes: 2 additions & 2 deletions operator/opensearchcontroller/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (v *Validator) validateSettings(obj exoscalev1.OpenSearchParameters) error

func (v *Validator) validateVersion(obj exoscalev1.OpenSearchParameters) error {
// opensearch accepts only major version as a string
switch obj.Version {
switch obj.MajorVersion {
case "1":
break
case "2":
Expand Down Expand Up @@ -114,7 +114,7 @@ func (v *Validator) compareZone(old, new *exoscalev1.OpenSearch) error {
}

func (v *Validator) compareVersion(old, new *exoscalev1.OpenSearch) error {
return webhook.ValidateVersion(old.Status.AtProvider.Version, old.Spec.ForProvider.Version, new.Spec.ForProvider.Version)
return webhook.ValidateVersion(old.Status.AtProvider.MajorVersion, old.Spec.ForProvider.MajorVersion, new.Spec.ForProvider.MajorVersion)
}

func (v *Validator) isCreated(obj *exoscalev1.OpenSearch) bool {
Expand Down
11 changes: 6 additions & 5 deletions package/crds/exoscale.crossplane.io_opensearches.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ spec:
pattern: ^([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$
type: string
type: object
majorVersion:
description: majorVersion - supported versions are "1" and "2"
(string)
type: string
openSearchSettings:
type: object
x-kubernetes-preserve-unknown-fields: true
Expand All @@ -125,9 +129,6 @@ spec:
description: TerminationProtection protects against termination
and powering off.
type: boolean
version:
description: Version - supported versions are "1" and "2" (string)
type: string
zone:
description: Zone is the datacenter identifier in which the instance
runs in.
Expand Down Expand Up @@ -353,6 +354,8 @@ spec:
pattern: ^([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$
type: string
type: object
majorVersion:
type: string
nodeStates:
description: State of individual service nodes
items:
Expand Down Expand Up @@ -404,8 +407,6 @@ spec:
description: TerminationProtection protects against termination
and powering off.
type: boolean
version:
type: string
required:
- maintenance
type: object
Expand Down
2 changes: 1 addition & 1 deletion samples/exoscale.crossplane.io_opensearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ spec:
maintenance:
dayOfWeek: monday
timeOfDay: "12:01:55"
majorVersion: "2"
openSearchSettings: null
size:
plan: hobbyist-2
version: "2"
zone: ch-dk-2
providerConfigRef:
name: provider-config
Expand Down

0 comments on commit a3183b0

Please sign in to comment.