Skip to content

Commit

Permalink
Merge pull request #22 from kraken-iac/import-state
Browse files Browse the repository at this point in the history
import referenced state
  • Loading branch information
eoinfennessy committed Mar 30, 2024
2 parents 814a6c4 + b9c63d3 commit 31c3068
Show file tree
Hide file tree
Showing 14 changed files with 821 additions and 41 deletions.
33 changes: 25 additions & 8 deletions api/v1alpha1/ec2instance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ limitations under the License.
package v1alpha1

import (
"reflect"

"github.com/kraken-iac/aws-ec2-instance/pkg/option"
"github.com/kraken-iac/kraken/api/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -25,19 +29,32 @@ import (

// EC2InstanceSpec defines the desired state of EC2Instance
type EC2InstanceSpec struct {
ImageId string `json:"imageId"`
InstanceType string `json:"instanceType"`

//+kubebuilder:validation:Minimum=1
MaxCount int `json:"maxCount"`

//+kubebuilder:validation:Minimum=1
MinCount int `json:"minCount"`
ImageID option.String `json:"imageID"`
InstanceType option.String `json:"instanceType"`
MaxCount option.Int `json:"maxCount"`
MinCount option.Int `json:"minCount"`

// +optional
Tags map[string]string `json:"tags,omitempty"`
}

func (s EC2InstanceSpec) GenerateDependencyRequestSpec() v1alpha1.DependencyRequestSpec {
dr := v1alpha1.DependencyRequestSpec{}
if s.ImageID.ValueFrom != nil {
s.ImageID.ValueFrom.AddToDependencyRequestSpec(&dr, reflect.String)
}
if s.InstanceType.ValueFrom != nil {
s.InstanceType.ValueFrom.AddToDependencyRequestSpec(&dr, reflect.String)
}
if s.MaxCount.ValueFrom != nil {
s.MaxCount.ValueFrom.AddToDependencyRequestSpec(&dr, reflect.Int)
}
if s.MinCount.ValueFrom != nil {
s.MinCount.ValueFrom.AddToDependencyRequestSpec(&dr, reflect.Int)
}
return dr
}

// EC2InstanceStatus defines the observed state of EC2Instance
type EC2InstanceStatus struct {
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
Expand Down
4 changes: 4 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

170 changes: 162 additions & 8 deletions config/crd/bases/aws.kraken-iac.eoinfennessy.com_ec2instances.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,176 @@ spec:
spec:
description: EC2InstanceSpec defines the desired state of EC2Instance
properties:
imageId:
type: string
imageID:
properties:
value:
type: string
valueFrom:
properties:
configMap:
properties:
key:
type: string
name:
type: string
required:
- key
- name
type: object
krakenResource:
properties:
kind:
type: string
name:
type: string
path:
type: string
required:
- kind
- name
- path
type: object
secret:
properties:
key:
type: string
name:
type: string
required:
- key
- name
type: object
type: object
type: object
instanceType:
type: string
properties:
value:
type: string
valueFrom:
properties:
configMap:
properties:
key:
type: string
name:
type: string
required:
- key
- name
type: object
krakenResource:
properties:
kind:
type: string
name:
type: string
path:
type: string
required:
- kind
- name
- path
type: object
secret:
properties:
key:
type: string
name:
type: string
required:
- key
- name
type: object
type: object
type: object
maxCount:
minimum: 1
type: integer
properties:
value:
type: integer
valueFrom:
properties:
configMap:
properties:
key:
type: string
name:
type: string
required:
- key
- name
type: object
krakenResource:
properties:
kind:
type: string
name:
type: string
path:
type: string
required:
- kind
- name
- path
type: object
secret:
properties:
key:
type: string
name:
type: string
required:
- key
- name
type: object
type: object
type: object
minCount:
minimum: 1
type: integer
properties:
value:
type: integer
valueFrom:
properties:
configMap:
properties:
key:
type: string
name:
type: string
required:
- key
- name
type: object
krakenResource:
properties:
kind:
type: string
name:
type: string
path:
type: string
required:
- kind
- name
- path
type: object
secret:
properties:
key:
type: string
name:
type: string
required:
- key
- name
type: object
type: object
type: object
tags:
additionalProperties:
type: string
type: object
required:
- imageId
- imageID
- instanceType
- maxCount
- minCount
Expand Down
12 changes: 12 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ rules:
verbs:
- create
- patch
- apiGroups:
- core.kraken-iac.eoinfennessy.com
resources:
- dependencyrequests
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- core.kraken-iac.eoinfennessy.com
resources:
Expand Down
26 changes: 22 additions & 4 deletions config/samples/aws_v1alpha1_ec2instance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,25 @@ metadata:
app.kubernetes.io/created-by: aws-ec2-instance
name: ec2instance-sample
spec:
imageId: "ami-0277155c3f0ab2930"
instanceType: "t2.nano"
maxCount: 1
minCount: 1
imageID:
valueFrom:
configMap:
name: my-ec2-config
key: imageID
instanceType:
valueFrom:
krakenResource:
kind: ec2instance
name: my-instance
path: instances.0.instanceType
maxCount:
valueFrom:
configMap:
name: my-ec2-config
key: maxCount
minCount:
valueFrom:
krakenResource:
kind: ec2instance
name: my-instance
path: instances.0.minCount
7 changes: 7 additions & 0 deletions config/samples/dependencies/configmap-dependency.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: my-ec2-config
data:
imageID: "ami-0277155c3f0ab2930"
maxCount: "1"
15 changes: 15 additions & 0 deletions config/samples/dependencies/statedeclaration-dependency.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: core.kraken-iac.eoinfennessy.com/v1alpha1
kind: StateDeclaration
metadata:
labels:
app.kubernetes.io/name: statedeclaration
app.kubernetes.io/instance: statedeclaration-sample
app.kubernetes.io/part-of: kraken
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/created-by: kraken
name: ec2instance-my-instance
spec:
data:
instances:
- instanceType: t2.nano
minCount: 1
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ require (
)

require (
github.com/Jeffail/gabs/v2 v2.7.0
github.com/aws/aws-sdk-go-v2/config v1.26.6
github.com/aws/aws-sdk-go-v2/service/ec2 v1.146.0
github.com/beorn7/perks v1.0.1 // indirect
Expand All @@ -52,7 +53,7 @@ require (
github.com/imdario/mergo v0.3.6 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kraken-iac/kraken v0.1.0
github.com/kraken-iac/kraken v0.3.1
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/Jeffail/gabs/v2 v2.7.0 h1:Y2edYaTcE8ZpRsR2AtmPu5xQdFDIthFG0jYhu5PY8kg=
github.com/Jeffail/gabs/v2 v2.7.0/go.mod h1:dp5ocw1FvBBQYssgHsG7I1WYsiLRtkUaB1FEtSwvNUw=
github.com/aws/aws-sdk-go-v2 v1.24.1 h1:xAojnj+ktS95YZlDf0zxWBkbFtymPeDP+rvUQIH3uAU=
github.com/aws/aws-sdk-go-v2 v1.24.1/go.mod h1:LNh45Br1YAkEKaAqvmE1m8FUx6a5b/V0oAKV7of29b4=
github.com/aws/aws-sdk-go-v2/config v1.26.6 h1:Z/7w9bUqlRI0FFQpetVuFYEsjzE3h7fpU6HuGmfPL/o=
Expand Down Expand Up @@ -106,6 +108,12 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kraken-iac/kraken v0.1.0 h1:BtdOK5KfKqsEXJZBn9mQwHCRSFRiJPC82Dc7OVOohhg=
github.com/kraken-iac/kraken v0.1.0/go.mod h1:DWYEW7ukNyx8y5y5mTKnIiKZOyc0xg8v/OhVqzekAk8=
github.com/kraken-iac/kraken v0.2.0 h1:5QVUUfni63wg5rgZPH7TEEQCiuQc+4Vp6v5PRZ5flzY=
github.com/kraken-iac/kraken v0.2.0/go.mod h1:DWYEW7ukNyx8y5y5mTKnIiKZOyc0xg8v/OhVqzekAk8=
github.com/kraken-iac/kraken v0.3.0 h1:ugVSR7NP8jtMXl9K43KbEkoGXZuzY4xwri/JHcQW3eA=
github.com/kraken-iac/kraken v0.3.0/go.mod h1:DWYEW7ukNyx8y5y5mTKnIiKZOyc0xg8v/OhVqzekAk8=
github.com/kraken-iac/kraken v0.3.1 h1:k4o5dSMdjL3Ry/73/DGlZ+64GgBaVP7+bBvsVmTONKo=
github.com/kraken-iac/kraken v0.3.1/go.mod h1:DWYEW7ukNyx8y5y5mTKnIiKZOyc0xg8v/OhVqzekAk8=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
Expand Down
Loading

0 comments on commit 31c3068

Please sign in to comment.