-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
60 changed files
with
5,809 additions
and
3,259 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
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,26 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
type AbstractVolumeSource corev1.VolumeSource | ||
|
||
func (in AbstractVolumeSource) getURNParts() (kind string, name string) { | ||
if v := in.ConfigMap; v != nil { | ||
return "configmap", v.Name | ||
} else if v := in.PersistentVolumeClaim; v != nil { | ||
return "persistentvolumeclaim", v.ClaimName | ||
} else if v := in.Secret; v != nil { | ||
return "secret", v.SecretName | ||
} | ||
panic(fmt.Errorf("un-suppported volume source %v", in)) | ||
} | ||
|
||
func (in AbstractVolumeSource) GenURN(cluster, namespace string) string { | ||
kind, name := in.getURNParts() | ||
return fmt.Sprintf("urn:dataflow:volume:%s:%s.%s.%s.%s", strings.ToLower(kind), name, kind, namespace, cluster) | ||
} |
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,39 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
var cluster, namespace = "my-cluster", "my-ns" | ||
|
||
func TestAbstractVolumeSource_GenURN(t *testing.T) { | ||
t.Run("ConfigMap", func(t *testing.T) { | ||
urn := AbstractVolumeSource{ | ||
ConfigMap: &corev1.ConfigMapVolumeSource{ | ||
LocalObjectReference: corev1.LocalObjectReference{ | ||
Name: "my-name", | ||
}, | ||
}, | ||
}.GenURN(cluster, namespace) | ||
assert.Equal(t, "urn:dataflow:volume:configmap:my-name.configmap.my-ns.my-cluster", urn) | ||
}) | ||
t.Run("PersistentVolumeClaim", func(t *testing.T) { | ||
urn := AbstractVolumeSource{ | ||
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{ | ||
ClaimName: "my-name", | ||
}, | ||
}.GenURN(cluster, namespace) | ||
assert.Equal(t, "urn:dataflow:volume:persistentvolumeclaim:my-name.persistentvolumeclaim.my-ns.my-cluster", urn) | ||
}) | ||
t.Run("Secret", func(t *testing.T) { | ||
urn := AbstractVolumeSource{ | ||
Secret: &corev1.SecretVolumeSource{ | ||
SecretName: "my-name", | ||
}, | ||
}.GenURN(cluster, namespace) | ||
assert.Equal(t, "urn:dataflow:volume:secret:my-name.secret.my-ns.my-cluster", urn) | ||
}) | ||
} |
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 |
---|---|---|
@@ -1,7 +1,15 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type Cron struct { | ||
Schedule string `json:"schedule" protobuf:"bytes,1,opt,name=schedule"` | ||
// +kubebuilder:default="2006-01-02T15:04:05Z07:00" | ||
Layout string `json:"layout,omitempty" protobuf:"bytes,2,opt,name=layout"` | ||
} | ||
|
||
func (in Cron) GenURN(cluster, namespace string) string { | ||
return fmt.Sprintf("urn:dataflow:cron:%s", in.Schedule) | ||
} |
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,12 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCron_GenURN(t *testing.T) { | ||
urn := Cron{Schedule: "* * * * *"}.GenURN(cluster, namespace) | ||
assert.Equal(t, "urn:dataflow:cron:* * * * *", urn) | ||
} |
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,22 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func TestDatabase_GenURN(t *testing.T) { | ||
t.Run("Value", func(t *testing.T) { | ||
urn := Database{DataSource: &DBDataSource{Value: "my-value"}}.GenURN(cluster, namespace) | ||
assert.Equal(t, "urn:dataflow:db:my-value", urn) | ||
}) | ||
t.Run("ValueFrom", func(t *testing.T) { | ||
urn := Database{DataSource: &DBDataSource{ValueFrom: &DBDataSourceFrom{SecretKeyRef: &corev1.SecretKeySelector{ | ||
LocalObjectReference: corev1.LocalObjectReference{Name: "my-name"}, | ||
Key: "my-key", | ||
}}}}.GenURN(cluster, namespace) | ||
assert.Equal(t, "urn:dataflow:db:my-name.secret.my-ns.my-cluster:my-key", urn) | ||
}) | ||
} |
Oops, something went wrong.