-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from wlan0/master
add storage class
- Loading branch information
Showing
20 changed files
with
522 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package converters | ||
|
||
import ( | ||
"k8s.io/api/core/v1" | ||
|
||
"github.com/koki/short/types" | ||
) | ||
|
||
func Convert_Kube_v1_ConfigMap_to_Koki_ConfigMap(kubeConfigMap *v1.ConfigMap) (*types.ConfigMapWrapper, error) { | ||
kokiConfigMapWrapper := &types.ConfigMapWrapper{} | ||
kokiConfigMap := types.ConfigMap{} | ||
|
||
kokiConfigMap.Name = kubeConfigMap.Name | ||
kokiConfigMap.Namespace = kubeConfigMap.Namespace | ||
kokiConfigMap.Version = kubeConfigMap.APIVersion | ||
kokiConfigMap.Cluster = kubeConfigMap.ClusterName | ||
kokiConfigMap.Labels = kubeConfigMap.Labels | ||
kokiConfigMap.Annotations = kubeConfigMap.Annotations | ||
|
||
kokiConfigMap.Data = kubeConfigMap.Data | ||
|
||
kokiConfigMapWrapper.ConfigMap = kokiConfigMap | ||
|
||
return kokiConfigMapWrapper, nil | ||
} | ||
|
||
func Convert_Koki_ConfigMap_to_Kube_v1_ConfigMap(kokiConfigMapWrapper *types.ConfigMapWrapper) (*v1.ConfigMap, error) { | ||
kubeConfigMap := &v1.ConfigMap{} | ||
kokiConfigMap := kokiConfigMapWrapper.ConfigMap | ||
|
||
kubeConfigMap.Name = kokiConfigMap.Name | ||
kubeConfigMap.Namespace = kokiConfigMap.Namespace | ||
kubeConfigMap.APIVersion = kokiConfigMap.Version | ||
kubeConfigMap.ClusterName = kokiConfigMap.Cluster | ||
kubeConfigMap.Kind = "ConfigMap" | ||
kubeConfigMap.Labels = kokiConfigMap.Labels | ||
kubeConfigMap.Annotations = kokiConfigMap.Annotations | ||
|
||
kubeConfigMap.Data = kokiConfigMap.Data | ||
|
||
return kubeConfigMap, nil | ||
} |
66 changes: 66 additions & 0 deletions
66
converter/converters/koki_storageclass_to_kube_storageclass.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package converters | ||
|
||
import ( | ||
storagev1 "k8s.io/api/storage/v1" | ||
storagev1beta1 "k8s.io/api/storage/v1beta1" | ||
|
||
"github.com/ghodss/yaml" | ||
|
||
"github.com/koki/short/parser" | ||
"github.com/koki/short/types" | ||
"github.com/koki/short/util" | ||
) | ||
|
||
func Convert_Koki_StorageClass_to_Kube_StorageClass(storageClass *types.StorageClassWrapper) (interface{}, error) { | ||
// Perform version-agnostic conversion into storage/v1 StorageClass. | ||
kubeStorageClass := Convert_Koki_StorageClass_to_Kube_storage_v1_StorageClass(storageClass) | ||
|
||
// Serialize the "generic" kube StorageClass. | ||
b, err := yaml.Marshal(kubeStorageClass) | ||
if err != nil { | ||
return nil, util.InvalidValueErrorf(kubeStorageClass, "couldn't serialize 'generic' kube StorageClass: %s", err.Error()) | ||
} | ||
|
||
// Deserialize a versioned kube StorageClass using its apiVersion. | ||
versionedStorageClass, err := parser.ParseSingleKubeNativeFromBytes(b) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
switch versionedStorageClass := versionedStorageClass.(type) { | ||
case *storagev1.StorageClass: | ||
// Perform storage/v1beta1 initialization here. | ||
case *storagev1beta1.StorageClass: | ||
// Perform storage/v1beta1 initialization here. | ||
default: | ||
return nil, util.TypeErrorf(versionedStorageClass, "deserialized the manifest, but not as a supported kube StorageClass") | ||
} | ||
|
||
return versionedStorageClass, nil | ||
} | ||
|
||
func Convert_Koki_StorageClass_to_Kube_storage_v1_StorageClass(storageClass *types.StorageClassWrapper) *storagev1.StorageClass { | ||
kubeStorageClass := &storagev1.StorageClass{} | ||
kokiStorageClass := &storageClass.StorageClass | ||
|
||
kubeStorageClass.Name = kokiStorageClass.Name | ||
kubeStorageClass.Namespace = kokiStorageClass.Namespace | ||
kubeStorageClass.APIVersion = kokiStorageClass.Version | ||
kubeStorageClass.Kind = "StorageClass" | ||
kubeStorageClass.ClusterName = kokiStorageClass.Cluster | ||
kubeStorageClass.Labels = kokiStorageClass.Labels | ||
kubeStorageClass.Annotations = kokiStorageClass.Annotations | ||
|
||
kubeStorageClass.Provisioner = kokiStorageClass.Provisioner | ||
kubeStorageClass.Parameters = kokiStorageClass.Parameters | ||
|
||
kubeStorageClass.MountOptions = kokiStorageClass.MountOptions | ||
kubeStorageClass.AllowVolumeExpansion = kokiStorageClass.AllowVolumeExpansion | ||
|
||
if kokiStorageClass.Reclaim != nil { | ||
reclaimPolicy := revertReclaimPolicy(*kokiStorageClass.Reclaim) | ||
kubeStorageClass.ReclaimPolicy = &reclaimPolicy | ||
} | ||
|
||
return kubeStorageClass | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package converters | ||
|
||
import ( | ||
storagev1 "k8s.io/api/storage/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
|
||
"github.com/ghodss/yaml" | ||
|
||
"github.com/koki/short/parser" | ||
"github.com/koki/short/types" | ||
"github.com/koki/short/util" | ||
) | ||
|
||
func Convert_Kube_StorageClass_to_Koki_StorageClass(kubeStorageClass runtime.Object) (*types.StorageClassWrapper, error) { | ||
groupVersionKind := kubeStorageClass.GetObjectKind().GroupVersionKind() | ||
groupVersionString := groupVersionKind.GroupVersion().String() | ||
groupVersionKind.Version = "v1" | ||
groupVersionKind.Group = "storage.k8s.io" | ||
kubeStorageClass.GetObjectKind().SetGroupVersionKind(groupVersionKind) | ||
|
||
// Serialize as v1 | ||
b, err := yaml.Marshal(kubeStorageClass) | ||
if err != nil { | ||
return nil, util.InvalidInstanceErrorf(kubeStorageClass, "couldn't serialize kube StorageClass after setting apiVersion to storage/v1: %s", err.Error()) | ||
} | ||
|
||
// Deserialize the "generic" kube StorageClass | ||
genericStorageClass, err := parser.ParseSingleKubeNativeFromBytes(b) | ||
if err != nil { | ||
return nil, util.InvalidInstanceErrorf(string(b), "couldn't deserialize 'generic' kube StorageClass: %s", err.Error()) | ||
} | ||
|
||
if genericStorageClass, ok := genericStorageClass.(*storagev1.StorageClass); ok { | ||
kokiWrapper, err := Convert_Kube_storage_v1_StorageClass_to_Koki_StorageClass(genericStorageClass) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
kokiStorageClass := &kokiWrapper.StorageClass | ||
|
||
kokiStorageClass.Version = groupVersionString | ||
|
||
return kokiWrapper, nil | ||
} | ||
|
||
return nil, util.InvalidInstanceErrorf(genericStorageClass, "didn't deserialize 'generic' kube Deployment as storage/v1.StorageClass") | ||
} | ||
|
||
func Convert_Kube_storage_v1_StorageClass_to_Koki_StorageClass(kubeStorageClass *storagev1.StorageClass) (*types.StorageClassWrapper, error) { | ||
kokiStorageClass := &types.StorageClass{} | ||
|
||
kokiStorageClass.Name = kubeStorageClass.Name | ||
kokiStorageClass.Namespace = kubeStorageClass.Namespace | ||
kokiStorageClass.Version = kubeStorageClass.APIVersion | ||
kokiStorageClass.Cluster = kubeStorageClass.ClusterName | ||
kokiStorageClass.Labels = kubeStorageClass.Labels | ||
kokiStorageClass.Annotations = kubeStorageClass.Annotations | ||
|
||
kokiStorageClass.Provisioner = kubeStorageClass.Provisioner | ||
kokiStorageClass.Parameters = kubeStorageClass.Parameters | ||
kokiStorageClass.MountOptions = kubeStorageClass.MountOptions | ||
kokiStorageClass.AllowVolumeExpansion = kubeStorageClass.AllowVolumeExpansion | ||
|
||
if kubeStorageClass.ReclaimPolicy != nil { | ||
reclaimPolicy := convertReclaimPolicy(*kubeStorageClass.ReclaimPolicy) | ||
kokiStorageClass.Reclaim = &reclaimPolicy | ||
} | ||
|
||
return &types.StorageClassWrapper{ | ||
StorageClass: *kokiStorageClass, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package converters | ||
|
||
import ( | ||
"k8s.io/api/core/v1" | ||
|
||
"github.com/koki/short/types" | ||
"github.com/koki/short/util" | ||
) | ||
|
||
func Convert_Kube_v1_Secret_to_Koki_Secret(kubeSecret *v1.Secret) (*types.SecretWrapper, error) { | ||
kokiSecretWrapper := &types.SecretWrapper{} | ||
kokiSecret := types.Secret{} | ||
|
||
kokiSecret.Name = kubeSecret.Name | ||
kokiSecret.Namespace = kubeSecret.Namespace | ||
kokiSecret.Version = kubeSecret.APIVersion | ||
kokiSecret.Cluster = kubeSecret.ClusterName | ||
kokiSecret.Labels = kubeSecret.Labels | ||
kokiSecret.Annotations = kubeSecret.Annotations | ||
kokiSecret.Data = kubeSecret.Data | ||
kokiSecret.StringData = kubeSecret.StringData | ||
|
||
t, err := convertSecretType(kubeSecret.Type) | ||
if err != nil { | ||
return nil, err | ||
} | ||
kokiSecret.SecretType = t | ||
|
||
kokiSecretWrapper.Secret = kokiSecret | ||
return kokiSecretWrapper, nil | ||
} | ||
|
||
func convertSecretType(secret v1.SecretType) (types.SecretType, error) { | ||
if secret == "" { | ||
return "", nil | ||
} | ||
switch secret { | ||
case v1.SecretTypeOpaque: | ||
return types.SecretTypeOpaque, nil | ||
case v1.SecretTypeServiceAccountToken: | ||
return types.SecretTypeServiceAccountToken, nil | ||
case v1.SecretTypeDockercfg: | ||
return types.SecretTypeDockercfg, nil | ||
case v1.SecretTypeDockerConfigJson: | ||
return types.SecretTypeDockerConfigJson, nil | ||
case v1.SecretTypeBasicAuth: | ||
return types.SecretTypeBasicAuth, nil | ||
case v1.SecretTypeSSHAuth: | ||
return types.SecretTypeSSHAuth, nil | ||
case v1.SecretTypeTLS: | ||
return types.SecretTypeTLS, nil | ||
default: | ||
return "", util.InvalidValueErrorf(secret, "unrecognized Secret type") | ||
} | ||
} | ||
|
||
func Convert_Koki_Secret_to_Kube_v1_Secret(kokiSecretWrapper *types.SecretWrapper) (*v1.Secret, error) { | ||
kubeSecret := &v1.Secret{} | ||
kokiSecret := kokiSecretWrapper.Secret | ||
|
||
kubeSecret.Name = kokiSecret.Name | ||
kubeSecret.Namespace = kokiSecret.Namespace | ||
kubeSecret.APIVersion = kokiSecret.Version | ||
kubeSecret.ClusterName = kokiSecret.Cluster | ||
kubeSecret.Kind = "Secret" | ||
kubeSecret.Labels = kokiSecret.Labels | ||
kubeSecret.Annotations = kokiSecret.Annotations | ||
kubeSecret.Data = kokiSecret.Data | ||
kubeSecret.StringData = kubeSecret.StringData | ||
|
||
t, err := revertSecretType(kokiSecret.SecretType) | ||
if err != nil { | ||
return nil, err | ||
} | ||
kubeSecret.Type = t | ||
|
||
return kubeSecret, nil | ||
} | ||
|
||
func revertSecretType(secret types.SecretType) (v1.SecretType, error) { | ||
if secret == "" { | ||
return "", nil | ||
} | ||
|
||
switch secret { | ||
case types.SecretTypeOpaque: | ||
return v1.SecretTypeOpaque, nil | ||
case types.SecretTypeServiceAccountToken: | ||
return v1.SecretTypeServiceAccountToken, nil | ||
case types.SecretTypeDockercfg: | ||
return v1.SecretTypeDockercfg, nil | ||
case types.SecretTypeDockerConfigJson: | ||
return v1.SecretTypeDockerConfigJson, nil | ||
case types.SecretTypeBasicAuth: | ||
return v1.SecretTypeBasicAuth, nil | ||
case types.SecretTypeSSHAuth: | ||
return v1.SecretTypeSSHAuth, nil | ||
case types.SecretTypeTLS: | ||
return v1.SecretTypeTLS, nil | ||
default: | ||
return "", util.InvalidValueErrorf(secret, "unrecognized Secret type") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
config_map: | ||
data: | ||
game.properties: | | ||
enemies=aliens | ||
lives=3 | ||
enemies.cheat=true | ||
enemies.cheat.level=noGoodRotten | ||
secret.code.passphrase=UUDDLRLRBABAS | ||
secret.code.allowed=true | ||
secret.code.lives=30 | ||
ui.properties: | | ||
color.good=purple | ||
color.bad=yellow | ||
allow.textmode=true | ||
how.nice.to.look=fairlyNice | ||
name: game-config | ||
namespace: default | ||
version: v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
apiVersion: v1 | ||
data: | ||
game.properties: | | ||
enemies=aliens | ||
lives=3 | ||
enemies.cheat=true | ||
enemies.cheat.level=noGoodRotten | ||
secret.code.passphrase=UUDDLRLRBABAS | ||
secret.code.allowed=true | ||
secret.code.lives=30 | ||
ui.properties: | | ||
color.good=purple | ||
color.bad=yellow | ||
allow.textmode=true | ||
how.nice.to.look=fairlyNice | ||
kind: ConfigMap | ||
metadata: | ||
creationTimestamp: 2016-02-18T18:52:05Z | ||
name: game-config | ||
namespace: default | ||
resourceVersion: "516" | ||
selfLink: /api/v1/namespaces/default/configmaps/game-config-2 | ||
uid: b4952dc3-d670-11e5-8cd0-68f728db1985 |
Oops, something went wrong.