Skip to content

Commit 98a7644

Browse files
AbdullahAlShaadtamalsaha
authored andcommitted
Add docker-machine operator (#1)
Signed-off-by: Shaad7 <abdullah.alshaad@appscode.com> Signed-off-by: Tamal Saha <tamal@appscode.com>
1 parent c147a20 commit 98a7644

File tree

1,253 files changed

+118179
-72080
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,253 files changed

+118179
-72080
lines changed

.dockerignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

.gitignore

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
1-
2-
# Binaries for programs and plugins
3-
*.exe
4-
*.exe~
5-
*.dll
1+
# Compiled Object files, Static and Dynamic libs (Shared Objects)
2+
*.o
3+
*.a
64
*.so
7-
*.dylib
8-
bin/*
9-
Dockerfile.cross
105

11-
# Test binary, build with `go test -c`
12-
*.test
6+
# Folders
7+
_obj
8+
_test
139

14-
# Output of the go coverage tool, specifically when used with LiteIDE
15-
*.out
10+
# Architecture specific extensions/prefixes
11+
*.cgo1.go
12+
*.cgo2.c
13+
_cgo_defun.c
14+
_cgo_gotypes.go
15+
_cgo_export.*
1616

17-
# Kubernetes Generated files - skip generated files, except for vendored files
17+
_testmain.go
18+
19+
*.exe
20+
*.test
21+
*.prof
1822

19-
!vendor/**/zz_generated.*
23+
/bin
24+
/.go
2025

21-
# editor and IDE paraphernalia
22-
.idea
23-
.vscode
24-
*.swp
25-
*.swo
26-
*~
26+
/.idea
27+
/.markdownlint.json
28+
/.vscode
29+
/apiserver.local.config
30+
/coverage.txt
31+
/dist
32+
/hack/config/.env
33+
/test/e2e/junit.xml
34+
/test/e2e/report.xml

Dockerfile.dbg

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,19 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
FROM ghcr.io/appscode/dlv:1.20.1
15+
FROM alpine
16+
17+
ARG TARGETARCH
18+
19+
RUN set -x \
20+
&& apk add --no-cache ca-certificates \
21+
&& wget -O rancher-machine.tar.gz https://github.com/rancher/machine/releases/download/v0.15.0-rancher103/rancher-machine-${TARGETARCH}.tar.gz \
22+
&& tar xzf rancher-machine.tar.gz \
23+
&& chmod +x rancher-machine \
24+
&& mv rancher-machine docker-machine
25+
26+
27+
FROM ghcr.io/appscode/dlv:1.20.1 as build-env
1628

1729
FROM {ARG_FROM}
1830

@@ -21,12 +33,14 @@ LABEL org.opencontainers.image.source https://github.com/cluster-api/docker-mach
2133
RUN set -x \
2234
&& apt-get update \
2335
&& apt-get upgrade -y \
24-
&& apt-get install -y --no-install-recommends ca-certificates \
36+
&& apt-get install -y --no-install-recommends ca-certificates openssh-client \
2537
&& rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man /tmp/* \
2638
&& echo 'Etc/UTC' > /etc/timezone
2739

2840
ADD bin/{ARG_BIN}-{ARG_OS}-{ARG_ARCH} /{ARG_BIN}
29-
COPY --from=0 /usr/local/bin/dlv /bin/dlv
41+
COPY --from=build-env /usr/local/bin/dlv /bin/dlv
42+
43+
COPY --from=0 /docker-machine /bin/docker-machine
3044

3145
EXPOSE 40000
3246

Dockerfile.in

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,29 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
FROM alpine
16+
17+
ARG TARGETARCH
18+
19+
RUN set -x \
20+
&& apk add --no-cache ca-certificates \
21+
&& wget -O rancher-machine.tar.gz https://github.com/rancher/machine/releases/download/v0.15.0-rancher103/rancher-machine-${TARGETARCH}.tar.gz \
22+
&& tar xzf rancher-machine.tar.gz \
23+
&& chmod +x rancher-machine \
24+
&& mv rancher-machine docker-machine
25+
1526
FROM {ARG_FROM}
1627

1728
LABEL org.opencontainers.image.source https://github.com/cluster-api/docker-machine-operator
1829

1930
RUN set -x \
20-
&& apk add --update --upgrade --no-cache pcre2 ca-certificates tzdata \
31+
&& apk add --update --upgrade --no-cache pcre2 ca-certificates tzdata openssh-client \
2132
&& echo 'Etc/UTC' > /etc/timezone
2233

2334
ADD bin/{ARG_BIN}-{ARG_OS}-{ARG_ARCH} /{ARG_BIN}
2435

36+
COPY --from=0 /docker-machine /bin/docker-machine
37+
2538
USER 65534
2639

2740
ENTRYPOINT ["/{ARG_BIN}"]

api/v1alpha1/driver_types.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,11 @@ import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121
)
2222

23-
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
24-
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
25-
2623
// DriverSpec defines the desired state of Driver
2724
type DriverSpec struct {
28-
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
29-
// Important: Run "make" to regenerate code after modifying this file
30-
31-
// Foo is an example field of Driver. Edit driver_types.go to remove/update
32-
Foo string `json:"foo,omitempty"`
25+
Builtin bool `json:"builtin"`
26+
// +optional
27+
DownloadURL string `json:"downloadURL,omitempty"`
3328
}
3429

3530
// DriverStatus defines the observed state of Driver

api/v1alpha1/helper.go

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
Copyright AppsCode Inc. and Contributors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
"fmt"
21+
22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
kmapi "kmodules.xyz/client-go/api/v1"
24+
)
25+
26+
type MachinePhase string
27+
28+
const (
29+
MachineConditionTypeMachineReady kmapi.ConditionType = "MachineReady"
30+
MachineConditionTypeScriptReady kmapi.ConditionType = "ScriptReady"
31+
MachineConditionTypeAuthDataReady kmapi.ConditionType = "AuthDataReady"
32+
MachineConditionTypeClusterReady kmapi.ConditionType = "ClusterReady"
33+
)
34+
35+
const (
36+
MachineConditionClusterCreatedSuccessfully = "ClusterCreatedSuccessfully"
37+
MachineConditionClusterCreateFailed = "ClusterCreateFailed"
38+
MachineConditionWaitingForScriptCompletion = "WaitingForScriptCompletion"
39+
MachineConditionAuthDataNotFound = "AuthDataNotFound"
40+
MachineConditionScriptDataNotFound = "ScriptDataNotFound"
41+
MachineConditionMachineCreating = "MachineCreating"
42+
)
43+
44+
const (
45+
MachinePhasePending MachinePhase = "Pending"
46+
MachinePhaseInProgress MachinePhase = "InProgress"
47+
MachinePhaseWaitingForClusterReady MachinePhase = "WaitingForClusterReady"
48+
MachinePhaseClusterCreateFailed MachinePhase = "ClusterCreateFailed"
49+
MachinePhaseSuccess MachinePhase = "Success"
50+
MachinePhaseTerminating MachinePhase = "Terminating"
51+
MachinePhaseFailed MachinePhase = "Failed"
52+
)
53+
54+
func ConditionsOrder() []kmapi.ConditionType {
55+
return []kmapi.ConditionType{
56+
MachineConditionTypeClusterReady,
57+
MachineConditionTypeMachineReady,
58+
MachineConditionTypeAuthDataReady,
59+
MachineConditionTypeScriptReady,
60+
}
61+
}
62+
63+
func GetPhase(obj *Machine) MachinePhase {
64+
if !obj.GetDeletionTimestamp().IsZero() {
65+
return MachinePhaseTerminating
66+
}
67+
conditions := obj.GetConditions()
68+
if len(conditions) == 0 {
69+
return MachinePhaseInProgress
70+
}
71+
var cond kmapi.Condition
72+
for i := range conditions {
73+
c := conditions[i]
74+
if c.Type == kmapi.ReadyCondition {
75+
cond = c
76+
break
77+
}
78+
}
79+
if cond.Type != kmapi.ReadyCondition {
80+
panic(fmt.Sprintf("no Ready condition in the status for %s/%s", obj.GetNamespace(), obj.GetName()))
81+
}
82+
83+
if cond.Status == metav1.ConditionTrue {
84+
return MachinePhaseSuccess
85+
}
86+
87+
if cond.Reason == MachineConditionAuthDataNotFound ||
88+
cond.Reason == MachineConditionScriptDataNotFound {
89+
return MachinePhaseFailed
90+
}
91+
if cond.Reason == MachineConditionMachineCreating {
92+
return MachinePhaseInProgress
93+
}
94+
if cond.Reason == MachineConditionWaitingForScriptCompletion {
95+
return MachinePhaseWaitingForClusterReady
96+
}
97+
if cond.Reason == MachineConditionClusterCreateFailed {
98+
return MachineConditionClusterCreateFailed
99+
}
100+
return MachinePhaseFailed
101+
}
102+
103+
func GetFinalizer() string {
104+
return GroupVersion.Group
105+
}

api/v1alpha1/machine_types.go

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,36 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20+
core "k8s.io/api/core/v1"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
kmapi "kmodules.xyz/client-go/api/v1"
2123
)
2224

23-
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
24-
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
25-
2625
// MachineSpec defines the desired state of Machine
2726
type MachineSpec struct {
28-
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
29-
// Important: Run "make" to regenerate code after modifying this file
30-
31-
// Foo is an example field of Machine. Edit machine_types.go to remove/update
32-
Foo string `json:"foo,omitempty"`
27+
Driver *core.LocalObjectReference `json:"driver"`
28+
ScriptRef *kmapi.ObjectReference `json:"scriptRef"`
29+
AuthSecret *kmapi.ObjectReference `json:"authSecret"`
30+
Parameters map[string]string `json:"parameters"`
3331
}
3432

3533
// MachineStatus defines the observed state of Machine
3634
type MachineStatus struct {
37-
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
38-
// Important: Run "make" to regenerate code after modifying this file
35+
// +optional
36+
// +listType=map
37+
// +listMapKey=type
38+
// +kubebuilder:validation:MaxItems=8
39+
Conditions []kmapi.Condition `json:"conditions"`
40+
// +optional
41+
Phase MachinePhase `json:"phase"`
3942
}
4043

41-
//+kubebuilder:object:root=true
42-
//+kubebuilder:subresource:status
43-
4444
// Machine is the Schema for the machines API
45+
46+
// +kubebuilder:object:root=true
47+
// +kubebuilder:subresource:status
48+
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.phase"
49+
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
4550
type Machine struct {
4651
metav1.TypeMeta `json:",inline"`
4752
metav1.ObjectMeta `json:"metadata,omitempty"`
@@ -62,3 +67,15 @@ type MachineList struct {
6267
func init() {
6368
SchemeBuilder.Register(&Machine{}, &MachineList{})
6469
}
70+
71+
func (in *Machine) GetStatus() *MachineStatus {
72+
return &in.Status
73+
}
74+
75+
func (in *Machine) GetConditions() kmapi.Conditions {
76+
return in.Status.Conditions
77+
}
78+
79+
func (in *Machine) SetConditions(conditions kmapi.Conditions) {
80+
in.Status.Conditions = conditions
81+
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 33 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)