8000 ⚠️ Change FybrikStorageAccount CRD by shlomitk1 · Pull Request #1855 · fybrik/fybrik · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

⚠️ Change FybrikStorageAccount CRD #1855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ spec:
singular: fybrikstorageaccount
scope: Namespaced
versions:
- name: v1beta1
- deprecated: true
deprecationWarning: v1beta1 version of fybrikstorageaccount is deprecated and will be removed soon, please use v1beta2 version instead
name: v1beta1
schema:
openAPIV3Schema:
description: FybrikStorageAccount defines a storage account used for copying data. Only S3 based storage is supported. It contains endpoint, region and a reference to the credentials a Owner of the asset is responsible to store the credentials
Expand Down Expand Up @@ -54,6 +56,49 @@ spec:
- spec
type: object
served: true
storage: false
- name: v1beta2
schema:
openAPIV3Schema:
description: FybrikStorageAccount is a storage account Fybrik uses to dynamically allocate space for datasets whose creation or copy it orchestrates.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: FybrikStorageAccountSpec defines the desired state of FybrikStorageAccount
properties:
geography:
description: Storage geography
type: string
id:
description: Identification of a storage account
type: string
secretRef:
description: A name of k8s secret deployed in the control plane.
type: string
type:
description: Type of the storage, e.g., s3
type: string
required:
- geography
- id
- secretRef
- type
type: object
x-kubernetes-preserve-unknown-fields: true
status:
description: FybrikStorageAccountStatus defines the observed state of FybrikStorageAccount
type: object
required:
- spec
type: object
served: true
storage: true
status:
acceptedNames:
Expand Down
2 changes: 1 addition & 1 deletion manager/apis/app/v1beta1/fybrikstorageaccount_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type FybrikStorageAccountStatus struct {
// It contains endpoint, region and a reference to the credentials a
// Owner of the asset is responsible to store the credentials
// +kubebuilder:object:root=true
// +kubebuilder:storageversion
// +kubebuilder:deprecatedversion:warning="v1beta1 version of fybrikstorageaccount is deprecated and will be removed soon, please use v1beta2 version instead"
type FybrikStorageAccount struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
28 changes: 28 additions & 0 deletions manager/apis/app/v1beta2/decode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2020 IBM Corp.
// SPDX-License-Identifier: Apache-2.0

package v1beta2

import (
"encoding/json"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/yaml"
)

func (o *FybrikStorageAccount) DecodeYaml(bytes []byte) error {
if err := yaml.Unmarshal(bytes, o); err != nil {
return err
}
// get additional properties
object := &unstructured.Unstructured{}
if err := yaml.Unmarshal(bytes, &object); err != nil {
return err
}
spec := object.UnstructuredContent()["spec"]
specData, err := json.Marshal(spec)
if err != nil {
return err
}
return o.Spec.UnmarshalJSON(specData)
}
104 changes: 104 additions & 0 deletions manager/apis/app/v1beta2/fybrikstorageaccount_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Copyright 2020 IBM Corp.
// SPDX-License-Identifier: Apache-2.0

package v1beta2

import (
"encoding/json"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"fybrik.io/fybrik/pkg/model/taxonomy"
"fybrik.io/fybrik/pkg/serde"
)

const typeKey = "type"
const idKey = "id"
const geographyKey = "geography"
const secretRefKey = "secretRef"

// FybrikStorageAccountSpec defines the desired state of FybrikStorageAccount
// +kubebuilder:pruning:PreserveUnknownFields
type FybrikStorageAccountSpec struct {
// Identification of a storage account
// +required
ID string `json:"id"`
// +required
// A name of k8s secret deployed in the control plane.
SecretRef string `json:"secretRef"`
// +required
// Type of the storage, e.g., s3
Type taxonomy.ConnectionType `json:"type"`
// +required
// Storage geography
Geography taxonomy.ProcessingLocation `json:"geography"`
// Additional storage properties, specific to the storage type
AdditionalProperties serde.Properties `json:"-"`
}

// FybrikStorageAccountStatus defines the observed state of FybrikStorageAccount
type FybrikStorageAccountStatus struct {
}

// FybrikStorageAccount is a storage account Fybrik uses to dynamically allocate space
// for datasets whose creation or copy it orchestrates.
// +kubebuilder:object:root=true
// +kubebuilder:storageversion
type FybrikStorageAccount struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

// +required
Spec FybrikStorageAccountSpec `json:"spec"`
Status FybrikStorageAccountStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// FybrikStorageAccountList contains a list of FybrikStorageAccount
type FybrikStorageAccountList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []FybrikStorageAccount `json:"items"`
}

func init() {
SchemeBuilder.Register(&FybrikStorageAccount{}, &FybrikStorageAccountList{})
}

func (o FybrikStorageAccountSpec) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{
idKey: o.ID,
secretRefKey: o.SecretRef,
typeKey: o.Type,
geographyKey: o.Geography,
}
for key, value := range o.AdditionalProperties.Items {
toSerialize[key] = value
}

return json.Marshal(toSerialize)
}

func (o *FybrikStorageAccountSpec) UnmarshalJSON(bytes []byte) (err error) {
items := make(map[string]interface{})
if err = json.Unmarshal(bytes, &items); err == nil {
o.ID = items[idKey].(string)
o.SecretRef = items[secretRefKey].(string)
delete(items, idKey)
delete(items, secretRefKey)
if val, ok := items[typeKey]; ok {
o.Type = taxonomy.ConnectionType(val.(string))
delete(items, typeKey)
}
if val, ok := items[geographyKey]; ok {
o.Geography = taxonomy.ProcessingLocation(val.(string))
delete(items, geographyKey)
}
if len(items) == 0 {
items = nil
}
o.AdditionalProperties = serde.Properties{Items: items}
}
return err
}
23 changes: 23 additions & 0 deletions manager/apis/app/v1beta2/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2020 IBM Corp.
// SPDX-License-Identifier: Apache-2.0

// Package v1beta1 contains API Schema definitions for the api v1beta1 API group
// +kubebuilder:object:generate=true
// +groupName=app.fybrik.io
package v1beta2

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "app.fybrik.io", Version: "v1beta2"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
102 changes: 102 additions & 0 deletions manager/apis/app/v1beta2/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion manager/controllers/app/data_catalog_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (r *FybrikApplicationReconciler) RegisterAsset(assetID string, catalogID st
} else {
resourceMetadata.Name = assetID
}
// Update the Geography with the allocated storage region
// Update the Geography with the allocated storage geography
if info.ResourceMetadata != nil {
resourceMetadata.Geography = info.ResourceMetadata.Geography
}
Expand Down
Loading
0