-
Notifications
You must be signed in to change notification settings - Fork 592
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
44 changed files
with
3,556 additions
and
2 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
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 @@ | ||
core/resources/containersource.yaml |
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,62 @@ | ||
# Copyright 2020 The Knative Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
apiVersion: apiextensions.k8s.io/v1beta1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
labels: | ||
eventing.knative.dev/release: devel | ||
eventing.knative.dev/source: "true" | ||
duck.knative.dev/source: "true" | ||
knative.dev/crd-install: "true" | ||
name: containersources.sources.knative.dev | ||
spec: | ||
group: sources.knative.dev | ||
names: | ||
categories: | ||
- all | ||
- knative | ||
- eventing | ||
- sources | ||
kind: ContainerSource | ||
plural: containersources | ||
scope: Namespaced | ||
subresources: | ||
status: {} | ||
preserveUnknownFields: false | ||
validation: | ||
openAPIV3Schema: | ||
type: object | ||
# this is a work around so we don't need to flesh out the | ||
# schema for each version at this time | ||
# | ||
# see issue: https://github.com/knative/serving/issues/912 | ||
x-kubernetes-preserve-unknown-fields: true | ||
additionalPrinterColumns: | ||
- name: Ready | ||
type: string | ||
JSONPath: ".status.conditions[?(@.type==\"Ready\")].status" | ||
- name: Reason | ||
type: string | ||
JSONPath: ".status.conditions[?(@.type=='Ready')].reason" | ||
- name: Sink | ||
type: string | ||
JSONPath: ".status.sinkUri" | ||
- name: Age | ||
type: date | ||
JSONPath: .metadata.creationTimestamp | ||
versions: | ||
- name: v1alpha1 | ||
served: true | ||
storage: true |
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
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 @@ | ||
/* | ||
Copyright 2020 The Knative Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
"knative.dev/pkg/apis" | ||
) | ||
|
||
func (s *ContainerSource) SetDefaults(ctx context.Context) { | ||
withName := apis.WithinParent(ctx, s.ObjectMeta) | ||
s.Spec.SetDefaults(withName) | ||
} | ||
|
||
func (ss *ContainerSourceSpec) SetDefaults(ctx context.Context) { | ||
containers := make([]corev1.Container, 0, len(ss.Template.Spec.Containers)) | ||
for i, c := range ss.Template.Spec.Containers { | ||
// If the Container specified has no name, then default to "<source_name>_<i>". | ||
if c.Name == "" { | ||
c.Name = fmt.Sprintf("%s-%d", apis.ParentMeta(ctx).Name, i) | ||
} | ||
containers = append(containers, c) | ||
} | ||
ss.Template.Spec.Containers = containers | ||
} |
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,115 @@ | ||
/* | ||
Copyright 2020 The Knative Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// No-op test because method does nothing. | ||
func TestContainerSourceDefaults(t *testing.T) { | ||
testCases := map[string]struct { | ||
initial ContainerSource | ||
expected ContainerSource | ||
}{ | ||
"no container name": { | ||
initial: ContainerSource{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test-name", | ||
Namespace: "test-namespace", | ||
}, | ||
Spec: ContainerSourceSpec{ | ||
Template: corev1.PodTemplateSpec{ | ||
Spec: corev1.PodSpec{ | ||
Containers: []corev1.Container{{ | ||
Image: "test-image", | ||
}}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expected: ContainerSource{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test-name", | ||
Namespace: "test-namespace", | ||
}, | ||
Spec: ContainerSourceSpec{ | ||
Template: corev1.PodTemplateSpec{ | ||
Spec: corev1.PodSpec{ | ||
Containers: []corev1.Container{{ | ||
Name: "test-name-0", | ||
Image: "test-image", | ||
}}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"one with ontainer name one without": { | ||
initial: ContainerSource{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test-name", | ||
Namespace: "test-namespace", | ||
}, | ||
Spec: ContainerSourceSpec{ | ||
Template: corev1.PodTemplateSpec{ | ||
Spec: corev1.PodSpec{ | ||
Containers: []corev1.Container{{ | ||
Name: "test-container", | ||
Image: "test-image", | ||
}, { | ||
Image: "test-another-image", | ||
}}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expected: ContainerSource{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test-name", | ||
Namespace: "test-namespace", | ||
}, | ||
Spec: ContainerSourceSpec{ | ||
Template: corev1.PodTemplateSpec{ | ||
Spec: corev1.PodSpec{ | ||
Containers: []corev1.Container{{ | ||
Name: "test-container", | ||
Image: "test-image", | ||
}, { | ||
Name: "test-name-1", | ||
Image: "test-another-image", | ||
}}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
for n, tc := range testCases { | ||
t.Run(n, func(t *testing.T) { | ||
tc.initial.SetDefaults(context.Background()) | ||
if diff := cmp.Diff(tc.expected, tc.initial); diff != "" { | ||
t.Fatalf("Unexpected defaults (-want, +got): %s", diff) | ||
} | ||
}) | ||
} | ||
} |
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,86 @@ | ||
/* | ||
Copyright 2020 The Knative Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
appsv1 "k8s.io/api/apps/v1" | ||
"knative.dev/eventing/pkg/apis/duck" | ||
"knative.dev/pkg/apis" | ||
) | ||
|
||
const ( | ||
// ContainerSourceConditionReady has status True when the ContainerSource is ready to send events. | ||
ContainerConditionReady = apis.ConditionReady | ||
|
||
// ContainerConditionSinkProvided has status True when the ContainerSource has been configured with a sink target. | ||
ContainerConditionSinkProvided apis.ConditionType = "SinkProvided" | ||
|
||
// ContainerConditionDeployed has status True when the ContainerSource has had it's deployment created. | ||
ContainerConditionDeployed apis.ConditionType = "Deployed" | ||
) | ||
|
||
var containerCondSet = apis.NewLivingConditionSet( | ||
ContainerConditionSinkProvided, | ||
ContainerConditionDeployed, | ||
) | ||
|
||
// GetCondition returns the condition currently associated with the given type, or nil. | ||
func (s *ContainerSourceStatus) GetCondition(t apis.ConditionType) *apis.Condition { | ||
return containerCondSet.Manage(s).GetCondition(t) | ||
} | ||
|
||
// IsReady returns true if the resource is ready overall. | ||
func (s *ContainerSourceStatus) IsReady() bool { | ||
return containerCondSet.Manage(s).IsHappy() | ||
} | ||
|
||
// InitializeConditions sets relevant unset conditions to Unknown state. | ||
func (s *ContainerSourceStatus) InitializeConditions() { | ||
containerCondSet.Manage(s).InitializeConditions() | ||
} | ||
|
||
// MarkSink sets the condition that the source has a sink configured. | ||
func (s *ContainerSourceStatus) MarkSink(uri *apis.URL) { | ||
s.SinkURI = uri | ||
if !uri.IsEmpty() { | ||
containerCondSet.Manage(s).MarkTrue(ContainerConditionSinkProvided) | ||
} else { | ||
containerCondSet.Manage(s).MarkFalse(ContainerConditionSinkProvided, "SinkEmpty", "Sink has resolved to empty.%s", "") | ||
} | ||
} | ||
|
||
// MarkNoSink sets the condition that the source does not have a sink configured. | ||
func (s *ContainerSourceStatus) MarkNoSink(reason, messageFormat string, messageA ...interface{}) { | ||
containerCondSet.Manage(s).MarkFalse(ContainerConditionSinkProvided, reason, messageFormat, messageA...) | ||
} | ||
|
||
// PropagateDeploymentAvailability uses the availability of the provided Deployment to determine if | ||
// ContainerConditionDeployed should be marked as true or false. | ||
func (s *ContainerSourceStatus) PropagateDeploymentAvailability(d *appsv1.Deployment) { | ||
if duck.DeploymentIsAvailable(&d.Status, false) { | ||
containerCondSet.Manage(s).MarkTrue(ContainerConditionDeployed) | ||
} else { | ||
// I don't know how to propagate the status well, so just give the name of the Deployment | ||
// for now. | ||
containerCondSet.Manage(s).MarkFalse(ContainerConditionDeployed, "DeploymentUnavailable", "The Deployment '%s' is unavailable.", d.Name) | ||
} | ||
} | ||
|
||
// MarkNotDeployed sets the condition that the source has not been deployed. | ||
func (s *ContainerSourceStatus) MarkNotDeployed(reason, messageFormat string, messageA ...interface{}) { | ||
containerCondSet.Manage(s).MarkFalse(ContainerConditionDeployed, reason, messageFormat, messageA...) | ||
} |
Oops, something went wrong.