Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions config/core/deployments/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: CONTROLLER_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: CONTROLLER_UID
valueFrom:
fieldRef:
fieldPath: metadata.uid
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The downward API populates these with Pod values, so this PR is setting up bad owner references and Kubernetes GC will randomly delete the deployments as a result. We hit a similar issue with bad owner references in the webhook several months ago.

I believe @duglin was also just seeing a similar bad behavior in a separate context, and @markusthoemmes got bitten by this a month or two ago.

- name: CONFIG_LOGGING_NAME
value: config-logging
- name: CONFIG_OBSERVABILITY_NAME
Expand Down
4 changes: 4 additions & 0 deletions pkg/reconciler/pingsource/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ import (
type envConfig struct {
Image string `envconfig:"PING_IMAGE" required:"true"`
MTImage string `envconfig:"MT_PING_IMAGE" required:"true"`

// Add this for validation purpose only of validation.
ControllerName string `envconfig:"CONTROLLER_NAME" required:"true"`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these for?

ControllerUID string `envconfig:"CONTROLLER_UID" required:"true"`
}

// NewController initializes the controller and is called by the generated code
Expand Down
12 changes: 12 additions & 0 deletions pkg/reconciler/pingsource/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,25 @@ func TestNew(t *testing.T) {
if err := os.Setenv("PING_IMAGE", "anything"); err != nil {
t.Fatalf("Failed to set env var: %v", err)
}
if err := os.Setenv("CONTROLLER_NAME", "anything"); err != nil {
t.Fatalf("Failed to set env var: %v", err)
}
if err := os.Setenv("CONTROLLER_UID", "anything"); err != nil {
t.Fatalf("Failed to set env var: %v", err)
}
if err := os.Setenv("MT_PING_IMAGE", "anything"); err != nil {
t.Fatalf("Failed to set env var: %v", err)
}
defer func() {
if err := os.Unsetenv("PING_IMAGE"); err != nil {
t.Fatalf("Failed to unset env var: %v", err)
}
if err := os.Unsetenv("CONTROLLER_NAME"); err != nil {
t.Fatalf("Failed to unset env var: %v", err)
}
if err := os.Unsetenv("CONTROLLER_UID"); err != nil {
t.Fatalf("Failed to unset env var: %v", err)
}
if err := os.Unsetenv("MT_PING_IMAGE"); err != nil {
t.Fatalf("Failed to unset env var: %v", err)
}
Expand Down
16 changes: 15 additions & 1 deletion pkg/reconciler/pingsource/resources/mt_receive_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ limitations under the License.
package resources

import (
"os"

v1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"k8s.io/apimachinery/pkg/types"
"knative.dev/pkg/system"
)

Expand All @@ -41,6 +43,8 @@ type MTArgs struct {
// MakeMTReceiveAdapter generates the mtping deployment for pingsources
func MakeMTReceiveAdapter(args MTArgs) *v1.Deployment {
replicas := int32(1)
blockOwnerDeletion := true
isController := true

return &v1.Deployment{
TypeMeta: metav1.TypeMeta{
Expand All @@ -50,6 +54,16 @@ func MakeMTReceiveAdapter(args MTArgs) *v1.Deployment {
ObjectMeta: metav1.ObjectMeta{
Namespace: system.Namespace(),
Name: args.MTAdapterName,
OwnerReferences: []metav1.OwnerReference{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting the owner ref to the controller deployment seems like a bug to me, this means that the dataplane and control plane lifecycles are tied together and an upgrade of the control plane takes down the dataplane.

{
APIVersion: v1.SchemeGroupVersion.String(),
Kind: "Deployment",
Name: os.Getenv("CONTROLLER_NAME"), // guarantee to be non-empty
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have already pulled this out of the environment, you should pass that var down so it is not also pulled from the env here.

UID: types.UID(os.Getenv("CONTROLLER_UID")), // guarantee to be non-empty
Controller: &isController,
BlockOwnerDeletion: &blockOwnerDeletion,
},
},
},
Spec: v1.DeploymentSpec{
Replicas: &replicas,
Expand Down
10 changes: 10 additions & 0 deletions pkg/reconciler/pingsource/resources/mt_receive_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (

func TestMakeMTPingAdapter(t *testing.T) {
replicas := int32(1)
blockOwnerDeletion := true
isController := true

args := MTArgs{
ServiceAccountName: "test-sa",
Expand All @@ -45,6 +47,14 @@ func TestMakeMTPingAdapter(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Namespace: system.Namespace(),
Name: args.MTAdapterName,
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "apps/v1",
Kind: "Deployment",
Controller: &isController,
BlockOwnerDeletion: &blockOwnerDeletion,
},
},
},
Spec: v1.DeploymentSpec{
Replicas: &replicas,
Expand Down