Skip to content

Commit

Permalink
Add resource patches to API
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-demicev committed Oct 23, 2023
1 parent e20945c commit cf8fdca
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 8 deletions.
101 changes: 93 additions & 8 deletions api/v1alpha1/provider_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

apimachineryconversion "k8s.io/apimachinery/pkg/conversion"
"k8s.io/utils/pointer"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
ctrlconfigv1 "sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/conversion"

Expand All @@ -34,7 +35,19 @@ func (src *BootstrapProvider) ConvertTo(dstRaw conversion.Hub) error {
panic("expected to get an of object of type v1alpha2.BootstrapProvider")
}

return Convert_v1alpha1_BootstrapProvider_To_v1alpha2_BootstrapProvider(src, dst, nil)
if err := Convert_v1alpha1_BootstrapProvider_To_v1alpha2_BootstrapProvider(src, dst, nil); err != nil {
return err
}

// Manually restore data.
restored := &operatorv1.BootstrapProvider{}
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
return err
}

dst.Spec.ManifestPatches = restored.Spec.ManifestPatches

return nil
}

// ConvertFrom converts from the BootstrapProvider version (v1alpha2) to this version.
Expand All @@ -44,7 +57,16 @@ func (dst *BootstrapProvider) ConvertFrom(srcRaw conversion.Hub) error {
panic("expected to get an of object of type v1alpha2.BootstrapProvider")
}

return Convert_v1alpha2_BootstrapProvider_To_v1alpha1_BootstrapProvider(src, dst, nil)
if err := Convert_v1alpha2_BootstrapProvider_To_v1alpha1_BootstrapProvider(src, dst, nil); err != nil {
return err
}

// Preserve Hub data on down-conversion.
if err := utilconversion.MarshalData(src, dst); err != nil {
return err
}

return nil
}

// ConvertTo converts this BootstrapProviderList to the Hub version (v1alpha2).
Expand Down Expand Up @@ -74,7 +96,19 @@ func (src *ControlPlaneProvider) ConvertTo(dstRaw conversion.Hub) error {
panic("expected to get an of object of type v1alpha2.ControlPlaneProvider")
}

return Convert_v1alpha1_ControlPlaneProvider_To_v1alpha2_ControlPlaneProvider(src, dst, nil)
if err := Convert_v1alpha1_ControlPlaneProvider_To_v1alpha2_ControlPlaneProvider(src, dst, nil); err != nil {
return err
}

// Manually restore data.
restored := &operatorv1.ControlPlaneProvider{}
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
return err
}

dst.Spec.ManifestPatches = restored.Spec.ManifestPatches

return nil
}

// ConvertFrom converts from the ControlPlaneProvider version (v1alpha2) to this version.
Expand All @@ -84,7 +118,16 @@ func (dst *ControlPlaneProvider) ConvertFrom(srcRaw conversion.Hub) error {
panic("expected to get an of object of type v1alpha2.ControlPlaneProvider")
}

return Convert_v1alpha2_ControlPlaneProvider_To_v1alpha1_ControlPlaneProvider(src, dst, nil)
if err := Convert_v1alpha2_ControlPlaneProvider_To_v1alpha1_ControlPlaneProvider(src, dst, nil); err != nil {
return err
}

// Preserve Hub data on down-conversion.
if err := utilconversion.MarshalData(src, dst); err != nil {
return err
}

return nil
}

// ConvertTo converts this ControlPlaneProviderList to the Hub version (v1alpha2).
Expand Down Expand Up @@ -114,7 +157,19 @@ func (src *CoreProvider) ConvertTo(dstRaw conversion.Hub) error {
panic("expected to get an of object of type v1alpha2.CoreProvider")
}

return Convert_v1alpha1_CoreProvider_To_v1alpha2_CoreProvider(src, dst, nil)
if err := Convert_v1alpha1_CoreProvider_To_v1alpha2_CoreProvider(src, dst, nil); err != nil {
return err
}

// Manually restore data.
restored := &operatorv1.CoreProvider{}
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
return err
}

dst.Spec.ManifestPatches = restored.Spec.ManifestPatches

return nil
}

// ConvertFrom converts from the CoreProvider version (v1alpha2) to this version.
Expand All @@ -124,7 +179,16 @@ func (dst *CoreProvider) ConvertFrom(srcRaw conversion.Hub) error {
panic("expected to get an of object of type v1alpha2.CoreProvider")
}

return Convert_v1alpha2_CoreProvider_To_v1alpha1_CoreProvider(src, dst, nil)
if err := Convert_v1alpha2_CoreProvider_To_v1alpha1_CoreProvider(src, dst, nil); err != nil {
return err
}

// Preserve Hub data on down-conversion.
if err := utilconversion.MarshalData(src, dst); err != nil {
return err
}

return nil
}

