Skip to content

Commit

Permalink
store namespace in configpod status name
Browse files Browse the repository at this point in the history
Signed-off-by: Avinash Patnala <avinashpatnala@google.com>
  • Loading branch information
Avinash Patnala committed Oct 1, 2024
1 parent ad53e9e commit ef2c85a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
8 changes: 4 additions & 4 deletions apis/status/v1beta1/configpodstatus_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func init() {
// NewConfigStatusForPod returns an config status object
// that has been initialized with the bare minimum of fields to make it functional
// with the config status controller.
func NewConfigStatusForPod(pod *corev1.Pod, configName string, scheme *runtime.Scheme) (*ConfigPodStatus, error) {
func NewConfigStatusForPod(pod *corev1.Pod, configNamespace string, configName string, scheme *runtime.Scheme) (*ConfigPodStatus, error) {
obj := &ConfigPodStatus{}
name, err := KeyForConfig(pod.Name, configName)
name, err := KeyForConfig(pod.Name, configNamespace, configName)
if err != nil {
return nil, err
}
Expand All @@ -81,6 +81,6 @@ func NewConfigStatusForPod(pod *corev1.Pod, configName string, scheme *runtime.S

// KeyForConfig returns a unique status object name given the Pod ID and
// a config object.
func KeyForConfig(id string, configName string) (string, error) {
return DashPacker(id, configName)
func KeyForConfig(id string, configNamespace string, configName string) (string, error) {
return DashPacker(id, configNamespace, configName)
}
7 changes: 4 additions & 3 deletions apis/status/v1beta1/configpodstatus_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func TestNewConfigStatusForPod(t *testing.T) {
const podName = "some-gk-pod"
const podNS = "a-gk-namespace"
const configName = "a-config"
const configNameSpace = "a-gk-ns"

testutils.Setenv(t, "POD_NAMESPACE", podNS)

Expand All @@ -37,7 +38,7 @@ func TestNewConfigStatusForPod(t *testing.T) {
)

expectedStatus := &v1beta1.ConfigPodStatus{}
expectedStatus.SetName("some--gk--pod-a--config")
expectedStatus.SetName("some--gk--pod-a--gk--ns-a--config")
expectedStatus.SetNamespace(podNS)
expectedStatus.Status.ID = podName
expectedStatus.Status.Operations = operations.AssignedStringList()
Expand All @@ -51,14 +52,14 @@ func TestNewConfigStatusForPod(t *testing.T) {
t.Fatal(err)
}

status, err := v1beta1.NewConfigStatusForPod(pod, configName, scheme)
status, err := v1beta1.NewConfigStatusForPod(pod, configNameSpace, configName, scheme)
if err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(expectedStatus, status); diff != "" {
t.Fatal(diff)
}
n, err := v1beta1.KeyForConfig(podName, configName)
n, err := v1beta1.KeyForConfig(podName, configNameSpace, configName)
if err != nil {
t.Fatal(err)
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/controller/config/config_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,18 @@ func (r *ReconcileConfig) Reconcile(ctx context.Context, request reconcile.Reque
r.tracker.For(configGVK).Observe(instance)

if deleted {
return reconcile.Result{}, r.deleteStatus(ctx, request.NamespacedName.Name)
return reconcile.Result{}, r.deleteStatus(ctx, request.NamespacedName.Namespace, request.NamespacedName.Name)
}
return reconcile.Result{}, r.updateOrCreatePodStatus(ctx, instance, err)
}

func (r *ReconcileConfig) deleteStatus(ctx context.Context, cfgName string) error {
func (r *ReconcileConfig) deleteStatus(ctx context.Context, cfgNamespace string, cfgName string) error {
status := &statusv1beta1.ConfigPodStatus{}
pod, err := r.getPod(ctx)
if err != nil {
return fmt.Errorf("getting reconciler pod: %w", err)
}
sName, err := statusv1beta1.KeyForConfig(pod.Name, cfgName)
sName, err := statusv1beta1.KeyForConfig(pod.Name, cfgNamespace, cfgName)
if err != nil {
return fmt.Errorf("getting key for config: %w", err)
}
Expand All @@ -252,7 +252,7 @@ func (r *ReconcileConfig) updateOrCreatePodStatus(ctx context.Context, cfg *conf

// Check if it exists already
sNS := pod.Namespace
sName, err := statusv1beta1.KeyForConfig(pod.Name, cfg.GetName())
sName, err := statusv1beta1.KeyForConfig(pod.Name, cfg.GetNamespace(), cfg.GetName())
if err != nil {
return fmt.Errorf("getting key for config: %w", err)
}
Expand Down Expand Up @@ -282,7 +282,7 @@ func (r *ReconcileConfig) updateOrCreatePodStatus(ctx context.Context, cfg *conf
}

func (r *ReconcileConfig) newConfigStatus(pod *corev1.Pod, cfg *configv1alpha1.Config) (*statusv1beta1.ConfigPodStatus, error) {
status, err := statusv1beta1.NewConfigStatusForPod(pod, cfg.GetName(), r.scheme)
status, err := statusv1beta1.NewConfigStatusForPod(pod, cfg.GetNamespace(), cfg.GetName(), r.scheme)
if err != nil {
return nil, fmt.Errorf("creating status for pod: %w", err)
}
Expand Down

0 comments on commit ef2c85a

Please sign in to comment.