Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
meshuga committed Sep 13, 2024
1 parent 95ebe75 commit a674cfc
Show file tree
Hide file tree
Showing 9 changed files with 5 additions and 101 deletions.
13 changes: 0 additions & 13 deletions pkg/apis/hykube/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,8 @@ type ProviderList struct {
Items []Provider
}

// ReferenceType defines the type of object reference.
type ReferenceType string

const (
// ProviderReferenceType is used for Provider references.
ProviderReferenceType = ReferenceType("Provider")
)

// ProviderSpec is the specification of a Provider.
type ProviderSpec struct {
// A name of another provider. TODO: is it needed??
ProviderReference string
// The reference type.
ReferenceType ReferenceType

DownloadName string
Version *string
DownloadUrl *string
Expand Down
15 changes: 0 additions & 15 deletions pkg/apis/hykube/v1alpha1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ func Convert_v1alpha1_ProviderSpec_To_hykube_ProviderSpec(in *ProviderSpec, out
return err
}

if in.ReferenceType != nil {
// assume that ReferenceType is defaulted
switch *in.ReferenceType {
case ProviderReferenceType:
out.ReferenceType = hykube.ProviderReferenceType
out.ProviderReference = in.Reference
}
}
return nil
}

Expand All @@ -40,12 +32,5 @@ func Convert_hykube_ProviderSpec_To_v1alpha1_ProviderSpec(in *hykube.ProviderSpe
return err
}

switch in.ReferenceType {
case hykube.ProviderReferenceType:
t := ProviderReferenceType
out.ReferenceType = &t
out.Reference = in.ProviderReference
}

return nil
}
5 changes: 1 addition & 4 deletions pkg/apis/hykube/v1alpha1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,5 @@ func addDefaultingFuncs(scheme *runtime.Scheme) error {

// SetDefaults_ProviderSpec sets defaults for Provider spec
func SetDefaults_ProviderSpec(obj *ProviderSpec) {
if (obj.ReferenceType == nil || len(*obj.ReferenceType) == 0) && len(obj.Reference) != 0 {
t := ProviderReferenceType
obj.ReferenceType = &t
}

}
12 changes: 0 additions & 12 deletions pkg/apis/hykube/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,7 @@ type ProviderList struct {
Items []Provider `json:"items" protobuf:"bytes,2,rep,name=items"`
}

type ReferenceType string

const (
ProviderReferenceType = ReferenceType("Provider")
FischerReferenceType = ReferenceType("Fischer")
)

type ProviderSpec struct {
// A name of another provider or fischer, depending on the reference type.
Reference string `json:"reference,omitempty" protobuf:"bytes,1,opt,name=reference"`
// The reference type, defaults to "Provider" if reference is set.
ReferenceType *ReferenceType `json:"referenceType,omitempty" protobuf:"bytes,2,opt,name=referenceType"`

DownloadName string `json:"downloadName" protobuf:"bytes,3,name=downloadName"`
Version *string `json:"version,omitempty" protobuf:"bytes,4,opt,name=version"`
DownloadUrl *string `json:"downloadUrl,omitempty" protobuf:"bytes,5,opt,name=downloadUrl"`
Expand Down
4 changes: 0 additions & 4 deletions pkg/apis/hykube/v1alpha1/zz_generated.conversion.go

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

5 changes: 0 additions & 5 deletions pkg/apis/hykube/v1alpha1/zz_generated.deepcopy.go

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

10 changes: 1 addition & 9 deletions pkg/apis/hykube/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,7 @@ func ValidateProviderSpec(s *hykube.ProviderSpec, fldPath *field.Path) field.Err
allErrs := field.ErrorList{}

if s.DownloadName == "" {
allErrs = append(allErrs, field.Invalid(fldPath.Child("downloadName"), s.ProviderReference, "cannot be empty"))
}

if len(s.ProviderReference) == 0 && s.ReferenceType == hykube.ProviderReferenceType {
allErrs = append(allErrs, field.Invalid(fldPath.Child("providerReference"), s.ProviderReference, "cannot be empty if referenceType is Provider"))
}

if len(s.ReferenceType) != 0 && s.ReferenceType != hykube.ProviderReferenceType {
allErrs = append(allErrs, field.Invalid(fldPath.Child("referenceType"), s.ReferenceType, "must be Provider"))
allErrs = append(allErrs, field.Invalid(fldPath.Child("downloadName"), s.DownloadName, "cannot be empty"))
}

return allErrs
Expand Down
28 changes: 3 additions & 25 deletions pkg/generated/applyconfiguration/hykube/v1alpha1/providerspec.go

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

14 changes: 0 additions & 14 deletions pkg/generated/openapi/zz_generated.openapi.go

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

0 comments on commit a674cfc

Please sign in to comment.