// ConvertTo converts this CoreProviderList to the Hub version (v1alpha2).
Expand Down Expand Up @@ -154,7 +218,19 @@ func (src *InfrastructureProvider) ConvertTo(dstRaw conversion.Hub) error {
panic("expected to get an of object of type v1alpha2.InfrastructureProvider")
}

return Convert_v1alpha1_InfrastructureProvider_To_v1alpha2_InfrastructureProvider(src, dst, nil)
if err := Convert_v1alpha1_InfrastructureProvider_To_v1alpha2_InfrastructureProvider(src, dst, nil); err != nil {
return err
}

// Manually restore data.
restored := &operatorv1.InfrastructureProvider{}
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
return err
}

dst.Spec.ManifestPatches = restored.Spec.ManifestPatches

return nil
}

// ConvertFrom converts from the InfrastructureProvider version (v1alpha2) to this version.
Expand All @@ -164,7 +240,16 @@ func (dst *InfrastructureProvider) ConvertFrom(srcRaw conversion.Hub) error {
panic("expected to get an of object of type v1alpha2.InfrastructureProvider")
}

return Convert_v1alpha2_InfrastructureProvider_To_v1alpha1_InfrastructureProvider(src, dst, nil)
if err := Convert_v1alpha2_InfrastructureProvider_To_v1alpha1_InfrastructureProvider(src, dst, nil); err != nil {
return err
}

// Preserve Hub data on down-conversion.
if err := utilconversion.MarshalData(src, dst); err != nil {
return err
}

return nil
}

// ConvertTo converts this InfrastructureProviderList to the Hub version (v1alpha2).
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/zz_generated.conversion.go

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

8 changes: 8 additions & 0 deletions api/v1alpha2/provider_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ type ProviderSpec struct {
// namespace of the provider will be used. There is no validation of the yaml content inside the configmap.
// +optional
AdditionalManifestsRef *ConfigmapReference `json:"additionalManifests,omitempty"`

// ManifestPatches are applied to rendered provider manifests to customize the
// provider manifests. Patches are applied in the order they are specified.
// The `kind` field must match the target object, and
// if `apiVersion` is specified it will only be applied to matching objects.
// This should be an inline yaml blob-string https://datatracker.ietf.org/doc/html/rfc7396
// +optional
ManifestPatches []string `json:"manifestPatches,omitempty"`
}

// ConfigmapReference contains enough information to locate the configmap.
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha2/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -1466,6 +1466,15 @@ spec:
type: integer
type: object
type: object
manifestPatches:
description: ManifestPatches are applied to rendered provider manifests
to customize the provider manifests. Patches are applied in the
order they are specified. The `kind` field must match the target
object, and if `apiVersion` is specified it will only be applied
to matching objects. This should be an inline yaml blob-string https://datatracker.ietf.org/doc/html/rfc7396
items:
type: string
type: array
version:
description: Version indicates the provider version.
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2995,6 +2995,15 @@ spec:
type: integer
type: object
type: object
manifestPatches:
description: ManifestPatches are applied to rendered provider manifests
to customize the provider manifests. Patches are applied in the
order they are specified. The `kind` field must match the target
object, and if `apiVersion` is specified it will only be applied
to matching objects. This should be an inline yaml blob-string https://datatracker.ietf.org/doc/html/rfc7396
items:
type: string
type: array
version:
description: Version indicates the provider version.
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2998,6 +2998,15 @@ spec:
type: integer
type: object
type: object
manifestPatches:
description: ManifestPatches are applied to rendered provider manifests
to customize the provider manifests. Patches are applied in the
order they are specified. The `kind` field must match the target
object, and if `apiVersion` is specified it will only be applied
to matching objects. This should be an inline yaml blob-string https://datatracker.ietf.org/doc/html/rfc7396
items:
type: string
type: array
version:
description: Version indicates the provider version.
type: string
Expand Down
9 changes: 9 additions & 0 deletions config/crd/bases/operator.cluster.x-k8s.io_coreproviders.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2995,6 +2995,15 @@ spec:
type: integer
type: object
type: object
manifestPatches:
description: ManifestPatches are applied to rendered provider manifests
to customize the provider manifests. Patches are applied in the
order they are specified. The `kind` field must match the target
object, and if `apiVersion` is specified it will only be applied
to matching objects. This should be an inline yaml blob-string https://datatracker.ietf.org/doc/html/rfc7396
items:
type: string
type: array
version:
description: Version indicates the provider version.
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2998,6 +2998,15 @@ spec:
type: integer
type: object
type: object
manifestPatches:
description: ManifestPatches are applied to rendered provider manifests
to customize the provider manifests. Patches are applied in the
order they are specified. The `kind` field must match the target
object, and if `apiVersion` is specified it will only be applied
to matching objects. This should be an inline yaml blob-string https://datatracker.ietf.org/doc/html/rfc7396
items:
type: string
type: array
version:
description: Version indicates the provider version.
type: string
Expand Down

0 comments on commit cf8fdca

Please sign in to comment.