Skip to content

Commit

Permalink
lca: Limiting the client for pull and newbuilder for lca (#315)
Browse files Browse the repository at this point in the history
This is based on assignment
#299

Signed-off-by: Alexander Chuzhoy <achuzhoy@redhat.com>
  • Loading branch information
achuzhoy authored Apr 4, 2024
1 parent c548f69 commit ed7ca3e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
24 changes: 18 additions & 6 deletions pkg/lca/imagebasedupgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type ImageBasedUpgradeBuilder struct {
// Used in functions that define or mutate the imagebasedupgrade definition.
// errorMsg is processed before the imagebasedupgrade object is created
errorMsg string
apiClient *clients.Settings
apiClient goclient.Client
}

// AdditionalOptions additional options for imagebasedupgrade object.
Expand All @@ -47,8 +47,14 @@ func NewImageBasedUpgradeBuilder(
apiClient *clients.Settings,
name string,
) *ImageBasedUpgradeBuilder {
if apiClient == nil {
glog.V(100).Infof("The apiClient cannot be nil")

return nil
}

builder := ImageBasedUpgradeBuilder{
apiClient: apiClient,
apiClient: apiClient.Client,
Definition: &lcav1alpha1.ImageBasedUpgrade{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Expand Down Expand Up @@ -94,8 +100,14 @@ func (builder *ImageBasedUpgradeBuilder) WithOptions(options ...AdditionalOption
func PullImageBasedUpgrade(apiClient *clients.Settings, name string) (*ImageBasedUpgradeBuilder, error) {
glog.V(100).Infof("Pulling existing imagebasedupgrade name %s from cluster", name)

if apiClient == nil {
glog.V(100).Infof("The apiClient cannot be nil")

return nil, fmt.Errorf("the apiClient is nil")
}

builder := ImageBasedUpgradeBuilder{
apiClient: apiClient,
apiClient: apiClient.Client,
Definition: &lcav1alpha1.ImageBasedUpgrade{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Expand Down Expand Up @@ -147,13 +159,13 @@ func (builder *ImageBasedUpgradeBuilder) Update() (*ImageBasedUpgradeBuilder, er
glog.V(100).Infof("Waiting for imagebasedupgrade %s to finish reconciling",
builder.Definition.Name)

ibu, err := PullImageBasedUpgrade(builder.apiClient, builder.Definition.Name)
ibu, err := builder.Get()
if err != nil {
return false, err
}

if ibu.Object.ObjectMeta.Generation == ibu.Object.Status.ObservedGeneration {
builder.Object = ibu.Object
if ibu.ObjectMeta.Generation == ibu.Status.ObservedGeneration {
builder.Object = ibu

return true, nil
}
Expand Down
18 changes: 15 additions & 3 deletions pkg/lca/seedgenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type SeedGeneratorBuilder struct {
// Used in functions that define or mutate the seedgenerator definition.
// errorMsg is processed before the seedgenerator object is created
errorMsg string
apiClient *clients.Settings
apiClient goclient.Client
}

// SeedGeneratorAdditionalOptions additional options for imagebasedupgrade object.
Expand All @@ -36,8 +36,14 @@ func NewSeedGeneratorBuilder(
apiClient *clients.Settings,
name string,
) *SeedGeneratorBuilder {
if apiClient == nil {
glog.V(100).Infof("The apiClient cannot be nil")

return nil
}

builder := SeedGeneratorBuilder{
apiClient: apiClient,
apiClient: apiClient.Client,
Definition: &lcasgv1alpha1.SeedGenerator{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Expand Down Expand Up @@ -103,8 +109,14 @@ func (builder *SeedGeneratorBuilder) Create() (*SeedGeneratorBuilder, error) {
func PullSeedGenerator(apiClient *clients.Settings, name string) (*SeedGeneratorBuilder, error) {
glog.V(100).Infof("Pulling existing seedgenerator name %s from cluster", name)

if apiClient == nil {
glog.V(100).Infof("The apiClient cannot be nil")

return nil, fmt.Errorf("the apiClient is nil")
}

builder := SeedGeneratorBuilder{
apiClient: apiClient,
apiClient: apiClient.Client,
Definition: &lcasgv1alpha1.SeedGenerator{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Expand Down

0 comments on commit ed7ca3e

Please sign in to comment.