Skip to content
Draft
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: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
with:
submodules: true
- name: Setup Go
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Find the Go Build Cache
Expand Down Expand Up @@ -74,7 +74,7 @@ jobs:
with:
submodules: true
- name: Setup Go
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Install goimports
Expand Down Expand Up @@ -110,7 +110,7 @@ jobs:
- name: Fetch History
run: git fetch --prune --unshallow
- name: Setup Go
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Find the Go Build Cache
Expand All @@ -133,7 +133,7 @@ jobs:
- name: Run Unit Tests
run: make -j2 test
- name: Publish Unit Test Coverage
uses: codecov/codecov-action@fdcc8476540edceab3de004e990f80d881c6cc00 # v1
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v1
with:
flags: unittests
file: _output/tests/linux_amd64/coverage.txt
Expand All @@ -149,7 +149,7 @@ jobs:
- name: Fetch History
run: git fetch --prune --unshallow
- name: Setup Go
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Find the Go Build Cache
Expand Down
2 changes: 1 addition & 1 deletion cluster/images/provider-upjet-github/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine:3.19.1
FROM alpine:3.22.1
RUN apk --no-cache add ca-certificates bash

ARG TARGETOS
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/crossplane-contrib/provider-upjet-github

go 1.23.0
go 1.23.12

require (
dario.cat/mergo v1.0.2
Expand Down
37 changes: 23 additions & 14 deletions internal/clients/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@
RetryableErrors []int `json:"retryable_errors,omitempty"`
}

type githubCredentialCache struct {
configName *terraform.Setup
cachedAt time.Time
}

// setCredentialConfigs will add credential type fields (Owner, Token, AppAuth) to terraform providerConfiguration
func setCredentialConfigs(creds githubConfig, cnf terraform.ProviderConfiguration) (terraform.ProviderConfiguration, error) {
if creds.Owner != nil {
Expand Down Expand Up @@ -144,13 +139,28 @@

}

// The terraform provider currently doesn't refresh installation tokens automatically
// Therefore, the terraform provider config needs to be refreshed at least every hour
// Once this PR is merged to terraform provider, the cache expiry can be removed
// https://github.com/integrations/terraform-provider-github/pull/2695

type CachedTerraformSetup struct {
setup *terraform.Setup
expiry time.Time
}

const (
tfSetupCacheTTL = time.Minute * 55
)

// TerraformSetupBuilder builds Terraform a terraform.SetupFn function which returns Terraform provider setup configuration
//
//gocyclo:ignore
func TerraformSetupBuilder(tfProvider *schema.Provider) terraform.SetupFn {
var tfSetupLock sync.RWMutex
tfSetups := make(map[string]*githubCredentialCache)
tfSetups := make(map[string]CachedTerraformSetup)


Check failure on line 163 in internal/clients/github.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (gofmt)
return func(ctx context.Context, client client.Client, mg resource.Managed) (terraform.Setup, error) {
ps := terraform.Setup{}

Expand All @@ -159,17 +169,13 @@
return ps, errors.New(errNoProviderConfig)
}

tokenValidDuration, err := time.ParseDuration("45m")
if err != nil {
return ps, err
}

tfSetupLock.Lock()
defer tfSetupLock.Unlock()

tfSetup, ok := tfSetups[configRef.Name]
if ok && time.Since(tfSetup.cachedAt) < tokenValidDuration {
return *tfSetup.configName, nil
if ok && tfSetup.expiry.After(time.Now()) {
return *tfSetup.setup, nil

}

pc := &v1beta1.ProviderConfig{}
Expand Down Expand Up @@ -204,7 +210,10 @@
return ps, errors.Wrap(err, "failed to configure the Terraform Github provider meta")
}

tfSetups[configRef.Name] = &githubCredentialCache{&ps, time.Now()}
tfSetups[configRef.Name] = CachedTerraformSetup{
setup: &ps,
expiry: time.Now().Add(tfSetupCacheTTL),
}

return ps, nil

Expand Down
Loading