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

chore: upgrade to 1.21 #794

Merged
merged 4 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion .github/workflows/gotest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

env:
# this must match the version in go.mod
GO_SVR: 1.20.10
GO_SVR: 1.21.9

jobs:
commit:
Expand Down
2 changes: 1 addition & 1 deletion build/RedHat.dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM registry.access.redhat.com/ubi9/go-toolset:1.20 as build
FROM registry.access.redhat.com/ubi9/go-toolset:1.21 as build
USER 0
RUN mkdir /build
WORKDIR /build
Expand Down
2 changes: 1 addition & 1 deletion cmd/spec/example_reservation.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/RHEnVision/provisioning-backend/internal/ptr"
)

var ReservationTime time.Time = MustParseTime("2013-05-13T19:20:25Z")
var ReservationTime = MustParseTime("2013-05-13T19:20:25Z")
Copy link
Member Author

Choose a reason for hiding this comment

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

There are couple of changes like this, I did not pay attention and IDE fixed these for me. These are not relevant, will not hurt I guess.

Copy link
Member

Choose a reason for hiding this comment

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

I like it, that's the way C++ headed last time I lookes as well, no useless explicity :)


func MustParseTime(t string) time.Time {
result, err := time.Parse(time.RFC3339, t)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/RHEnVision/provisioning-backend

// Also change: mk/tools.mk .github/workflows build/Dockerfile
go 1.20
go 1.21

require (
cloud.google.com/go/compute v1.25.0
Expand Down
28 changes: 28 additions & 0 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/cache/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var (

// Forever is used for items that should be cached "forever". Expiration of 30 days
// is used to allow cleanup of unused items.
const Forever time.Duration = 24 * time.Hour * 30
const Forever = 24 * time.Hour * 30

type Cacheable interface {
CacheKeyName() string
Expand Down
1 change: 0 additions & 1 deletion internal/cache/tests/main_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build integration
// +build integration

// To override application configuration for integration tests, create config/test.env file.
package tests
Expand Down
1 change: 0 additions & 1 deletion internal/cache/tests/redis_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build integration
// +build integration

package tests

Expand Down
10 changes: 10 additions & 0 deletions internal/clients/http/azure/0init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build !test

package azure

import "github.com/RHEnVision/provisioning-backend/internal/clients"

func init() {
clients.GetAzureClient = newAzureClient
clients.GetServiceAzureClient = newServiceClient
}
4 changes: 0 additions & 4 deletions internal/clients/http/azure/azure_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ type client struct {
credential *azidentity.ClientSecretCredential
}

func init() {
clients.GetAzureClient = newAzureClient
}

func newAzureClient(ctx context.Context, auth *clients.Authentication) (clients.Azure, error) {
opts := azidentity.ClientSecretCredentialOptions{}
identityClient, err := azidentity.NewClientSecretCredential(config.Azure.TenantID, config.Azure.ClientID, config.Azure.ClientSecret, &opts)
Expand Down
4 changes: 0 additions & 4 deletions internal/clients/http/azure/azure_service_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ type serviceClient struct {
credential *azidentity.ClientSecretCredential
}

func init() {
clients.GetServiceAzureClient = newServiceClient
}

func newServiceClient(ctx context.Context) (clients.ServiceAzure, error) {
opts := azidentity.ClientSecretCredentialOptions{}
identityClient, err := azidentity.NewClientSecretCredential(config.Azure.TenantID, config.Azure.ClientID, config.Azure.ClientSecret, &opts)
Expand Down
10 changes: 10 additions & 0 deletions internal/clients/http/ec2/0init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build !test

package ec2

import "github.com/RHEnVision/provisioning-backend/internal/clients"

func init() {
clients.GetEC2Client = newAssumedEC2ClientWithRegion
clients.GetServiceEC2Client = newEC2ClientWithRegion
}
5 changes: 0 additions & 5 deletions internal/clients/http/ec2/ec2_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ type ec2Client struct {
assumed bool
}

func init() {
clients.GetEC2Client = newAssumedEC2ClientWithRegion
clients.GetServiceEC2Client = newEC2ClientWithRegion
}

func logger(ctx context.Context) *zerolog.Logger {
logger := zerolog.Ctx(ctx).With().Str("client", "ec2").Logger()
return &logger
Expand Down
10 changes: 10 additions & 0 deletions internal/clients/http/gcp/0init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build !test

package gcp

import "github.com/RHEnVision/provisioning-backend/internal/clients"

func init() {
clients.GetGCPClient = newGCPClient
clients.GetServiceGCPClient = newServiceGCPClient
}
4 changes: 0 additions & 4 deletions internal/clients/http/gcp/gcp_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ type gcpClient struct {
options []option.ClientOption
}

func init() {
clients.GetGCPClient = newGCPClient
}

// GCP SDK does not provide a single client, so only configuration can be shared and
// clients need to be created and closed in each function.
// The difference between the customer and service authentication is which Project ID was given: the service or the customer
Expand Down
6 changes: 1 addition & 5 deletions internal/clients/http/gcp/gcp_service_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ type gcpServiceClient struct {
options []option.ClientOption
}

func init() {
clients.GetServiceGCPClient = newServiceGCPClient
}

func newServiceGCPClient(ctx context.Context) (clients.ServiceGCP, error) {
options := []option.ClientOption{
option.WithCredentialsJSON([]byte(config.GCP.JSON)),
Expand Down Expand Up @@ -161,6 +157,6 @@ func getTotalStorage(disks []*computepb.ScratchDisks) int64 {
}

func mbToMib(mb float32) int64 {
var mib float32 = mb * 0.9536
mib := mb * 0.9536
return int64(mib)
}
9 changes: 9 additions & 0 deletions internal/clients/http/image_builder/0init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build !test

package image_builder

import "github.com/RHEnVision/provisioning-backend/internal/clients"

func init() {
clients.GetImageBuilderClient = newImageBuilderClient
}
4 changes: 0 additions & 4 deletions internal/clients/http/image_builder/image_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ type ibClient struct {
client *ClientWithResponses
}

func init() {
clients.GetImageBuilderClient = newImageBuilderClient
}

func logger(ctx context.Context) zerolog.Logger {
return zerolog.Ctx(ctx).With().Str("client", "ib").Logger()
}
Expand Down
9 changes: 9 additions & 0 deletions internal/clients/http/rbac/0init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build !test

package rbac

import "github.com/RHEnVision/provisioning-backend/internal/clients"

func init() {
clients.GetRbacClient = newClient
}
4 changes: 0 additions & 4 deletions internal/clients/http/rbac/rbac_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ type rbac struct {
client *ClientWithResponses
}

func init() {
clients.GetRbacClient = newClient
}

func logger(ctx context.Context) zerolog.Logger {
return zerolog.Ctx(ctx).With().Str("client", "ib").Logger()
}
Expand Down
9 changes: 9 additions & 0 deletions internal/clients/http/sources/0init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build !test

package sources

import "github.com/RHEnVision/provisioning-backend/internal/clients"

func init() {
clients.GetSourcesClient = newSourcesClient
}
4 changes: 0 additions & 4 deletions internal/clients/http/sources/sources_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ type sourcesClient struct {
client *ClientWithResponses
}

func init() {
clients.GetSourcesClient = newSourcesClient
}

func logger(ctx context.Context) zerolog.Logger {
return zerolog.Ctx(ctx).With().Str("client", "sources").Logger()
}
Expand Down
28 changes: 21 additions & 7 deletions internal/clients/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ type AzureResourceGroup struct {

// GetSourcesClient returns Sources interface implementation. There are currently
// two implementations available: HTTP and stub
var GetSourcesClient func(ctx context.Context) (Sources, error)
var GetSourcesClient = func(ctx context.Context) (Sources, error) {
panic("client func not initialized")
}

// Sources interface provides access to the Sources backend service API
type Sources interface {
Expand All @@ -34,7 +36,9 @@ type Sources interface {

// GetImageBuilderClient returns ImageBuilder interface implementation. There are currently
// two implementations available: HTTP and stub
var GetImageBuilderClient func(ctx context.Context) (ImageBuilder, error)
var GetImageBuilderClient = func(ctx context.Context) (ImageBuilder, error) {
panic("client func not initialized")
}

// ImageBuilder interface provides access to the Image Builder backend service API
type ImageBuilder interface {
Expand Down Expand Up @@ -62,10 +66,14 @@ type ClientStatuser interface {
}

// GetEC2Client returns an EC2 facade interface with assumed role.
var GetEC2Client func(ctx context.Context, auth *Authentication, region string) (EC2, error)
var GetEC2Client = func(ctx context.Context, auth *Authentication, region string) (EC2, error) {
panic("client func not initialized")
}

// GetServiceEC2Client returns an EC2 client for the service account.
var GetServiceEC2Client func(ctx context.Context, region string) (EC2, error)
var GetServiceEC2Client = func(ctx context.Context, region string) (EC2, error) {
panic("client func not initialized")
}

type EC2 interface {
ClientStatuser
Expand Down Expand Up @@ -106,10 +114,14 @@ type EC2 interface {
}

// GetAzureClient returns an Azure client with customer's subscription ID.
var GetAzureClient func(ctx context.Context, auth *Authentication) (Azure, error)
var GetAzureClient = func(ctx context.Context, auth *Authentication) (Azure, error) {
panic("client func not initialized")
}

// GetServiceAzureClient returns an Azure client for the service account itself.
var GetServiceAzureClient func(ctx context.Context) (ServiceAzure, error)
var GetServiceAzureClient = func(ctx context.Context) (ServiceAzure, error) {
panic("client func not initialized")
}

type Azure interface {
ClientStatuser
Expand All @@ -132,7 +144,9 @@ type ServiceAzure interface {
}

// GetGCPClient returns a GCP facade interface.
var GetGCPClient func(ctx context.Context, auth *Authentication) (GCP, error)
var GetGCPClient = func(ctx context.Context, auth *Authentication) (GCP, error) {
panic("client func not initialized")
}

// GetServiceGCPClient returns a GCP client for the service account.
var GetServiceGCPClient func(ctx context.Context) (ServiceGCP, error)
Expand Down
2 changes: 1 addition & 1 deletion internal/clients/regional_availability.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewRegionalInstanceTypes() *RegionalTypeAvailability {
}
}

var ErrUnknownRegionZoneCombination error = errors.New("unknown region and zone combination")
var ErrUnknownRegionZoneCombination = errors.New("unknown region and zone combination")

func key(region, zone string) string {
if zone == "" {
Expand Down
16 changes: 16 additions & 0 deletions internal/clients/stubs/0init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//go:build test

package stubs

import "github.com/RHEnVision/provisioning-backend/internal/clients"

func init() {
clients.GetAzureClient = getAzureClient
clients.GetEC2Client = newEC2CustomerClientStubWithRegion
clients.GetServiceEC2Client = newEC2ServiceClientStubWithRegion
clients.GetGCPClient = newGCPCustomerClientStub
clients.GetServiceGCPClient = getServiceGCPClientStub
clients.GetImageBuilderClient = getImageBuilderClientStub
clients.GetRbacClient = getRbacClient
clients.GetSourcesClient = getSourcesClient
}
4 changes: 0 additions & 4 deletions internal/clients/stubs/context_getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ type ctxKeyType int

const azureCtxKey ctxKeyType = iota

func init() {
clients.GetAzureClient = getAzureClient
}

func WithAzureClient(parent context.Context) context.Context {
ctx := context.WithValue(parent, azureCtxKey, &AzureClientStub{})
return ctx
Expand Down
5 changes: 0 additions & 5 deletions internal/clients/stubs/ec2_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ type EC2ClientStub struct {
Imported []*types.KeyPairInfo
}

func init() {
clients.GetEC2Client = newEC2CustomerClientStubWithRegion
clients.GetServiceEC2Client = newEC2ServiceClientStubWithRegion
}

func WithEC2Client(parent context.Context) context.Context {
ctx := context.WithValue(parent, ec2CtxKey, &EC2ClientStub{})
return ctx
Expand Down
5 changes: 0 additions & 5 deletions internal/clients/stubs/gcp_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ type (
GCPServiceClientStub struct{}
)

func init() {
clients.GetGCPClient = newGCPCustomerClientStub
clients.GetServiceGCPClient = getServiceGCPClientStub
}

func newGCPCustomerClientStub(ctx context.Context, auth *clients.Authentication) (clients.GCP, error) {
return getCustomerGCPClientStub(ctx, auth)
}
Expand Down
4 changes: 0 additions & 4 deletions internal/clients/stubs/image_builder_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ var imageBuilderCtxKey imageBuilderCtxKeyType = "image-builder-interface"

type ImageBuilderClientStub struct{}

func init() {
clients.GetImageBuilderClient = getImageBuilderClientStub
}

func WithImageBuilderClient(parent context.Context) context.Context {
ctx := context.WithValue(parent, imageBuilderCtxKey, &ImageBuilderClientStub{})
return ctx
Expand Down
4 changes: 0 additions & 4 deletions internal/clients/stubs/rbac_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import (

type rbacClient struct{}

func init() {
clients.GetRbacClient = getRbacClient
}

func getRbacClient(ctx context.Context) clients.Rbac {
return rbacClient{}
}
Expand Down
6 changes: 0 additions & 6 deletions internal/clients/stubs/sources_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ type SourcesClientStub struct {
auths map[string]*clients.Authentication
}

func init() {
// We are currently using SourcesClientStub
clients.GetSourcesClient = getSourcesClient
}

// SourcesClient
func WithSourcesClient(parent context.Context) context.Context {
ctx := context.WithValue(parent, sourcesCtxKey, &SourcesClientStub{auths: make(map[string]*clients.Authentication)})
return ctx
Expand Down
1 change: 0 additions & 1 deletion internal/config/override_integration.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build integration && !test
// +build integration,!test

package config

Expand Down
1 change: 0 additions & 1 deletion internal/config/override_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build test && !integration
// +build test,!integration

package config

Expand Down
Loading
Loading