Skip to content
This repository has been archived by the owner on Jun 19, 2022. It is now read-only.

Commit

Permalink
[master] Auto-update dependencies (#722)
Browse files Browse the repository at this point in the history
Produced via:
  `./hack/update-deps.sh --upgrade && ./hack/update-codegen.sh`
/assign grantr nachocano
/cc grantr nachocano
  • Loading branch information
mattmoor authored Mar 27, 2020
1 parent f1babc0 commit 67fa2fe
Show file tree
Hide file tree
Showing 38 changed files with 1,086 additions and 23 deletions.
10 changes: 5 additions & 5 deletions Gopkg.lock

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

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

6 changes: 6 additions & 0 deletions vendor/knative.dev/eventing/pkg/apis/sources/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,10 @@ var (
Group: GroupName,
Resource: "sinkbindings",
}

// ContainerSourceResource respresents a Knative Eventing Sources ContainerSource
ContainerSourceResource = schema.GroupResource{
Group: GroupName,
Resource: "containersources",
}
)
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 v1alpha2

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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
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 v1alpha2

import (
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"knative.dev/eventing/pkg/apis/duck"
"knative.dev/pkg/apis"
)

const (
// ContainerSourceConditionReady has status True when the ContainerSource is ready to send events.
ContainerSourceConditionReady = apis.ConditionReady

// ContainerSourceConditionSinkBindingReady has status True when the ContainerSource's SinkBinding is ready.
ContainerSourceConditionSinkBindingReady apis.ConditionType = "SinkBindingReady"

// ContainerSourceConditionReceiveAdapterReady has status True when the ContainerSource's ReceiveAdapter is ready.
ContainerSourceConditionReceiveAdapterReady apis.ConditionType = "ReceiveAdapterReady"
)

var containerCondSet = apis.NewLivingConditionSet(
ContainerSourceConditionSinkBindingReady,
ContainerSourceConditionReceiveAdapterReady,
)

// 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()
}

// PropagateSinkBindingStatus uses the availability of the provided Deployment to determine if
// ContainerSourceConditionSinkBindingReady should be marked as true, false or unknown.
func (s *ContainerSourceStatus) PropagateSinkBindingStatus(status *SinkBindingStatus) {
// Do not copy conditions nor observedGeneration
conditions := s.Conditions
observedGeneration := s.ObservedGeneration
s.SourceStatus = status.SourceStatus
s.Conditions = conditions
s.ObservedGeneration = observedGeneration

cond := status.GetCondition(apis.ConditionReady)
switch {
case cond == nil:
containerCondSet.Manage(s).MarkUnknown(ContainerSourceConditionSinkBindingReady, "", "")
case cond.Status == corev1.ConditionTrue:
containerCondSet.Manage(s).MarkTrue(ContainerSourceConditionSinkBindingReady)
case cond.Status == corev1.ConditionFalse:
containerCondSet.Manage(s).MarkFalse(ContainerSourceConditionSinkBindingReady, cond.Reason, cond.Message)
case cond.Status == corev1.ConditionUnknown:
containerCondSet.Manage(s).MarkUnknown(ContainerSourceConditionSinkBindingReady, cond.Reason, cond.Message)
default:
containerCondSet.Manage(s).MarkUnknown(ContainerSourceConditionSinkBindingReady, cond.Reason, cond.Message)
}
}

// PropagateReceiveAdapterStatus uses the availability of the provided Deployment to determine if
// ContainerSourceConditionReceiveAdapterReady should be marked as true or false.
func (s *ContainerSourceStatus) PropagateReceiveAdapterStatus(d *appsv1.Deployment) {
if duck.DeploymentIsAvailable(&d.Status, false) {
containerCondSet.Manage(s).MarkTrue(ContainerSourceConditionReceiveAdapterReady)
} 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(ContainerSourceConditionReceiveAdapterReady, "DeploymentUnavailable", "The Deployment '%s' is unavailable.", d.Name)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
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 v1alpha2

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"knative.dev/pkg/apis"
duckv1 "knative.dev/pkg/apis/duck/v1"
"knative.dev/pkg/kmeta"
)

// +genclient
// +genreconciler
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ContainerSource is the Schema for the containersources API
type ContainerSource struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ContainerSourceSpec `json:"spec,omitempty"`
Status ContainerSourceStatus `json:"status,omitempty"`
}

var (
_ runtime.Object = (*ContainerSource)(nil)
_ kmeta.OwnerRefable = (*ContainerSource)(nil)
_ apis.Validatable = (*ContainerSource)(nil)
_ apis.Defaultable = (*ContainerSource)(nil)
_ apis.HasSpec = (*ContainerSource)(nil)
)

// ContainerSourceSpec defines the desired state of ContainerSource
type ContainerSourceSpec struct {
// inherits duck/v1 SourceSpec, which currently provides:
// * Sink - a reference to an object that will resolve to a domain name or
// a URI directly to use as the sink.
// * CloudEventOverrides - defines overrides to control the output format
// and modifications of the event sent to the sink.
duckv1.SourceSpec `json:",inline"`

// Template describes the pods that will be created
Template corev1.PodTemplateSpec `json:"template"`
}

// GetGroupVersionKind returns the GroupVersionKind.
func (s *ContainerSource) GetGroupVersionKind() schema.GroupVersionKind {
return SchemeGroupVersion.WithKind("ContainerSource")
}

// ContainerSourceStatus defines the observed state of ContainerSource
type ContainerSourceStatus struct {
// inherits duck/v1 SourceStatus, which currently provides:
// * ObservedGeneration - the 'Generation' of the Service that was last
// processed by the controller.
// * Conditions - the latest available observations of a resource's current
// state.
// * SinkURI - the current active sink URI that has been configured for the
// Source.
duckv1.SourceStatus `json:",inline"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ContainerSourceList contains a list of ContainerSource
type ContainerSourceList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ContainerSource `json:"items"`
}

// GetUntypedSpec returns the spec of the ContainerSource.
func (c *ContainerSource) GetUntypedSpec() interface{} {
return c.Spec
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
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 v1alpha2

import (
"context"

corev1 "k8s.io/api/core/v1"
"knative.dev/pkg/apis"
)

func (c *ContainerSource) Validate(ctx context.Context) *apis.FieldError {
return c.Spec.Validate(ctx).ViaField("spec")
}

func (cs *ContainerSourceSpec) Validate(ctx context.Context) *apis.FieldError {
var errs *apis.FieldError
if fe := cs.Sink.Validate(ctx); fe != nil {
errs = errs.Also(fe.ViaField("sink"))
}

// Validate there is at least a container
if cs.Template.Spec.Containers == nil || len(cs.Template.Spec.Containers) == 0 {
fe := apis.ErrMissingField("containers")
errs = errs.Also(fe)
} else {
for i, c := range cs.Template.Spec.Containers {
if ce := isValidContainer(&c); ce != nil {
errs = errs.Also(ce.ViaFieldIndex("containers", i))
}
}
}
return errs
}

func isValidContainer(c *corev1.Container) *apis.FieldError {
var errs *apis.FieldError
if c.Name == "" {
errs = errs.Also(apis.ErrMissingField("name"))
}
if c.Image == "" {
errs = errs.Also(apis.ErrMissingField("image"))
}
return errs
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&PingSourceList{},
&SinkBinding{},
&SinkBindingList{},
&ContainerSource{},
&ContainerSourceList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
Expand Down
Loading

0 comments on commit 67fa2fe

Please sign in to comment.