Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(projects.deploykey): Add nil check before pointer deref for CreatedAt in controller #95

Merged
merged 1 commit into from
Aug 10, 2023
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
10 changes: 10 additions & 0 deletions pkg/clients/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ package clients

import (
"context"
"time"

"github.com/google/go-cmp/cmp"
"github.com/pkg/errors"
gitlab "github.com/xanzy/go-gitlab"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -209,3 +211,11 @@ func IsResponseNotFound(res *gitlab.Response) bool {
}
return false
}

// TimeToMetaTime returns nil if parameter is nil, otherwise metav1.Time value
func TimeToMetaTime(t *time.Time) *metav1.Time {
if t == nil {
return nil
}
return &metav1.Time{Time: *t}
}
3 changes: 1 addition & 2 deletions pkg/controller/projects/deploykeys/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/xanzy/go-gitlab"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
controller "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -118,7 +117,7 @@ func (e *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex

cr.Status.AtProvider = v1alpha1.DeployKeyObservation{
ID: &dk.ID,
CreatedAt: &metav1.Time{Time: *dk.CreatedAt},
CreatedAt: clients.TimeToMetaTime(dk.CreatedAt),
}

cr.Status.SetConditions(xpv1.Available())
Expand Down
Loading