-
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 #186 from ublubu/docs
docs and style fixes, limitrange and HPA implementation
- Loading branch information
Showing
24 changed files
with
725 additions
and
3 deletions.
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,56 @@ | ||
package converters | ||
|
||
import ( | ||
autoscaling "k8s.io/api/autoscaling/v1" | ||
|
||
"github.com/koki/short/types" | ||
) | ||
|
||
func Convert_Koki_HPA_to_Kube(wrapper *types.HorizontalPodAutoscalerWrapper) (*autoscaling.HorizontalPodAutoscaler, error) { | ||
kube := &autoscaling.HorizontalPodAutoscaler{} | ||
koki := wrapper.HPA | ||
|
||
kube.Name = koki.Name | ||
kube.Namespace = koki.Namespace | ||
if len(koki.Version) == 0 { | ||
kube.APIVersion = "autoscaling/v1" | ||
} else { | ||
kube.APIVersion = koki.Version | ||
} | ||
kube.Kind = "HorizontalPodAutoscaler" | ||
kube.ClusterName = koki.Cluster | ||
kube.Labels = koki.Labels | ||
kube.Annotations = koki.Annotations | ||
|
||
kube.Spec = revertHPASpec(koki.HorizontalPodAutoscalerSpec) | ||
kube.Status = revertHPAStatus(koki.HorizontalPodAutoscalerStatus) | ||
|
||
return kube, nil | ||
} | ||
|
||
func revertHPASpec(kokiSpec types.HorizontalPodAutoscalerSpec) autoscaling.HorizontalPodAutoscalerSpec { | ||
return autoscaling.HorizontalPodAutoscalerSpec{ | ||
ScaleTargetRef: revertCrossVersionObjectReference(kokiSpec.ScaleTargetRef), | ||
MinReplicas: kokiSpec.MinReplicas, | ||
MaxReplicas: kokiSpec.MaxReplicas, | ||
TargetCPUUtilizationPercentage: kokiSpec.TargetCPUUtilizationPercentage, | ||
} | ||
} | ||
|
||
func revertHPAStatus(kokiStatus types.HorizontalPodAutoscalerStatus) autoscaling.HorizontalPodAutoscalerStatus { | ||
return autoscaling.HorizontalPodAutoscalerStatus{ | ||
ObservedGeneration: kokiStatus.ObservedGeneration, | ||
LastScaleTime: kokiStatus.LastScaleTime, | ||
CurrentReplicas: kokiStatus.CurrentReplicas, | ||
DesiredReplicas: kokiStatus.DesiredReplicas, | ||
CurrentCPUUtilizationPercentage: kokiStatus.CurrentCPUUtilizationPercentage, | ||
} | ||
} | ||
|
||
func revertCrossVersionObjectReference(kokiRef types.CrossVersionObjectReference) autoscaling.CrossVersionObjectReference { | ||
return autoscaling.CrossVersionObjectReference{ | ||
Kind: kokiRef.Kind, | ||
Name: kokiRef.Name, | ||
APIVersion: kokiRef.APIVersion, | ||
} | ||
} |
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,81 @@ | ||
package converters | ||
|
||
import ( | ||
"k8s.io/api/core/v1" | ||
|
||
"github.com/koki/short/types" | ||
serrors "github.com/koki/structurederrors" | ||
) | ||
|
||
func Convert_Koki_LimitRange_to_Kube(wrapper *types.LimitRangeWrapper) (*v1.LimitRange, error) { | ||
var err error | ||
kube := &v1.LimitRange{} | ||
koki := wrapper.LimitRange | ||
|
||
kube.Name = koki.Name | ||
kube.Namespace = koki.Namespace | ||
if len(koki.Version) == 0 { | ||
kube.APIVersion = "v1" | ||
} else { | ||
kube.APIVersion = koki.Version | ||
} | ||
kube.Kind = "LimitRange" | ||
kube.ClusterName = koki.Cluster | ||
kube.Labels = koki.Labels | ||
kube.Annotations = koki.Annotations | ||
|
||
kube.Spec.Limits, err = revertLimitRangeItems(koki.Limits) | ||
if err != nil { | ||
return nil, serrors.ContextualizeErrorf(err, "LimitRange.Spec.Limits") | ||
} | ||
|
||
return kube, nil | ||
} | ||
|
||
func revertLimitRangeItems(kokiItems []types.LimitRangeItem) ([]v1.LimitRangeItem, error) { | ||
if len(kokiItems) == 0 { | ||
return nil, nil | ||
} | ||
|
||
var err error | ||
kubeItems := make([]v1.LimitRangeItem, len(kokiItems)) | ||
for i, kokiItem := range kokiItems { | ||
kubeItems[i], err = revertLimitRangeItem(kokiItem) | ||
if err != nil { | ||
return nil, serrors.ContextualizeErrorf(err, "[%d]", i) | ||
} | ||
} | ||
|
||
return kubeItems, nil | ||
} | ||
|
||
func revertLimitRangeItem(kokiItem types.LimitRangeItem) (v1.LimitRangeItem, error) { | ||
kubeItem := v1.LimitRangeItem{ | ||
Max: kokiItem.Max, | ||
Min: kokiItem.Min, | ||
Default: kokiItem.Default, | ||
DefaultRequest: kokiItem.DefaultRequest, | ||
MaxLimitRequestRatio: kokiItem.MaxLimitRequestRatio, | ||
} | ||
|
||
var err error | ||
kubeItem.Type, err = revertLimitType(kokiItem.Type) | ||
return kubeItem, err | ||
} | ||
|
||
func revertLimitType(kokiType types.LimitType) (v1.LimitType, error) { | ||
if len(kokiType) == 0 { | ||
return "", nil | ||
} | ||
|
||
switch kokiType { | ||
case types.LimitTypePod: | ||
return v1.LimitTypePod, nil | ||
case types.LimitTypeContainer: | ||
return v1.LimitTypeContainer, nil | ||
case types.LimitTypePersistentVolumeClaim: | ||
return v1.LimitTypePersistentVolumeClaim, nil | ||
default: | ||
return "", serrors.InvalidInstanceError(kokiType) | ||
} | ||
} |
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,53 @@ | ||
package converters | ||
|
||
import ( | ||
autoscaling "k8s.io/api/autoscaling/v1" | ||
|
||
"github.com/koki/short/types" | ||
) | ||
|
||
func Convert_Kube_HPA_to_Koki(kube *autoscaling.HorizontalPodAutoscaler) (*types.HorizontalPodAutoscalerWrapper, error) { | ||
koki := &types.HorizontalPodAutoscaler{} | ||
|
||
koki.Name = kube.Name | ||
koki.Namespace = kube.Namespace | ||
koki.Version = kube.APIVersion | ||
koki.Cluster = kube.ClusterName | ||
koki.Labels = kube.Labels | ||
koki.Annotations = kube.Annotations | ||
|
||
koki.HorizontalPodAutoscalerSpec = convertHPASpec(kube.Spec) | ||
koki.HorizontalPodAutoscalerStatus = convertHPAStatus(kube.Status) | ||
|
||
return &types.HorizontalPodAutoscalerWrapper{ | ||
HPA: *koki, | ||
}, nil | ||
} | ||
|
||
func convertHPASpec(kubeSpec autoscaling.HorizontalPodAutoscalerSpec) types.HorizontalPodAutoscalerSpec { | ||
return types.HorizontalPodAutoscalerSpec{ | ||
ScaleTargetRef: convertCrossVersionObjectReference(kubeSpec.ScaleTargetRef), | ||
|
||
MinReplicas: kubeSpec.MinReplicas, | ||
MaxReplicas: kubeSpec.MaxReplicas, | ||
TargetCPUUtilizationPercentage: kubeSpec.TargetCPUUtilizationPercentage, | ||
} | ||
} | ||
|
||
func convertHPAStatus(kubeStatus autoscaling.HorizontalPodAutoscalerStatus) types.HorizontalPodAutoscalerStatus { | ||
return types.HorizontalPodAutoscalerStatus{ | ||
ObservedGeneration: kubeStatus.ObservedGeneration, | ||
LastScaleTime: kubeStatus.LastScaleTime, | ||
CurrentReplicas: kubeStatus.CurrentReplicas, | ||
DesiredReplicas: kubeStatus.DesiredReplicas, | ||
CurrentCPUUtilizationPercentage: kubeStatus.CurrentCPUUtilizationPercentage, | ||
} | ||
} | ||
|
||
func convertCrossVersionObjectReference(kubeRef autoscaling.CrossVersionObjectReference) types.CrossVersionObjectReference { | ||
return types.CrossVersionObjectReference{ | ||
Kind: kubeRef.Kind, | ||
Name: kubeRef.Name, | ||
APIVersion: kubeRef.APIVersion, | ||
} | ||
} |
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,77 @@ | ||
package converters | ||
|
||
import ( | ||
"k8s.io/api/core/v1" | ||
|
||
"github.com/koki/short/types" | ||
serrors "github.com/koki/structurederrors" | ||
) | ||
|
||
func Convert_Kube_LimitRange_to_Koki(kube *v1.LimitRange) (*types.LimitRangeWrapper, error) { | ||
var err error | ||
koki := &types.LimitRange{} | ||
|
||
koki.Name = kube.Name | ||
koki.Namespace = kube.Namespace | ||
koki.Version = kube.APIVersion | ||
koki.Cluster = kube.ClusterName | ||
koki.Labels = kube.Labels | ||
koki.Annotations = kube.Annotations | ||
|
||
koki.Limits, err = convertLimitRangeItems(kube.Spec.Limits) | ||
if err != nil { | ||
return nil, serrors.ContextualizeErrorf(err, "limit_range limits") | ||
} | ||
|
||
return &types.LimitRangeWrapper{ | ||
LimitRange: *koki, | ||
}, nil | ||
} | ||
|
||
func convertLimitRangeItems(kubeItems []v1.LimitRangeItem) ([]types.LimitRangeItem, error) { | ||
if len(kubeItems) == 0 { | ||
return nil, nil | ||
} | ||
|
||
var err error | ||
kokiItems := make([]types.LimitRangeItem, len(kubeItems)) | ||
for i, kubeItem := range kubeItems { | ||
kokiItems[i], err = convertLimitRangeItem(kubeItem) | ||
if err != nil { | ||
return nil, serrors.ContextualizeErrorf(err, "[%d]", i) | ||
} | ||
} | ||
|
||
return kokiItems, nil | ||
} | ||
|
||
func convertLimitRangeItem(kubeItem v1.LimitRangeItem) (types.LimitRangeItem, error) { | ||
kokiItem := types.LimitRangeItem{ | ||
Max: kubeItem.Max, | ||
Min: kubeItem.Min, | ||
Default: kubeItem.Default, | ||
DefaultRequest: kubeItem.DefaultRequest, | ||
MaxLimitRequestRatio: kubeItem.MaxLimitRequestRatio, | ||
} | ||
|
||
var err error | ||
kokiItem.Type, err = convertLimitType(kubeItem.Type) | ||
return kokiItem, err | ||
} | ||
|
||
func convertLimitType(kubeItem v1.LimitType) (types.LimitType, error) { | ||
if len(kubeItem) == 0 { | ||
return "", nil | ||
} | ||
|
||
switch kubeItem { | ||
case v1.LimitTypePod: | ||
return types.LimitTypePod, nil | ||
case v1.LimitTypeContainer: | ||
return types.LimitTypeContainer, nil | ||
case v1.LimitTypePersistentVolumeClaim: | ||
return types.LimitTypePersistentVolumeClaim, nil | ||
default: | ||
return "", serrors.InvalidInstanceError(kubeItem) | ||
} | ||
} |
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,42 @@ | ||
# Introduction | ||
|
||
ControllerRevision is an immutable snapshot of state. | ||
It's primarily intended for internal use by controllers. | ||
For example, it's used by the DaemonSet and StatefulSet controllers for update and rollback. | ||
|
||
Here's an example Kubernetes ControllerRevision: | ||
```yaml | ||
apiVersion: apps/v1 | ||
kind: ControllerRevision | ||
metadata: | ||
name: example | ||
data: | ||
key: value | ||
revision: 1 | ||
``` | ||
The following sections contain detailed information about each field in Short syntax, including how the field translates to and from Kubernetes syntax. | ||
# API Overview | ||
| Field | Type | K8s counterpart(s) | Description | | ||
|:------|:-----|:--------|:-----------------------| | ||
|version| `string` | `apiVersion` | The version of the resource object | | ||
|cluster| `string` | `metadata.clusterName` | The name of the cluster on which this Job is running | | ||
|name | `string` | `metadata.name`| The name of the Job | | ||
|namespace | `string` | `metadata.namespace` | The K8s namespace this Job will be a member of | | ||
|labels | `string` | `metadata.labels`| Metadata about the Job, including identifying information | | ||
|annotations| `string` | `metadata.annotations`| Non-identifying information about the Job | | ||
|data| YAML | `data` | This field can hold any valid YAML. | | ||
|revision| `int64` | The revision number | | ||
|
||
# Examples / Skeleton | ||
|
||
Here's a starter skeleton of a Short ControllerRevision. | ||
```yaml | ||
controller_revision: | ||
name: example | ||
data: | ||
key: value | ||
revision: 1 | ||
``` |
Oops, something went wrong.