From 3ee96b68c2dd29230fd0f3d5eca8b2485924062c Mon Sep 17 00:00:00 2001 From: Yacine FODIL Date: Tue, 5 Dec 2023 16:40:43 +0100 Subject: [PATCH 01/24] add update terraform provider version action --- .../workflows/update-terraform-provider.yaml | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 .github/workflows/update-terraform-provider.yaml diff --git a/.github/workflows/update-terraform-provider.yaml b/.github/workflows/update-terraform-provider.yaml new file mode 100755 index 0000000..df62df8 --- /dev/null +++ b/.github/workflows/update-terraform-provider.yaml @@ -0,0 +1,51 @@ +name: Update Terraform Provider + +on: + schedule: + - cron: '0 0 * * *' + workflow_dispatch: {} + +jobs: + update-terraform-provider: + runs-on: ubuntu-latest + + permissions: + contents: write + + steps: + - uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} + + - name: Install jq + run: sudo apt-get install jq + + - name: Check for New Terraform Provider Release + id: check_release + run: | + API_URL="https://api.github.com/repos/scaleway/terraform-provider-scaleway/releases/latest" + latest_release=$(curl -s $API_URL) + latest_version=$(echo $latest_release | jq -r '.tag_name' | sed 's/^v//') + echo "Latest version: $latest_version" + echo "new_version=$latest_version" >> $GITHUB_ENV + + - name: Read Current Terraform Provider Version from Makefile + id: current_version + run: | + current_version=$(awk -F ' := ' '/TERRAFORM_PROVIDER_VERSION/{print $2}' Makefile) + echo "Current version: $current_version" + echo "current_version=$current_version" >> $GITHUB_ENV + + - name: Update Makefile + if: env.new_version != env.current_version + run: | + new_version="${{ env.new_version }}" + sed -i "s/TERRAFORM_PROVIDER_VERSION := .*/TERRAFORM_PROVIDER_VERSION := $new_version/" Makefile + sed -i "s/TERRAFORM_NATIVE_PROVIDER_BINARY := terraform-provider-scaleway_v.*/TERRAFORM_NATIVE_PROVIDER_B + + - name: Commit and Push Changes + if: env.new_version != env.current_version + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "Update Terraform provider to ${{ env.new_version }}" + branch: ${{ github.head_ref }} \ No newline at end of file From 50f58cce25a03ae737374d698ecf8b8f6628dda5 Mon Sep 17 00:00:00 2001 From: Yacine FODIL Date: Tue, 12 Dec 2023 09:41:52 +0100 Subject: [PATCH 02/24] use github cli to fetch last terraform provider release --- .github/workflows/update-terraform-provider.yaml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/update-terraform-provider.yaml b/.github/workflows/update-terraform-provider.yaml index df62df8..9bab189 100755 --- a/.github/workflows/update-terraform-provider.yaml +++ b/.github/workflows/update-terraform-provider.yaml @@ -17,15 +17,11 @@ jobs: with: ref: ${{ github.head_ref }} - - name: Install jq - run: sudo apt-get install jq - - name: Check for New Terraform Provider Release id: check_release run: | - API_URL="https://api.github.com/repos/scaleway/terraform-provider-scaleway/releases/latest" - latest_release=$(curl -s $API_URL) - latest_version=$(echo $latest_release | jq -r '.tag_name' | sed 's/^v//') + latest_release=$(gh release list -R scaleway/terraform-provider-scaleway --limit 1) + latest_version=$(echo $latest_release | awk '{print $1}' | sed 's/^v//') echo "Latest version: $latest_version" echo "new_version=$latest_version" >> $GITHUB_ENV @@ -48,4 +44,4 @@ jobs: uses: stefanzweifel/git-auto-commit-action@v5 with: commit_message: "Update Terraform provider to ${{ env.new_version }}" - branch: ${{ github.head_ref }} \ No newline at end of file + branch: ${{ github.head_ref }} From 8a248ef560bd32f2bf073b9d8679be76490cf11e Mon Sep 17 00:00:00 2001 From: Yacine FODIL Date: Fri, 29 Dec 2023 09:35:44 +0100 Subject: [PATCH 03/24] add provider metadata comparator --- config/tools/comparator/main.go | 84 +++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 config/tools/comparator/main.go diff --git a/config/tools/comparator/main.go b/config/tools/comparator/main.go new file mode 100644 index 0000000..7386467 --- /dev/null +++ b/config/tools/comparator/main.go @@ -0,0 +1,84 @@ +package main + +import ( + _ "embed" + "encoding/json" + "fmt" + "os" + "strings" + + "github.com/pkg/errors" + "github.com/scaleway/provider-scaleway/config/tools" + "github.com/upbound/upjet/pkg/registry" + + "gopkg.in/yaml.v2" +) + +// ProviderMetadata represents the structure of provider-metadata.yaml +type ProviderMetadata struct { + Resources map[string]*registry.Resource `yaml:"resources"` +} + +func main() { + currentProviderMetadata := os.Getenv("CURRENT_METADATA") + newProviderMetadata := os.Getenv("NEW_METADATA") + + currentResources, err := parseProviderMetadata(currentProviderMetadata) + if err != nil { + fmt.Printf("Error parsing current provider metadata: %v\n", err) + return + } + + newResources, err := parseProviderMetadata(newProviderMetadata) + if err != nil { + fmt.Printf("Error parsing new provider metadata: %v\n", err) + return + } + + addedResources := findNewResources(currentResources, newResources) + fmt.Println("New resources found:") + var resourceConfigs []tools.ResourceConfig + for _, resource := range addedResources { + references := make(map[string]string) + + for _, example := range resource.Examples { + for refKey, refValue := range example.References { + resourceType := strings.Split(refValue, ".")[0] + references[refKey] = resourceType + } + } + + config := tools.ResourceConfig{ + PackageName: strings.ToLower(strings.ReplaceAll(resource.SubCategory, " ", "")), // Convert "Apple Silicon" to "applesilicon" + ShortGroup: strings.ToLower(resource.SubCategory), + ResourceName: resource.Title, + TerraformResourceName: resource.Name, + Kind: resource.Title, + References: references, + } + resourceConfigs = append(resourceConfigs, config) + fmt.Println(resource.Name) + } + + jsonData, _ := json.Marshal(resourceConfigs) + fmt.Println(string(jsonData)) +} + +func parseProviderMetadata(metadata string) (map[string]*registry.Resource, error) { + var providerMetadata ProviderMetadata + err := yaml.Unmarshal([]byte(metadata), &providerMetadata) + if err != nil { + return nil, errors.Wrap(err, "Failed to unmarshal provider metadata") + } + return providerMetadata.Resources, nil +} + +func findNewResources(current, new map[string]*registry.Resource) []*registry.Resource { + var addedResources []*registry.Resource + for resourceName, resource := range new { + if _, exists := current[resourceName]; !exists { + addedResources = append(addedResources, resource) + } + } + return addedResources +} From 0a4af09213b329b3c5a91221055a9372d541e9a9 Mon Sep 17 00:00:00 2001 From: Yacine FODIL Date: Fri, 29 Dec 2023 09:36:06 +0100 Subject: [PATCH 04/24] add resource generator --- config/tools/generator/main.go | 193 +++++++++++++++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 config/tools/generator/main.go diff --git a/config/tools/generator/main.go b/config/tools/generator/main.go new file mode 100644 index 0000000..d26f2d0 --- /dev/null +++ b/config/tools/generator/main.go @@ -0,0 +1,193 @@ +package main + +import ( + "bytes" + "encoding/json" + "fmt" + "io" + "os" + "path/filepath" + "strings" + "text/template" + + "github.com/pkg/errors" + "github.com/scaleway/provider-scaleway/config/tools" +) + +const initialConfigTemplate = `package {{ .PackageName }} + +import "github.com/upbound/upjet/pkg/config" + +const shortGroup = "{{ .ShortGroup }}" +` + +const resourceConfigTemplate = ` +// Configure adds configurations for {{ .ResourceName }} resource. +func Configure(p *config.Provider) { + p.AddResourceConfigurator("{{ .TerraformResourceName }}", func(r *config.Resource) { + r.ExternalName = config.IdentifierFromProvider + r.ShortGroup = shortGroup + r.Kind = "{{ .Kind }}" + {{ range $key, $value := .References }} + r.References["{{$key}}"] = config.Reference{ + Type: "{{$value}}", + } + {{ end }} + }) +} +` + +const ( + ProviderGoFilePath = "config/provider.go" + ExternalNameGoFilePath = "config/external_name.go" +) + +func generateConfigFile(resourceConfig tools.ResourceConfig) error { + dirPath := filepath.Join("config", resourceConfig.PackageName) + if err := os.MkdirAll(dirPath, 0755); err != nil { + return err + } + + filePath := filepath.Join(dirPath, "config.go") + + // Check if config.go already exists + if content, err := os.ReadFile(filePath); err == nil { + contentStr := string(content) + configurator := fmt.Sprintf("p.AddResourceConfigurator(\"%s\", func(r *config.Resource) {", resourceConfig.TerraformResourceName) + + // Check if the configurator already exists + if !strings.Contains(contentStr, configurator) { + tmpl, err := template.New("config").Parse(` + p.AddResourceConfigurator("{{ .TerraformResourceName }}", func(r *config.Resource) { + r.ExternalName = config.IdentifierFromProvider + r.ShortGroup = "{{ .ShortGroup }}" + r.Kind = "{{ .Kind }}" + }) + `) + if err != nil { + return err + } + + var tmplOutput bytes.Buffer + if err := tmpl.Execute(&tmplOutput, resourceConfig); err != nil { + return err + } + + // Append the new configurator before the last closing brace '}' + insertionPoint := strings.LastIndex(contentStr, "}") + if insertionPoint == -1 { + return errors.New("failed to find insertion point in config.go") + } + updatedContent := contentStr[:insertionPoint] + tmplOutput.String() + contentStr[insertionPoint:] + return os.WriteFile(filePath, []byte(updatedContent), 0644) + } + } else { + // Use initial template for new file + tmpl, err := template.New("config").Parse(initialConfigTemplate + resourceConfigTemplate) + if err != nil { + return err + } + file, err := os.Create(filePath) + if err != nil { + return err + } + defer file.Close() + return tmpl.Execute(file, resourceConfig) + } + return nil +} + +func updateProviderGo(resourceConfig tools.ResourceConfig) error { + content, err := os.ReadFile(ProviderGoFilePath) + if err != nil { + return err + } + + contentStr := string(content) + + existingLine := fmt.Sprintf("\t%s.Configure,\n", resourceConfig.PackageName) + if strings.Contains(contentStr, existingLine) { + fmt.Printf("Configuration for %s already exists in provider.go\n", resourceConfig.PackageName) + return nil // Skip insertion as it already exists + } + + // Find the last occurrence of ".Configure," + insertionPoint := strings.LastIndex(contentStr, ".Configure,") + if insertionPoint == -1 { + return errors.New("failed to find insertion point in provider.go") + } + + lineEnd := strings.Index(contentStr[insertionPoint:], "\n") + if lineEnd == -1 { + return errors.New("failed to find the end of the line for insertion point in provider.go") + } + + // Calculate the actual insertion point in the content + actualInsertionPoint := insertionPoint + lineEnd + 1 + newLine := existingLine + + // Insert the new line at the correct position + updatedContent := contentStr[:actualInsertionPoint] + newLine + contentStr[actualInsertionPoint:] + + return os.WriteFile(ProviderGoFilePath, []byte(updatedContent), 0644) +} + +func updateExternalNameGo(resourceConfig tools.ResourceConfig) error { + fileContent, err := os.ReadFile(ExternalNameGoFilePath) + if err != nil { + return err + } + + contentStr := string(fileContent) + resourceName := fmt.Sprintf("\"%s\": config.NameAsIdentifier,", resourceConfig.TerraformResourceName) + + // Check if the resource already exists in the file + if !strings.Contains(contentStr, resourceName) { + // Find the insertion point, which is before the last entry in the map + insertionPoint := strings.LastIndex(contentStr, "\t\"scaleway_") + if insertionPoint == -1 { + return errors.New("failed to find insertion point in external_name.go") + } + newLine := fmt.Sprintf("\t%s\n", resourceName) + + // Insert the new line at the correct position + updatedContent := contentStr[:insertionPoint] + newLine + contentStr[insertionPoint:] + + // Write the updated content back to the file + return os.WriteFile(ExternalNameGoFilePath, []byte(updatedContent), 0644) + } + + return nil +} + +func main() { + jsonData, err := io.ReadAll(os.Stdin) + + if err != nil { + fmt.Printf("Error reading JSON input: %v\n", err) + return + } + + var resourceConfigs []tools.ResourceConfig + if err := json.Unmarshal(jsonData, &resourceConfigs); err != nil { + fmt.Printf("Error parsing JSON input: %v\n", err) + return + } + + for _, config := range resourceConfigs { + if err := generateConfigFile(config); err != nil { + fmt.Printf("Error generating config file for %s: %v\n", config.ResourceName, err) + continue + } + + if err := updateProviderGo(config); err != nil { + fmt.Printf("Error updating provider.go for %s: %v\n", config.ResourceName, err) + continue + } + + if err := updateExternalNameGo(config); err != nil { + fmt.Printf("Error updating external_name.go for %s: %v\n", config.ResourceName, err) + continue + } + } +} From 15f6726b3b60adc3f035f7c9af25757f125b92ee Mon Sep 17 00:00:00 2001 From: Yacine FODIL Date: Fri, 29 Dec 2023 09:37:54 +0100 Subject: [PATCH 05/24] update action --- .../workflows/update-terraform-provider.yaml | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/.github/workflows/update-terraform-provider.yaml b/.github/workflows/update-terraform-provider.yaml index 9bab189..65a7d6a 100755 --- a/.github/workflows/update-terraform-provider.yaml +++ b/.github/workflows/update-terraform-provider.yaml @@ -39,9 +39,32 @@ jobs: sed -i "s/TERRAFORM_PROVIDER_VERSION := .*/TERRAFORM_PROVIDER_VERSION := $new_version/" Makefile sed -i "s/TERRAFORM_NATIVE_PROVIDER_BINARY := terraform-provider-scaleway_v.*/TERRAFORM_NATIVE_PROVIDER_B + - name: Read Current Provider Metadata + run: | + echo "CURRENT_METADATA=$(cat config/provider-metadata.yaml)" >> $GITHUB_ENV + + - name: Update Provider Metadata + run: make generate + + - name: Read New Provider Metadata + run: | + echo "NEW_METADATA=$(cat config/provider-metadata.yaml)" >> $GITHUB_ENV + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: '1.21' + + - name: Compare Provider Metadata + id: compare_provider_metadata + run: echo "::set-output name=resource_configs::$(go run ./config/tools/comparator/main.go)" + + - name: Generate Configurations for New Resources + run: echo ${{ steps.compare_provider_metadata.outputs.resource_configs }} | go run ./config/tools/generator/main.go + - name: Commit and Push Changes - if: env.new_version != env.current_version + if: env.new_version != env.current_version || steps.compare_provider_metadata.outputs.new_resources uses: stefanzweifel/git-auto-commit-action@v5 with: - commit_message: "Update Terraform provider to ${{ env.new_version }}" + commit_message: "Update Terraform provider to ${{ env.new_version }} and generate new resources" branch: ${{ github.head_ref }} From d46a4ba23444ce87fac68511119e50a0b126367e Mon Sep 17 00:00:00 2001 From: Yacine FODIL Date: Fri, 29 Dec 2023 11:18:40 +0100 Subject: [PATCH 06/24] go.mod --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index ccf483f..c1aeba6 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/pkg/errors v0.9.1 github.com/upbound/upjet v0.11.0-rc.0.0.20230927185952-cc55f3952474 gopkg.in/alecthomas/kingpin.v2 v2.2.6 + gopkg.in/yaml.v3 v3.0.1 k8s.io/apimachinery v0.28.1 k8s.io/client-go v0.28.1 sigs.k8s.io/controller-runtime v0.16.1 @@ -107,7 +108,6 @@ require ( google.golang.org/protobuf v1.31.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/api v0.28.1 // indirect k8s.io/apiextensions-apiserver v0.28.1 // indirect k8s.io/component-base v0.28.1 // indirect From 89b0d5253be4675ed8b687662c03189e3ff9daa9 Mon Sep 17 00:00:00 2001 From: Yacine FODIL Date: Fri, 29 Dec 2023 11:24:44 +0100 Subject: [PATCH 07/24] add types file --- config/tools/comparator/main.go | 2 +- config/tools/types.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 config/tools/types.go diff --git a/config/tools/comparator/main.go b/config/tools/comparator/main.go index 7386467..6c8be4e 100644 --- a/config/tools/comparator/main.go +++ b/config/tools/comparator/main.go @@ -11,7 +11,7 @@ import ( "github.com/scaleway/provider-scaleway/config/tools" "github.com/upbound/upjet/pkg/registry" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) // ProviderMetadata represents the structure of provider-metadata.yaml diff --git a/config/tools/types.go b/config/tools/types.go new file mode 100644 index 0000000..eaf8bb5 --- /dev/null +++ b/config/tools/types.go @@ -0,0 +1,10 @@ +package tools + +type ResourceConfig struct { + PackageName string + ShortGroup string + ResourceName string + TerraformResourceName string + Kind string + References map[string]string +} From 0802b3230e83c9a98c6b7c9525c6bf0ecf14e908 Mon Sep 17 00:00:00 2001 From: Yacine FODIL Date: Fri, 29 Dec 2023 15:41:06 +0100 Subject: [PATCH 08/24] refactor to reduce cyclomatic complexity --- config/tools/comparator/main.go | 9 ++- config/tools/generator/main.go | 123 +++++++++++++++++++------------- config/tools/types.go | 1 + 3 files changed, 81 insertions(+), 52 deletions(-) diff --git a/config/tools/comparator/main.go b/config/tools/comparator/main.go index 6c8be4e..b09aeac 100644 --- a/config/tools/comparator/main.go +++ b/config/tools/comparator/main.go @@ -37,7 +37,8 @@ func main() { addedResources := findNewResources(currentResources, newResources) fmt.Println("New resources found:") - var resourceConfigs []tools.ResourceConfig + resourceConfigs := make([]tools.ResourceConfig, 0, len(addedResources)) + for _, resource := range addedResources { references := make(map[string]string) @@ -60,7 +61,11 @@ func main() { fmt.Println(resource.Name) } - jsonData, _ := json.Marshal(resourceConfigs) + jsonData, err := json.Marshal(resourceConfigs) + if err != nil { + fmt.Printf("Error marshaling resource configuration: %v\n", err) + return + } fmt.Println(string(jsonData)) } diff --git a/config/tools/generator/main.go b/config/tools/generator/main.go index d26f2d0..9c22330 100644 --- a/config/tools/generator/main.go +++ b/config/tools/generator/main.go @@ -37,64 +37,87 @@ func Configure(p *config.Provider) { } ` -const ( - ProviderGoFilePath = "config/provider.go" - ExternalNameGoFilePath = "config/external_name.go" -) +// ProviderGoFilePath is the path to the provider.go file where provider configurations are set. +const ProviderGoFilePath = "config/provider.go" + +// ExternalNameGoFilePath is the path to the external_name.go file where external name configurations are defined. +const ExternalNameGoFilePath = "config/external_name.go" func generateConfigFile(resourceConfig tools.ResourceConfig) error { dirPath := filepath.Join("config", resourceConfig.PackageName) - if err := os.MkdirAll(dirPath, 0755); err != nil { + if err := os.MkdirAll(dirPath, 0750); err != nil { return err } filePath := filepath.Join(dirPath, "config.go") + cleanFilePath := filepath.Clean(filePath) + // Ensure the filePath starts with the expected directory + if !strings.HasPrefix(cleanFilePath, "config/") { + return fmt.Errorf("invalid file path: %s", cleanFilePath) + } - // Check if config.go already exists - if content, err := os.ReadFile(filePath); err == nil { - contentStr := string(content) - configurator := fmt.Sprintf("p.AddResourceConfigurator(\"%s\", func(r *config.Resource) {", resourceConfig.TerraformResourceName) - - // Check if the configurator already exists - if !strings.Contains(contentStr, configurator) { - tmpl, err := template.New("config").Parse(` - p.AddResourceConfigurator("{{ .TerraformResourceName }}", func(r *config.Resource) { - r.ExternalName = config.IdentifierFromProvider - r.ShortGroup = "{{ .ShortGroup }}" - r.Kind = "{{ .Kind }}" - }) - `) - if err != nil { - return err - } - - var tmplOutput bytes.Buffer - if err := tmpl.Execute(&tmplOutput, resourceConfig); err != nil { - return err - } - - // Append the new configurator before the last closing brace '}' - insertionPoint := strings.LastIndex(contentStr, "}") - if insertionPoint == -1 { - return errors.New("failed to find insertion point in config.go") - } - updatedContent := contentStr[:insertionPoint] + tmplOutput.String() + contentStr[insertionPoint:] - return os.WriteFile(filePath, []byte(updatedContent), 0644) - } - } else { - // Use initial template for new file - tmpl, err := template.New("config").Parse(initialConfigTemplate + resourceConfigTemplate) - if err != nil { - return err - } - file, err := os.Create(filePath) - if err != nil { - return err + content, err := os.ReadFile(filePath) + if err != nil { + return createNewConfigFile(filePath, resourceConfig) + } + return updateExistingConfigFile(content, filePath, resourceConfig) +} + +func createNewConfigFile(filePath string, resourceConfig tools.ResourceConfig) error { + tmpl, err := template.New("config").Parse(initialConfigTemplate + resourceConfigTemplate) + if err != nil { + return err + } + + cleanFilePath := filepath.Clean(filePath) + if !strings.HasPrefix(cleanFilePath, "config/") { + return fmt.Errorf("invalid file path: %s", cleanFilePath) + } + + file, err := os.Create(filePath) + if err != nil { + return err + } + + defer func() { + if cerr := file.Close(); cerr != nil && err == nil { + err = cerr } - defer file.Close() - return tmpl.Execute(file, resourceConfig) + }() + + return tmpl.Execute(file, resourceConfig) +} + +func updateExistingConfigFile(content []byte, filePath string, resourceConfig tools.ResourceConfig) error { + contentStr := string(content) + configurator := fmt.Sprintf("p.AddResourceConfigurator(\"%s\", func(r *config.Resource) {", resourceConfig.TerraformResourceName) + + if strings.Contains(contentStr, configurator) { + return nil // Configurator already exists } - return nil + + tmpl, err := template.New("config").Parse(` + p.AddResourceConfigurator("{{ .TerraformResourceName }}", func(r *config.Resource) { + r.ExternalName = config.IdentifierFromProvider + r.ShortGroup = "{{ .ShortGroup }}" + r.Kind = "{{ .Kind }}" + }) + `) + if err != nil { + return err + } + + var tmplOutput bytes.Buffer + if err := tmpl.Execute(&tmplOutput, resourceConfig); err != nil { + return err + } + + insertionPoint := strings.LastIndex(contentStr, "}") + if insertionPoint == -1 { + return errors.New("failed to find insertion point in config.go") + } + updatedContent := contentStr[:insertionPoint] + tmplOutput.String() + contentStr[insertionPoint:] + return os.WriteFile(filePath, []byte(updatedContent), 0600) } func updateProviderGo(resourceConfig tools.ResourceConfig) error { @@ -129,7 +152,7 @@ func updateProviderGo(resourceConfig tools.ResourceConfig) error { // Insert the new line at the correct position updatedContent := contentStr[:actualInsertionPoint] + newLine + contentStr[actualInsertionPoint:] - return os.WriteFile(ProviderGoFilePath, []byte(updatedContent), 0644) + return os.WriteFile(ProviderGoFilePath, []byte(updatedContent), 0600) } func updateExternalNameGo(resourceConfig tools.ResourceConfig) error { @@ -154,7 +177,7 @@ func updateExternalNameGo(resourceConfig tools.ResourceConfig) error { updatedContent := contentStr[:insertionPoint] + newLine + contentStr[insertionPoint:] // Write the updated content back to the file - return os.WriteFile(ExternalNameGoFilePath, []byte(updatedContent), 0644) + return os.WriteFile(ExternalNameGoFilePath, []byte(updatedContent), 0600) } return nil diff --git a/config/tools/types.go b/config/tools/types.go index eaf8bb5..8119cd3 100644 --- a/config/tools/types.go +++ b/config/tools/types.go @@ -1,5 +1,6 @@ package tools +// ResourceConfig contains configuration information for a Terraform resource. type ResourceConfig struct { PackageName string ShortGroup string From 18bde1aac8b95bdc39836ad13a63595c98335be2 Mon Sep 17 00:00:00 2001 From: Yacine FODIL Date: Fri, 29 Dec 2023 16:01:54 +0100 Subject: [PATCH 09/24] set golangci lint version to latest --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 25d0575..2af2616 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,6 @@ on: env: # Common versions GO_VERSION: '1.19' - GOLANGCI_VERSION: 'v1.50.0' DOCKER_BUILDX_VERSION: 'v0.8.2' # Common users. We can't run a step 'if secrets.XXX != ""' but we can run a @@ -77,7 +76,7 @@ jobs: - name: Lint uses: golangci/golangci-lint-action@v3 with: - version: ${{ env.GOLANGCI_VERSION }} + version: latest check-diff: runs-on: ubuntu-22.04 From 4662a7c94f99fa3b41081310245ed00fec4174e3 Mon Sep 17 00:00:00 2001 From: Yacine FODIL Date: Thu, 6 Jun 2024 07:52:08 +0200 Subject: [PATCH 10/24] move templates to a separate file --- config/tools/comparator/main.go | 2 +- config/tools/generator/main.go | 35 +++++++++++--------- config/tools/templates/config_templates.tmpl | 31 +++++++++++++++++ 3 files changed, 52 insertions(+), 16 deletions(-) create mode 100644 config/tools/templates/config_templates.tmpl diff --git a/config/tools/comparator/main.go b/config/tools/comparator/main.go index b09aeac..b98f70f 100644 --- a/config/tools/comparator/main.go +++ b/config/tools/comparator/main.go @@ -7,9 +7,9 @@ import ( "os" "strings" + "github.com/crossplane/upjet/pkg/registry" "github.com/pkg/errors" "github.com/scaleway/provider-scaleway/config/tools" - "github.com/upbound/upjet/pkg/registry" "gopkg.in/yaml.v3" ) diff --git a/config/tools/generator/main.go b/config/tools/generator/main.go index 9c22330..097fcb9 100644 --- a/config/tools/generator/main.go +++ b/config/tools/generator/main.go @@ -43,6 +43,10 @@ const ProviderGoFilePath = "config/provider.go" // ExternalNameGoFilePath is the path to the external_name.go file where external name configurations are defined. const ExternalNameGoFilePath = "config/external_name.go" +func parseTemplates() (*template.Template, error) { + return template.ParseFiles("config_templates.tmpl") +} + func generateConfigFile(resourceConfig tools.ResourceConfig) error { dirPath := filepath.Join("config", resourceConfig.PackageName) if err := os.MkdirAll(dirPath, 0750); err != nil { @@ -64,28 +68,35 @@ func generateConfigFile(resourceConfig tools.ResourceConfig) error { } func createNewConfigFile(filePath string, resourceConfig tools.ResourceConfig) error { - tmpl, err := template.New("config").Parse(initialConfigTemplate + resourceConfigTemplate) + tmpl, err := parseTemplates() if err != nil { return err } - cleanFilePath := filepath.Clean(filePath) - if !strings.HasPrefix(cleanFilePath, "config/") { - return fmt.Errorf("invalid file path: %s", cleanFilePath) - } - file, err := os.Create(filePath) if err != nil { return err } + cleanFilePath := filepath.Clean(filePath) + if !strings.HasPrefix(cleanFilePath, "config/") { + return fmt.Errorf("invalid file path: %s", cleanFilePath) + } + defer func() { if cerr := file.Close(); cerr != nil && err == nil { err = cerr } }() - return tmpl.Execute(file, resourceConfig) + templates := []string{"initialConfigTemplate", "resourceConfigTemplate"} + for _, tmplName := range templates { + if err = tmpl.ExecuteTemplate(file, tmplName, resourceConfig); err != nil { + return err + } + } + + return nil } func updateExistingConfigFile(content []byte, filePath string, resourceConfig tools.ResourceConfig) error { @@ -96,19 +107,13 @@ func updateExistingConfigFile(content []byte, filePath string, resourceConfig to return nil // Configurator already exists } - tmpl, err := template.New("config").Parse(` - p.AddResourceConfigurator("{{ .TerraformResourceName }}", func(r *config.Resource) { - r.ExternalName = config.IdentifierFromProvider - r.ShortGroup = "{{ .ShortGroup }}" - r.Kind = "{{ .Kind }}" - }) - `) + tmpl, err := parseTemplates() if err != nil { return err } var tmplOutput bytes.Buffer - if err := tmpl.Execute(&tmplOutput, resourceConfig); err != nil { + if err := tmpl.ExecuteTemplate(&tmplOutput, "updateConfigTemplate", resourceConfig); err != nil { return err } diff --git a/config/tools/templates/config_templates.tmpl b/config/tools/templates/config_templates.tmpl new file mode 100644 index 0000000..ddaef01 --- /dev/null +++ b/config/tools/templates/config_templates.tmpl @@ -0,0 +1,31 @@ +{{ define "initialConfigTemplate" }} + package {{ .PackageName }} + + import "github.com/crossplane/upjet/pkg/config" + + const shortGroup = "{{ .ShortGroup }}" +{{ end }} + +{{ define "resourceConfigTemplate" }} + // Configure adds configurations for {{ .ResourceName }} resource. + func Configure(p *config.Provider) { + p.AddResourceConfigurator("{{ .TerraformResourceName }}", func(r *config.Resource) { + r.ExternalName = config.IdentifierFromProvider + r.ShortGroup = shortGroup + r.Kind = "{{ .Kind }}" + {{ range $key, $value := .References }} + r.References["{{$key}}"] = config.Reference{ + Type: "{{$value}}", + } + {{ end }} + }) + } +{{ end }} + +{{ define "updateExistingConfigTemplate" }} + p.AddResourceConfigurator("{{ .TerraformResourceName }}", func(r *config.Resource) { + r.ExternalName = config.IdentifierFromProvider + r.ShortGroup = "{{ .ShortGroup }}" + r.Kind = "{{ .Kind }}" + }) +{{ end }} From 8b4dac9e092ee85ef4e78ed4e15cf163f1d37e34 Mon Sep 17 00:00:00 2001 From: Yacine FODIL Date: Thu, 6 Jun 2024 07:53:32 +0200 Subject: [PATCH 11/24] set go to 1.22 --- .github/workflows/update-terraform-provider.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-terraform-provider.yaml b/.github/workflows/update-terraform-provider.yaml index 65a7d6a..8223965 100755 --- a/.github/workflows/update-terraform-provider.yaml +++ b/.github/workflows/update-terraform-provider.yaml @@ -53,7 +53,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: '1.21' + go-version: '1.22' - name: Compare Provider Metadata id: compare_provider_metadata From 7c8df0bd44bc0929cc367dc31a699f55ed4094f2 Mon Sep 17 00:00:00 2001 From: Yacine FODIL Date: Thu, 6 Jun 2024 09:48:20 +0200 Subject: [PATCH 12/24] go mod tidy --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 2bcde50..1890897 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ require ( github.com/crossplane/crossplane-tools v0.0.0-20230925130601-628280f8bf79 github.com/crossplane/upjet v1.4.0 github.com/pkg/errors v0.9.1 + gopkg.in/yaml.v3 v3.0.1 k8s.io/apimachinery v0.30.1 k8s.io/client-go v0.29.4 sigs.k8s.io/controller-runtime v0.17.3 @@ -118,7 +119,6 @@ require ( gopkg.in/alecthomas/kingpin.v2 v2.2.6 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/api v0.29.4 // indirect k8s.io/apiextensions-apiserver v0.29.2 // indirect k8s.io/component-base v0.29.2 // indirect From f743a84aeaa3be454ea89fa19d15bbc550c9258a Mon Sep 17 00:00:00 2001 From: Yacine FODIL Date: Thu, 6 Jun 2024 10:34:54 +0200 Subject: [PATCH 13/24] lint --- config/tools/generator/main.go | 23 ----------------------- config/tools/types.go | 12 ++++++------ 2 files changed, 6 insertions(+), 29 deletions(-) diff --git a/config/tools/generator/main.go b/config/tools/generator/main.go index 097fcb9..487268c 100644 --- a/config/tools/generator/main.go +++ b/config/tools/generator/main.go @@ -14,29 +14,6 @@ import ( "github.com/scaleway/provider-scaleway/config/tools" ) -const initialConfigTemplate = `package {{ .PackageName }} - -import "github.com/upbound/upjet/pkg/config" - -const shortGroup = "{{ .ShortGroup }}" -` - -const resourceConfigTemplate = ` -// Configure adds configurations for {{ .ResourceName }} resource. -func Configure(p *config.Provider) { - p.AddResourceConfigurator("{{ .TerraformResourceName }}", func(r *config.Resource) { - r.ExternalName = config.IdentifierFromProvider - r.ShortGroup = shortGroup - r.Kind = "{{ .Kind }}" - {{ range $key, $value := .References }} - r.References["{{$key}}"] = config.Reference{ - Type: "{{$value}}", - } - {{ end }} - }) -} -` - // ProviderGoFilePath is the path to the provider.go file where provider configurations are set. const ProviderGoFilePath = "config/provider.go" diff --git a/config/tools/types.go b/config/tools/types.go index 8119cd3..1c5e316 100644 --- a/config/tools/types.go +++ b/config/tools/types.go @@ -2,10 +2,10 @@ package tools // ResourceConfig contains configuration information for a Terraform resource. type ResourceConfig struct { - PackageName string - ShortGroup string - ResourceName string - TerraformResourceName string - Kind string - References map[string]string + PackageName string `json:"package_name"` + ShortGroup string `json:"short_group"` + ResourceName string `json:"resource_name"` + TerraformResourceName string `json:"terraform_resource_name"` + Kind string `json:"kind"` + References map[string]string `json:"references"` } From c5d8a2a5af928559c986cc832b7bebc1ecb8863e Mon Sep 17 00:00:00 2001 From: Yacine FODIL Date: Wed, 7 Aug 2024 09:44:59 +0200 Subject: [PATCH 14/24] fix Kind fetching --- config/tools/comparator/main.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/config/tools/comparator/main.go b/config/tools/comparator/main.go index b98f70f..4048829 100644 --- a/config/tools/comparator/main.go +++ b/config/tools/comparator/main.go @@ -4,6 +4,8 @@ import ( _ "embed" "encoding/json" "fmt" + "golang.org/x/text/cases" + "golang.org/x/text/language" "os" "strings" @@ -54,7 +56,7 @@ func main() { ShortGroup: strings.ToLower(resource.SubCategory), ResourceName: resource.Title, TerraformResourceName: resource.Name, - Kind: resource.Title, + Kind: parseKindFromResourceName(resource.Name), References: references, } resourceConfigs = append(resourceConfigs, config) @@ -87,3 +89,15 @@ func findNewResources(current, new map[string]*registry.Resource) []*registry.Re } return addedResources } + +func parseKindFromResourceName(resourceName string) string { + titleCaser := cases.Title(language.English) + + parts := strings.Split(resourceName, "_") + if len(parts) == 0 { + return "" + } + lastWord := parts[len(parts)-1] + + return titleCaser.String(lastWord) +} From 14f124282a78d050a43c7014d63e9d13b53bc7e6 Mon Sep 17 00:00:00 2001 From: Yacine FODIL Date: Wed, 7 Aug 2024 09:50:11 +0200 Subject: [PATCH 15/24] gofmt the generated files --- .../config_templates.tmpl | 5 ++ config/tools/generator/main.go | 61 +++++++++++++------ 2 files changed, 47 insertions(+), 19 deletions(-) rename config/tools/{templates => generator}/config_templates.tmpl (86%) diff --git a/config/tools/templates/config_templates.tmpl b/config/tools/generator/config_templates.tmpl similarity index 86% rename from config/tools/templates/config_templates.tmpl rename to config/tools/generator/config_templates.tmpl index ddaef01..d2875d9 100644 --- a/config/tools/templates/config_templates.tmpl +++ b/config/tools/generator/config_templates.tmpl @@ -27,5 +27,10 @@ r.ExternalName = config.IdentifierFromProvider r.ShortGroup = "{{ .ShortGroup }}" r.Kind = "{{ .Kind }}" + {{ range $key, $value := .References }} + r.References["{{$key}}"] = config.Reference{ + Type: "{{$value}}", + } + {{ end }} }) {{ end }} diff --git a/config/tools/generator/main.go b/config/tools/generator/main.go index 487268c..7c56e48 100644 --- a/config/tools/generator/main.go +++ b/config/tools/generator/main.go @@ -4,7 +4,9 @@ import ( "bytes" "encoding/json" "fmt" + "go/format" "io" + "log" "os" "path/filepath" "strings" @@ -21,7 +23,12 @@ const ProviderGoFilePath = "config/provider.go" const ExternalNameGoFilePath = "config/external_name.go" func parseTemplates() (*template.Template, error) { - return template.ParseFiles("config_templates.tmpl") + templatePath := "config/config_templates.tmpl" + tmpl, err := template.ParseFiles(templatePath) + if err != nil { + log.Fatalf("Failed to parse templates: %v", err) + } + return tmpl, err } func generateConfigFile(resourceConfig tools.ResourceConfig) error { @@ -50,9 +57,17 @@ func createNewConfigFile(filePath string, resourceConfig tools.ResourceConfig) e return err } - file, err := os.Create(filePath) + var buf bytes.Buffer + templates := []string{"initialConfigTemplate", "resourceConfigTemplate"} + for _, tmplName := range templates { + if err = tmpl.ExecuteTemplate(&buf, tmplName, resourceConfig); err != nil { + return err + } + } + + formattedCode, err := format.Source(buf.Bytes()) if err != nil { - return err + return fmt.Errorf("failed to format generated code: %w", err) } cleanFilePath := filepath.Clean(filePath) @@ -60,17 +75,9 @@ func createNewConfigFile(filePath string, resourceConfig tools.ResourceConfig) e return fmt.Errorf("invalid file path: %s", cleanFilePath) } - defer func() { - if cerr := file.Close(); cerr != nil && err == nil { - err = cerr - } - }() - - templates := []string{"initialConfigTemplate", "resourceConfigTemplate"} - for _, tmplName := range templates { - if err = tmpl.ExecuteTemplate(file, tmplName, resourceConfig); err != nil { - return err - } + err = os.WriteFile(filePath, formattedCode, 0644) + if err != nil { + return err } return nil @@ -90,7 +97,7 @@ func updateExistingConfigFile(content []byte, filePath string, resourceConfig to } var tmplOutput bytes.Buffer - if err := tmpl.ExecuteTemplate(&tmplOutput, "updateConfigTemplate", resourceConfig); err != nil { + if err := tmpl.ExecuteTemplate(&tmplOutput, "updateExistingConfigTemplate", resourceConfig); err != nil { return err } @@ -98,8 +105,15 @@ func updateExistingConfigFile(content []byte, filePath string, resourceConfig to if insertionPoint == -1 { return errors.New("failed to find insertion point in config.go") } + updatedContent := contentStr[:insertionPoint] + tmplOutput.String() + contentStr[insertionPoint:] - return os.WriteFile(filePath, []byte(updatedContent), 0600) + + formattedCode, err := format.Source([]byte(updatedContent)) + if err != nil { + return fmt.Errorf("failed to format updated code: %w", err) + } + + return os.WriteFile(filePath, formattedCode, 0600) } func updateProviderGo(resourceConfig tools.ResourceConfig) error { @@ -134,7 +148,12 @@ func updateProviderGo(resourceConfig tools.ResourceConfig) error { // Insert the new line at the correct position updatedContent := contentStr[:actualInsertionPoint] + newLine + contentStr[actualInsertionPoint:] - return os.WriteFile(ProviderGoFilePath, []byte(updatedContent), 0600) + formattedCode, err := format.Source([]byte(updatedContent)) + if err != nil { + return fmt.Errorf("failed to format provider.go: %w", err) + } + + return os.WriteFile(ProviderGoFilePath, formattedCode, 0600) } func updateExternalNameGo(resourceConfig tools.ResourceConfig) error { @@ -158,8 +177,13 @@ func updateExternalNameGo(resourceConfig tools.ResourceConfig) error { // Insert the new line at the correct position updatedContent := contentStr[:insertionPoint] + newLine + contentStr[insertionPoint:] + formattedCode, err := format.Source([]byte(updatedContent)) + if err != nil { + return fmt.Errorf("failed to format external_name.go: %w", err) + } + // Write the updated content back to the file - return os.WriteFile(ExternalNameGoFilePath, []byte(updatedContent), 0600) + return os.WriteFile(ExternalNameGoFilePath, formattedCode, 0600) } return nil @@ -167,7 +191,6 @@ func updateExternalNameGo(resourceConfig tools.ResourceConfig) error { func main() { jsonData, err := io.ReadAll(os.Stdin) - if err != nil { fmt.Printf("Error reading JSON input: %v\n", err) return From 5008cd3ffe219f242d83ec17546edefeaeeb57f9 Mon Sep 17 00:00:00 2001 From: Yacine FODIL Date: Wed, 7 Aug 2024 09:57:36 +0200 Subject: [PATCH 16/24] go mod tidy --- .../v1alpha1/zz_definition_terraformed.go | 129 ------ apis/jobs/v1alpha1/zz_definition_types.go | 240 ---------- .../v1alpha1/zz_generated.conversion_hubs.go | 10 - apis/jobs/v1alpha1/zz_generated.deepcopy.go | 436 ------------------ apis/jobs/v1alpha1/zz_generated.managed.go | 68 --- .../jobs/v1alpha1/zz_generated.managedlist.go | 17 - apis/jobs/v1alpha1/zz_groupversion_info.go | 32 -- .../v1alpha1/zz_generated.conversion_hubs.go | 10 - apis/sdb/v1alpha1/zz_generated.deepcopy.go | 222 --------- apis/sdb/v1alpha1/zz_generated.managed.go | 68 --- apis/sdb/v1alpha1/zz_generated.managedlist.go | 17 - apis/sdb/v1alpha1/zz_groupversion_info.go | 32 -- .../v1alpha1/zz_sqldatabase_terraformed.go | 129 ------ apis/sdb/v1alpha1/zz_sqldatabase_types.go | 143 ------ go.mod | 2 +- 15 files changed, 1 insertion(+), 1554 deletions(-) delete mode 100755 apis/jobs/v1alpha1/zz_definition_terraformed.go delete mode 100755 apis/jobs/v1alpha1/zz_definition_types.go delete mode 100755 apis/jobs/v1alpha1/zz_generated.conversion_hubs.go delete mode 100644 apis/jobs/v1alpha1/zz_generated.deepcopy.go delete mode 100644 apis/jobs/v1alpha1/zz_generated.managed.go delete mode 100644 apis/jobs/v1alpha1/zz_generated.managedlist.go delete mode 100755 apis/jobs/v1alpha1/zz_groupversion_info.go delete mode 100755 apis/sdb/v1alpha1/zz_generated.conversion_hubs.go delete mode 100644 apis/sdb/v1alpha1/zz_generated.deepcopy.go delete mode 100644 apis/sdb/v1alpha1/zz_generated.managed.go delete mode 100644 apis/sdb/v1alpha1/zz_generated.managedlist.go delete mode 100755 apis/sdb/v1alpha1/zz_groupversion_info.go delete mode 100755 apis/sdb/v1alpha1/zz_sqldatabase_terraformed.go delete mode 100755 apis/sdb/v1alpha1/zz_sqldatabase_types.go diff --git a/apis/jobs/v1alpha1/zz_definition_terraformed.go b/apis/jobs/v1alpha1/zz_definition_terraformed.go deleted file mode 100755 index 5c02d4f..0000000 --- a/apis/jobs/v1alpha1/zz_definition_terraformed.go +++ /dev/null @@ -1,129 +0,0 @@ -/* -Copyright 2022 Upbound Inc. -*/ - -// Code generated by upjet. DO NOT EDIT. - -package v1alpha1 - -import ( - "dario.cat/mergo" - "github.com/pkg/errors" - - "github.com/crossplane/upjet/pkg/resource" - "github.com/crossplane/upjet/pkg/resource/json" -) - -// GetTerraformResourceType returns Terraform resource type for this Definition -func (mg *Definition) GetTerraformResourceType() string { - return "scaleway_job_definition" -} - -// GetConnectionDetailsMapping for this Definition -func (tr *Definition) GetConnectionDetailsMapping() map[string]string { - return nil -} - -// GetObservation of this Definition -func (tr *Definition) GetObservation() (map[string]any, error) { - o, err := json.TFParser.Marshal(tr.Status.AtProvider) - if err != nil { - return nil, err - } - base := map[string]any{} - return base, json.TFParser.Unmarshal(o, &base) -} - -// SetObservation for this Definition -func (tr *Definition) SetObservation(obs map[string]any) error { - p, err := json.TFParser.Marshal(obs) - if err != nil { - return err - } - return json.TFParser.Unmarshal(p, &tr.Status.AtProvider) -} - -// GetID returns ID of underlying Terraform resource of this Definition -func (tr *Definition) GetID() string { - if tr.Status.AtProvider.ID == nil { - return "" - } - return *tr.Status.AtProvider.ID -} - -// GetParameters of this Definition -func (tr *Definition) GetParameters() (map[string]any, error) { - p, err := json.TFParser.Marshal(tr.Spec.ForProvider) - if err != nil { - return nil, err - } - base := map[string]any{} - return base, json.TFParser.Unmarshal(p, &base) -} - -// SetParameters for this Definition -func (tr *Definition) SetParameters(params map[string]any) error { - p, err := json.TFParser.Marshal(params) - if err != nil { - return err - } - return json.TFParser.Unmarshal(p, &tr.Spec.ForProvider) -} - -// GetInitParameters of this Definition -func (tr *Definition) GetInitParameters() (map[string]any, error) { - p, err := json.TFParser.Marshal(tr.Spec.InitProvider) - if err != nil { - return nil, err - } - base := map[string]any{} - return base, json.TFParser.Unmarshal(p, &base) -} - -// GetInitParameters of this Definition -func (tr *Definition) GetMergedParameters(shouldMergeInitProvider bool) (map[string]any, error) { - params, err := tr.GetParameters() - if err != nil { - return nil, errors.Wrapf(err, "cannot get parameters for resource '%q'", tr.GetName()) - } - if !shouldMergeInitProvider { - return params, nil - } - - initParams, err := tr.GetInitParameters() - if err != nil { - return nil, errors.Wrapf(err, "cannot get init parameters for resource '%q'", tr.GetName()) - } - - // Note(lsviben): mergo.WithSliceDeepCopy is needed to merge the - // slices from the initProvider to forProvider. As it also sets - // overwrite to true, we need to set it back to false, we don't - // want to overwrite the forProvider fields with the initProvider - // fields. - err = mergo.Merge(¶ms, initParams, mergo.WithSliceDeepCopy, func(c *mergo.Config) { - c.Overwrite = false - }) - if err != nil { - return nil, errors.Wrapf(err, "cannot merge spec.initProvider and spec.forProvider parameters for resource '%q'", tr.GetName()) - } - - return params, nil -} - -// LateInitialize this Definition using its observed tfState. -// returns True if there are any spec changes for the resource. -func (tr *Definition) LateInitialize(attrs []byte) (bool, error) { - params := &DefinitionParameters{} - if err := json.TFParser.Unmarshal(attrs, params); err != nil { - return false, errors.Wrap(err, "failed to unmarshal Terraform state parameters for late-initialization") - } - opts := []resource.GenericLateInitializerOption{resource.WithZeroValueJSONOmitEmptyFilter(resource.CNameWildcard)} - - li := resource.NewGenericLateInitializer(opts...) - return li.LateInitialize(&tr.Spec.ForProvider, params) -} - -// GetTerraformSchemaVersion returns the associated Terraform schema version -func (tr *Definition) GetTerraformSchemaVersion() int { - return 0 -} diff --git a/apis/jobs/v1alpha1/zz_definition_types.go b/apis/jobs/v1alpha1/zz_definition_types.go deleted file mode 100755 index 31e2925..0000000 --- a/apis/jobs/v1alpha1/zz_definition_types.go +++ /dev/null @@ -1,240 +0,0 @@ -/* -Copyright 2022 Upbound Inc. -*/ - -// Code generated by upjet. DO NOT EDIT. - -package v1alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" - - v1 "github.com/crossplane/crossplane-runtime/apis/common/v1" -) - -type CronInitParameters struct { - - // Cron format string. - Schedule *string `json:"schedule,omitempty" tf:"schedule,omitempty"` - - // The timezone, must be a canonical TZ identifier as found in this list. - Timezone *string `json:"timezone,omitempty" tf:"timezone,omitempty"` -} - -type CronObservation struct { - - // Cron format string. - Schedule *string `json:"schedule,omitempty" tf:"schedule,omitempty"` - - // The timezone, must be a canonical TZ identifier as found in this list. - Timezone *string `json:"timezone,omitempty" tf:"timezone,omitempty"` -} - -type CronParameters struct { - - // Cron format string. - // +kubebuilder:validation:Optional - Schedule *string `json:"schedule" tf:"schedule,omitempty"` - - // The timezone, must be a canonical TZ identifier as found in this list. - // +kubebuilder:validation:Optional - Timezone *string `json:"timezone" tf:"timezone,omitempty"` -} - -type DefinitionInitParameters struct { - - // The amount of vCPU computing resources to allocate to each container running the job. - CPULimit *float64 `json:"cpuLimit,omitempty" tf:"cpu_limit,omitempty"` - - // The command that will be run in the container if specified. - Command *string `json:"command,omitempty" tf:"command,omitempty"` - - // The cron configuration - Cron []CronInitParameters `json:"cron,omitempty" tf:"cron,omitempty"` - - // The description of the job - Description *string `json:"description,omitempty" tf:"description,omitempty"` - - // The environment variables of the container. - // +mapType=granular - Env map[string]*string `json:"env,omitempty" tf:"env,omitempty"` - - // The uri of the container image that will be used for the job run. - ImageURI *string `json:"imageUri,omitempty" tf:"image_uri,omitempty"` - - // The memory computing resources in MB to allocate to each container running the job. - MemoryLimit *float64 `json:"memoryLimit,omitempty" tf:"memory_limit,omitempty"` - - // The name of the job. - // The job name - Name *string `json:"name,omitempty" tf:"name,omitempty"` - - // (Defaults to provider project_id) The ID of the project the Job is associated with. - // The project_id you want to attach the resource to - ProjectID *string `json:"projectId,omitempty" tf:"project_id,omitempty"` - - // (Defaults to provider region) The region of the Job. - // The region you want to attach the resource to - Region *string `json:"region,omitempty" tf:"region,omitempty"` - - // The job run timeout, in Go Time format (ex: 2h30m25s) - Timeout *string `json:"timeout,omitempty" tf:"timeout,omitempty"` -} - -type DefinitionObservation struct { - - // The amount of vCPU computing resources to allocate to each container running the job. - CPULimit *float64 `json:"cpuLimit,omitempty" tf:"cpu_limit,omitempty"` - - // The command that will be run in the container if specified. - Command *string `json:"command,omitempty" tf:"command,omitempty"` - - // The cron configuration - Cron []CronObservation `json:"cron,omitempty" tf:"cron,omitempty"` - - // The description of the job - Description *string `json:"description,omitempty" tf:"description,omitempty"` - - // The environment variables of the container. - // +mapType=granular - Env map[string]*string `json:"env,omitempty" tf:"env,omitempty"` - - // The ID of the Job Definition. - ID *string `json:"id,omitempty" tf:"id,omitempty"` - - // The uri of the container image that will be used for the job run. - ImageURI *string `json:"imageUri,omitempty" tf:"image_uri,omitempty"` - - // The memory computing resources in MB to allocate to each container running the job. - MemoryLimit *float64 `json:"memoryLimit,omitempty" tf:"memory_limit,omitempty"` - - // The name of the job. - // The job name - Name *string `json:"name,omitempty" tf:"name,omitempty"` - - // (Defaults to provider project_id) The ID of the project the Job is associated with. - // The project_id you want to attach the resource to - ProjectID *string `json:"projectId,omitempty" tf:"project_id,omitempty"` - - // (Defaults to provider region) The region of the Job. - // The region you want to attach the resource to - Region *string `json:"region,omitempty" tf:"region,omitempty"` - - // The job run timeout, in Go Time format (ex: 2h30m25s) - Timeout *string `json:"timeout,omitempty" tf:"timeout,omitempty"` -} - -type DefinitionParameters struct { - - // The amount of vCPU computing resources to allocate to each container running the job. - // +kubebuilder:validation:Optional - CPULimit *float64 `json:"cpuLimit,omitempty" tf:"cpu_limit,omitempty"` - - // The command that will be run in the container if specified. - // +kubebuilder:validation:Optional - Command *string `json:"command,omitempty" tf:"command,omitempty"` - - // The cron configuration - // +kubebuilder:validation:Optional - Cron []CronParameters `json:"cron,omitempty" tf:"cron,omitempty"` - - // The description of the job - // +kubebuilder:validation:Optional - Description *string `json:"description,omitempty" tf:"description,omitempty"` - - // The environment variables of the container. - // +kubebuilder:validation:Optional - // +mapType=granular - Env map[string]*string `json:"env,omitempty" tf:"env,omitempty"` - - // The uri of the container image that will be used for the job run. - // +kubebuilder:validation:Optional - ImageURI *string `json:"imageUri,omitempty" tf:"image_uri,omitempty"` - - // The memory computing resources in MB to allocate to each container running the job. - // +kubebuilder:validation:Optional - MemoryLimit *float64 `json:"memoryLimit,omitempty" tf:"memory_limit,omitempty"` - - // The name of the job. - // The job name - // +kubebuilder:validation:Optional - Name *string `json:"name,omitempty" tf:"name,omitempty"` - - // (Defaults to provider project_id) The ID of the project the Job is associated with. - // The project_id you want to attach the resource to - // +kubebuilder:validation:Optional - ProjectID *string `json:"projectId,omitempty" tf:"project_id,omitempty"` - - // (Defaults to provider region) The region of the Job. - // The region you want to attach the resource to - // +kubebuilder:validation:Optional - Region *string `json:"region,omitempty" tf:"region,omitempty"` - - // The job run timeout, in Go Time format (ex: 2h30m25s) - // +kubebuilder:validation:Optional - Timeout *string `json:"timeout,omitempty" tf:"timeout,omitempty"` -} - -// DefinitionSpec defines the desired state of Definition -type DefinitionSpec struct { - v1.ResourceSpec `json:",inline"` - ForProvider DefinitionParameters `json:"forProvider"` - // THIS IS A BETA FIELD. It will be honored - // unless the Management Policies feature flag is disabled. - // InitProvider holds the same fields as ForProvider, with the exception - // of Identifier and other resource reference fields. The fields that are - // in InitProvider are merged into ForProvider when the resource is created. - // The same fields are also added to the terraform ignore_changes hook, to - // avoid updating them after creation. This is useful for fields that are - // required on creation, but we do not desire to update them after creation, - // for example because of an external controller is managing them, like an - // autoscaler. - InitProvider DefinitionInitParameters `json:"initProvider,omitempty"` -} - -// DefinitionStatus defines the observed state of Definition. -type DefinitionStatus struct { - v1.ResourceStatus `json:",inline"` - AtProvider DefinitionObservation `json:"atProvider,omitempty"` -} - -// +kubebuilder:object:root=true -// +kubebuilder:subresource:status -// +kubebuilder:storageversion - -// Definition is the Schema for the Definitions API. -// +kubebuilder:printcolumn:name="SYNCED",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status" -// +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status" -// +kubebuilder:printcolumn:name="EXTERNAL-NAME",type="string",JSONPath=".metadata.annotations.crossplane\\.io/external-name" -// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp" -// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,scaleway} -type Definition struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - // +kubebuilder:validation:XValidation:rule="!('*' in self.managementPolicies || 'Create' in self.managementPolicies || 'Update' in self.managementPolicies) || has(self.forProvider.cpuLimit) || (has(self.initProvider) && has(self.initProvider.cpuLimit))",message="spec.forProvider.cpuLimit is a required parameter" - // +kubebuilder:validation:XValidation:rule="!('*' in self.managementPolicies || 'Create' in self.managementPolicies || 'Update' in self.managementPolicies) || has(self.forProvider.memoryLimit) || (has(self.initProvider) && has(self.initProvider.memoryLimit))",message="spec.forProvider.memoryLimit is a required parameter" - Spec DefinitionSpec `json:"spec"` - Status DefinitionStatus `json:"status,omitempty"` -} - -// +kubebuilder:object:root=true - -// DefinitionList contains a list of Definitions -type DefinitionList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []Definition `json:"items"` -} - -// Repository type metadata. -var ( - Definition_Kind = "Definition" - Definition_GroupKind = schema.GroupKind{Group: CRDGroup, Kind: Definition_Kind}.String() - Definition_KindAPIVersion = Definition_Kind + "." + CRDGroupVersion.String() - Definition_GroupVersionKind = CRDGroupVersion.WithKind(Definition_Kind) -) - -func init() { - SchemeBuilder.Register(&Definition{}, &DefinitionList{}) -} diff --git a/apis/jobs/v1alpha1/zz_generated.conversion_hubs.go b/apis/jobs/v1alpha1/zz_generated.conversion_hubs.go deleted file mode 100755 index 3bd87d2..0000000 --- a/apis/jobs/v1alpha1/zz_generated.conversion_hubs.go +++ /dev/null @@ -1,10 +0,0 @@ -/* -Copyright 2022 Upbound Inc. -*/ - -// Code generated by upjet. DO NOT EDIT. - -package v1alpha1 - -// Hub marks this type as a conversion hub. -func (tr *Definition) Hub() {} diff --git a/apis/jobs/v1alpha1/zz_generated.deepcopy.go b/apis/jobs/v1alpha1/zz_generated.deepcopy.go deleted file mode 100644 index fb55d94..0000000 --- a/apis/jobs/v1alpha1/zz_generated.deepcopy.go +++ /dev/null @@ -1,436 +0,0 @@ -//go:build !ignore_autogenerated - -/* -Copyright 2022 Upbound Inc. -*/ - -// Code generated by controller-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - runtime "k8s.io/apimachinery/pkg/runtime" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CronInitParameters) DeepCopyInto(out *CronInitParameters) { - *out = *in - if in.Schedule != nil { - in, out := &in.Schedule, &out.Schedule - *out = new(string) - **out = **in - } - if in.Timezone != nil { - in, out := &in.Timezone, &out.Timezone - *out = new(string) - **out = **in - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CronInitParameters. -func (in *CronInitParameters) DeepCopy() *CronInitParameters { - if in == nil { - return nil - } - out := new(CronInitParameters) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CronObservation) DeepCopyInto(out *CronObservation) { - *out = *in - if in.Schedule != nil { - in, out := &in.Schedule, &out.Schedule - *out = new(string) - **out = **in - } - if in.Timezone != nil { - in, out := &in.Timezone, &out.Timezone - *out = new(string) - **out = **in - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CronObservation. -func (in *CronObservation) DeepCopy() *CronObservation { - if in == nil { - return nil - } - out := new(CronObservation) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CronParameters) DeepCopyInto(out *CronParameters) { - *out = *in - if in.Schedule != nil { - in, out := &in.Schedule, &out.Schedule - *out = new(string) - **out = **in - } - if in.Timezone != nil { - in, out := &in.Timezone, &out.Timezone - *out = new(string) - **out = **in - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CronParameters. -func (in *CronParameters) DeepCopy() *CronParameters { - if in == nil { - return nil - } - out := new(CronParameters) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Definition) DeepCopyInto(out *Definition) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - in.Status.DeepCopyInto(&out.Status) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Definition. -func (in *Definition) DeepCopy() *Definition { - if in == nil { - return nil - } - out := new(Definition) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Definition) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DefinitionInitParameters) DeepCopyInto(out *DefinitionInitParameters) { - *out = *in - if in.CPULimit != nil { - in, out := &in.CPULimit, &out.CPULimit - *out = new(float64) - **out = **in - } - if in.Command != nil { - in, out := &in.Command, &out.Command - *out = new(string) - **out = **in - } - if in.Cron != nil { - in, out := &in.Cron, &out.Cron - *out = make([]CronInitParameters, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - if in.Description != nil { - in, out := &in.Description, &out.Description - *out = new(string) - **out = **in - } - if in.Env != nil { - in, out := &in.Env, &out.Env - *out = make(map[string]*string, len(*in)) - for key, val := range *in { - var outVal *string - if val == nil { - (*out)[key] = nil - } else { - inVal := (*in)[key] - in, out := &inVal, &outVal - *out = new(string) - **out = **in - } - (*out)[key] = outVal - } - } - if in.ImageURI != nil { - in, out := &in.ImageURI, &out.ImageURI - *out = new(string) - **out = **in - } - if in.MemoryLimit != nil { - in, out := &in.MemoryLimit, &out.MemoryLimit - *out = new(float64) - **out = **in - } - if in.Name != nil { - in, out := &in.Name, &out.Name - *out = new(string) - **out = **in - } - if in.ProjectID != nil { - in, out := &in.ProjectID, &out.ProjectID - *out = new(string) - **out = **in - } - if in.Region != nil { - in, out := &in.Region, &out.Region - *out = new(string) - **out = **in - } - if in.Timeout != nil { - in, out := &in.Timeout, &out.Timeout - *out = new(string) - **out = **in - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DefinitionInitParameters. -func (in *DefinitionInitParameters) DeepCopy() *DefinitionInitParameters { - if in == nil { - return nil - } - out := new(DefinitionInitParameters) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DefinitionList) DeepCopyInto(out *DefinitionList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Definition, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DefinitionList. -func (in *DefinitionList) DeepCopy() *DefinitionList { - if in == nil { - return nil - } - out := new(DefinitionList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *DefinitionList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DefinitionObservation) DeepCopyInto(out *DefinitionObservation) { - *out = *in - if in.CPULimit != nil { - in, out := &in.CPULimit, &out.CPULimit - *out = new(float64) - **out = **in - } - if in.Command != nil { - in, out := &in.Command, &out.Command - *out = new(string) - **out = **in - } - if in.Cron != nil { - in, out := &in.Cron, &out.Cron - *out = make([]CronObservation, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - if in.Description != nil { - in, out := &in.Description, &out.Description - *out = new(string) - **out = **in - } - if in.Env != nil { - in, out := &in.Env, &out.Env - *out = make(map[string]*string, len(*in)) - for key, val := range *in { - var outVal *string - if val == nil { - (*out)[key] = nil - } else { - inVal := (*in)[key] - in, out := &inVal, &outVal - *out = new(string) - **out = **in - } - (*out)[key] = outVal - } - } - if in.ID != nil { - in, out := &in.ID, &out.ID - *out = new(string) - **out = **in - } - if in.ImageURI != nil { - in, out := &in.ImageURI, &out.ImageURI - *out = new(string) - **out = **in - } - if in.MemoryLimit != nil { - in, out := &in.MemoryLimit, &out.MemoryLimit - *out = new(float64) - **out = **in - } - if in.Name != nil { - in, out := &in.Name, &out.Name - *out = new(string) - **out = **in - } - if in.ProjectID != nil { - in, out := &in.ProjectID, &out.ProjectID - *out = new(string) - **out = **in - } - if in.Region != nil { - in, out := &in.Region, &out.Region - *out = new(string) - **out = **in - } - if in.Timeout != nil { - in, out := &in.Timeout, &out.Timeout - *out = new(string) - **out = **in - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DefinitionObservation. -func (in *DefinitionObservation) DeepCopy() *DefinitionObservation { - if in == nil { - return nil - } - out := new(DefinitionObservation) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DefinitionParameters) DeepCopyInto(out *DefinitionParameters) { - *out = *in - if in.CPULimit != nil { - in, out := &in.CPULimit, &out.CPULimit - *out = new(float64) - **out = **in - } - if in.Command != nil { - in, out := &in.Command, &out.Command - *out = new(string) - **out = **in - } - if in.Cron != nil { - in, out := &in.Cron, &out.Cron - *out = make([]CronParameters, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - if in.Description != nil { - in, out := &in.Description, &out.Description - *out = new(string) - **out = **in - } - if in.Env != nil { - in, out := &in.Env, &out.Env - *out = make(map[string]*string, len(*in)) - for key, val := range *in { - var outVal *string - if val == nil { - (*out)[key] = nil - } else { - inVal := (*in)[key] - in, out := &inVal, &outVal - *out = new(string) - **out = **in - } - (*out)[key] = outVal - } - } - if in.ImageURI != nil { - in, out := &in.ImageURI, &out.ImageURI - *out = new(string) - **out = **in - } - if in.MemoryLimit != nil { - in, out := &in.MemoryLimit, &out.MemoryLimit - *out = new(float64) - **out = **in - } - if in.Name != nil { - in, out := &in.Name, &out.Name - *out = new(string) - **out = **in - } - if in.ProjectID != nil { - in, out := &in.ProjectID, &out.ProjectID - *out = new(string) - **out = **in - } - if in.Region != nil { - in, out := &in.Region, &out.Region - *out = new(string) - **out = **in - } - if in.Timeout != nil { - in, out := &in.Timeout, &out.Timeout - *out = new(string) - **out = **in - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DefinitionParameters. -func (in *DefinitionParameters) DeepCopy() *DefinitionParameters { - if in == nil { - return nil - } - out := new(DefinitionParameters) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DefinitionSpec) DeepCopyInto(out *DefinitionSpec) { - *out = *in - in.ResourceSpec.DeepCopyInto(&out.ResourceSpec) - in.ForProvider.DeepCopyInto(&out.ForProvider) - in.InitProvider.DeepCopyInto(&out.InitProvider) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DefinitionSpec. -func (in *DefinitionSpec) DeepCopy() *DefinitionSpec { - if in == nil { - return nil - } - out := new(DefinitionSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DefinitionStatus) DeepCopyInto(out *DefinitionStatus) { - *out = *in - in.ResourceStatus.DeepCopyInto(&out.ResourceStatus) - in.AtProvider.DeepCopyInto(&out.AtProvider) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DefinitionStatus. -func (in *DefinitionStatus) DeepCopy() *DefinitionStatus { - if in == nil { - return nil - } - out := new(DefinitionStatus) - in.DeepCopyInto(out) - return out -} diff --git a/apis/jobs/v1alpha1/zz_generated.managed.go b/apis/jobs/v1alpha1/zz_generated.managed.go deleted file mode 100644 index e0d8e80..0000000 --- a/apis/jobs/v1alpha1/zz_generated.managed.go +++ /dev/null @@ -1,68 +0,0 @@ -/* -Copyright 2022 Upbound Inc. -*/ -// Code generated by angryjet. DO NOT EDIT. - -package v1alpha1 - -import xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" - -// GetCondition of this Definition. -func (mg *Definition) GetCondition(ct xpv1.ConditionType) xpv1.Condition { - return mg.Status.GetCondition(ct) -} - -// GetDeletionPolicy of this Definition. -func (mg *Definition) GetDeletionPolicy() xpv1.DeletionPolicy { - return mg.Spec.DeletionPolicy -} - -// GetManagementPolicies of this Definition. -func (mg *Definition) GetManagementPolicies() xpv1.ManagementPolicies { - return mg.Spec.ManagementPolicies -} - -// GetProviderConfigReference of this Definition. -func (mg *Definition) GetProviderConfigReference() *xpv1.Reference { - return mg.Spec.ProviderConfigReference -} - -// GetPublishConnectionDetailsTo of this Definition. -func (mg *Definition) GetPublishConnectionDetailsTo() *xpv1.PublishConnectionDetailsTo { - return mg.Spec.PublishConnectionDetailsTo -} - -// GetWriteConnectionSecretToReference of this Definition. -func (mg *Definition) GetWriteConnectionSecretToReference() *xpv1.SecretReference { - return mg.Spec.WriteConnectionSecretToReference -} - -// SetConditions of this Definition. -func (mg *Definition) SetConditions(c ...xpv1.Condition) { - mg.Status.SetConditions(c...) -} - -// SetDeletionPolicy of this Definition. -func (mg *Definition) SetDeletionPolicy(r xpv1.DeletionPolicy) { - mg.Spec.DeletionPolicy = r -} - -// SetManagementPolicies of this Definition. -func (mg *Definition) SetManagementPolicies(r xpv1.ManagementPolicies) { - mg.Spec.ManagementPolicies = r -} - -// SetProviderConfigReference of this Definition. -func (mg *Definition) SetProviderConfigReference(r *xpv1.Reference) { - mg.Spec.ProviderConfigReference = r -} - -// SetPublishConnectionDetailsTo of this Definition. -func (mg *Definition) SetPublishConnectionDetailsTo(r *xpv1.PublishConnectionDetailsTo) { - mg.Spec.PublishConnectionDetailsTo = r -} - -// SetWriteConnectionSecretToReference of this Definition. -func (mg *Definition) SetWriteConnectionSecretToReference(r *xpv1.SecretReference) { - mg.Spec.WriteConnectionSecretToReference = r -} diff --git a/apis/jobs/v1alpha1/zz_generated.managedlist.go b/apis/jobs/v1alpha1/zz_generated.managedlist.go deleted file mode 100644 index 92f1c52..0000000 --- a/apis/jobs/v1alpha1/zz_generated.managedlist.go +++ /dev/null @@ -1,17 +0,0 @@ -/* -Copyright 2022 Upbound Inc. -*/ -// Code generated by angryjet. DO NOT EDIT. - -package v1alpha1 - -import resource "github.com/crossplane/crossplane-runtime/pkg/resource" - -// GetItems of this DefinitionList. -func (l *DefinitionList) GetItems() []resource.Managed { - items := make([]resource.Managed, len(l.Items)) - for i := range l.Items { - items[i] = &l.Items[i] - } - return items -} diff --git a/apis/jobs/v1alpha1/zz_groupversion_info.go b/apis/jobs/v1alpha1/zz_groupversion_info.go deleted file mode 100755 index 9d09474..0000000 --- a/apis/jobs/v1alpha1/zz_groupversion_info.go +++ /dev/null @@ -1,32 +0,0 @@ -/* -Copyright 2022 Upbound Inc. -*/ - -// Code generated by upjet. DO NOT EDIT. - -// +kubebuilder:object:generate=true -// +groupName=jobs.scaleway.upbound.io -// +versionName=v1alpha1 -package v1alpha1 - -import ( - "k8s.io/apimachinery/pkg/runtime/schema" - "sigs.k8s.io/controller-runtime/pkg/scheme" -) - -// Package type metadata. -const ( - CRDGroup = "jobs.scaleway.upbound.io" - CRDVersion = "v1alpha1" -) - -var ( - // CRDGroupVersion is the API Group Version used to register the objects - CRDGroupVersion = schema.GroupVersion{Group: CRDGroup, Version: CRDVersion} - - // SchemeBuilder is used to add go types to the GroupVersionKind scheme - SchemeBuilder = &scheme.Builder{GroupVersion: CRDGroupVersion} - - // AddToScheme adds the types in this group-version to the given scheme. - AddToScheme = SchemeBuilder.AddToScheme -) diff --git a/apis/sdb/v1alpha1/zz_generated.conversion_hubs.go b/apis/sdb/v1alpha1/zz_generated.conversion_hubs.go deleted file mode 100755 index 0c5f5da..0000000 --- a/apis/sdb/v1alpha1/zz_generated.conversion_hubs.go +++ /dev/null @@ -1,10 +0,0 @@ -/* -Copyright 2022 Upbound Inc. -*/ - -// Code generated by upjet. DO NOT EDIT. - -package v1alpha1 - -// Hub marks this type as a conversion hub. -func (tr *SQLDatabase) Hub() {} diff --git a/apis/sdb/v1alpha1/zz_generated.deepcopy.go b/apis/sdb/v1alpha1/zz_generated.deepcopy.go deleted file mode 100644 index 93a9621..0000000 --- a/apis/sdb/v1alpha1/zz_generated.deepcopy.go +++ /dev/null @@ -1,222 +0,0 @@ -//go:build !ignore_autogenerated - -/* -Copyright 2022 Upbound Inc. -*/ - -// Code generated by controller-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - runtime "k8s.io/apimachinery/pkg/runtime" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SQLDatabase) DeepCopyInto(out *SQLDatabase) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - in.Status.DeepCopyInto(&out.Status) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SQLDatabase. -func (in *SQLDatabase) DeepCopy() *SQLDatabase { - if in == nil { - return nil - } - out := new(SQLDatabase) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *SQLDatabase) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SQLDatabaseInitParameters) DeepCopyInto(out *SQLDatabaseInitParameters) { - *out = *in - if in.MaxCPU != nil { - in, out := &in.MaxCPU, &out.MaxCPU - *out = new(float64) - **out = **in - } - if in.MinCPU != nil { - in, out := &in.MinCPU, &out.MinCPU - *out = new(float64) - **out = **in - } - if in.ProjectID != nil { - in, out := &in.ProjectID, &out.ProjectID - *out = new(string) - **out = **in - } - if in.Region != nil { - in, out := &in.Region, &out.Region - *out = new(string) - **out = **in - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SQLDatabaseInitParameters. -func (in *SQLDatabaseInitParameters) DeepCopy() *SQLDatabaseInitParameters { - if in == nil { - return nil - } - out := new(SQLDatabaseInitParameters) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SQLDatabaseList) DeepCopyInto(out *SQLDatabaseList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]SQLDatabase, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SQLDatabaseList. -func (in *SQLDatabaseList) DeepCopy() *SQLDatabaseList { - if in == nil { - return nil - } - out := new(SQLDatabaseList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *SQLDatabaseList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SQLDatabaseObservation) DeepCopyInto(out *SQLDatabaseObservation) { - *out = *in - if in.Endpoint != nil { - in, out := &in.Endpoint, &out.Endpoint - *out = new(string) - **out = **in - } - if in.ID != nil { - in, out := &in.ID, &out.ID - *out = new(string) - **out = **in - } - if in.MaxCPU != nil { - in, out := &in.MaxCPU, &out.MaxCPU - *out = new(float64) - **out = **in - } - if in.MinCPU != nil { - in, out := &in.MinCPU, &out.MinCPU - *out = new(float64) - **out = **in - } - if in.ProjectID != nil { - in, out := &in.ProjectID, &out.ProjectID - *out = new(string) - **out = **in - } - if in.Region != nil { - in, out := &in.Region, &out.Region - *out = new(string) - **out = **in - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SQLDatabaseObservation. -func (in *SQLDatabaseObservation) DeepCopy() *SQLDatabaseObservation { - if in == nil { - return nil - } - out := new(SQLDatabaseObservation) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SQLDatabaseParameters) DeepCopyInto(out *SQLDatabaseParameters) { - *out = *in - if in.MaxCPU != nil { - in, out := &in.MaxCPU, &out.MaxCPU - *out = new(float64) - **out = **in - } - if in.MinCPU != nil { - in, out := &in.MinCPU, &out.MinCPU - *out = new(float64) - **out = **in - } - if in.ProjectID != nil { - in, out := &in.ProjectID, &out.ProjectID - *out = new(string) - **out = **in - } - if in.Region != nil { - in, out := &in.Region, &out.Region - *out = new(string) - **out = **in - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SQLDatabaseParameters. -func (in *SQLDatabaseParameters) DeepCopy() *SQLDatabaseParameters { - if in == nil { - return nil - } - out := new(SQLDatabaseParameters) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SQLDatabaseSpec) DeepCopyInto(out *SQLDatabaseSpec) { - *out = *in - in.ResourceSpec.DeepCopyInto(&out.ResourceSpec) - in.ForProvider.DeepCopyInto(&out.ForProvider) - in.InitProvider.DeepCopyInto(&out.InitProvider) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SQLDatabaseSpec. -func (in *SQLDatabaseSpec) DeepCopy() *SQLDatabaseSpec { - if in == nil { - return nil - } - out := new(SQLDatabaseSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SQLDatabaseStatus) DeepCopyInto(out *SQLDatabaseStatus) { - *out = *in - in.ResourceStatus.DeepCopyInto(&out.ResourceStatus) - in.AtProvider.DeepCopyInto(&out.AtProvider) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SQLDatabaseStatus. -func (in *SQLDatabaseStatus) DeepCopy() *SQLDatabaseStatus { - if in == nil { - return nil - } - out := new(SQLDatabaseStatus) - in.DeepCopyInto(out) - return out -} diff --git a/apis/sdb/v1alpha1/zz_generated.managed.go b/apis/sdb/v1alpha1/zz_generated.managed.go deleted file mode 100644 index 5e44c01..0000000 --- a/apis/sdb/v1alpha1/zz_generated.managed.go +++ /dev/null @@ -1,68 +0,0 @@ -/* -Copyright 2022 Upbound Inc. -*/ -// Code generated by angryjet. DO NOT EDIT. - -package v1alpha1 - -import xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" - -// GetCondition of this SQLDatabase. -func (mg *SQLDatabase) GetCondition(ct xpv1.ConditionType) xpv1.Condition { - return mg.Status.GetCondition(ct) -} - -// GetDeletionPolicy of this SQLDatabase. -func (mg *SQLDatabase) GetDeletionPolicy() xpv1.DeletionPolicy { - return mg.Spec.DeletionPolicy -} - -// GetManagementPolicies of this SQLDatabase. -func (mg *SQLDatabase) GetManagementPolicies() xpv1.ManagementPolicies { - return mg.Spec.ManagementPolicies -} - -// GetProviderConfigReference of this SQLDatabase. -func (mg *SQLDatabase) GetProviderConfigReference() *xpv1.Reference { - return mg.Spec.ProviderConfigReference -} - -// GetPublishConnectionDetailsTo of this SQLDatabase. -func (mg *SQLDatabase) GetPublishConnectionDetailsTo() *xpv1.PublishConnectionDetailsTo { - return mg.Spec.PublishConnectionDetailsTo -} - -// GetWriteConnectionSecretToReference of this SQLDatabase. -func (mg *SQLDatabase) GetWriteConnectionSecretToReference() *xpv1.SecretReference { - return mg.Spec.WriteConnectionSecretToReference -} - -// SetConditions of this SQLDatabase. -func (mg *SQLDatabase) SetConditions(c ...xpv1.Condition) { - mg.Status.SetConditions(c...) -} - -// SetDeletionPolicy of this SQLDatabase. -func (mg *SQLDatabase) SetDeletionPolicy(r xpv1.DeletionPolicy) { - mg.Spec.DeletionPolicy = r -} - -// SetManagementPolicies of this SQLDatabase. -func (mg *SQLDatabase) SetManagementPolicies(r xpv1.ManagementPolicies) { - mg.Spec.ManagementPolicies = r -} - -// SetProviderConfigReference of this SQLDatabase. -func (mg *SQLDatabase) SetProviderConfigReference(r *xpv1.Reference) { - mg.Spec.ProviderConfigReference = r -} - -// SetPublishConnectionDetailsTo of this SQLDatabase. -func (mg *SQLDatabase) SetPublishConnectionDetailsTo(r *xpv1.PublishConnectionDetailsTo) { - mg.Spec.PublishConnectionDetailsTo = r -} - -// SetWriteConnectionSecretToReference of this SQLDatabase. -func (mg *SQLDatabase) SetWriteConnectionSecretToReference(r *xpv1.SecretReference) { - mg.Spec.WriteConnectionSecretToReference = r -} diff --git a/apis/sdb/v1alpha1/zz_generated.managedlist.go b/apis/sdb/v1alpha1/zz_generated.managedlist.go deleted file mode 100644 index c02e2fb..0000000 --- a/apis/sdb/v1alpha1/zz_generated.managedlist.go +++ /dev/null @@ -1,17 +0,0 @@ -/* -Copyright 2022 Upbound Inc. -*/ -// Code generated by angryjet. DO NOT EDIT. - -package v1alpha1 - -import resource "github.com/crossplane/crossplane-runtime/pkg/resource" - -// GetItems of this SQLDatabaseList. -func (l *SQLDatabaseList) GetItems() []resource.Managed { - items := make([]resource.Managed, len(l.Items)) - for i := range l.Items { - items[i] = &l.Items[i] - } - return items -} diff --git a/apis/sdb/v1alpha1/zz_groupversion_info.go b/apis/sdb/v1alpha1/zz_groupversion_info.go deleted file mode 100755 index 2e10bbe..0000000 --- a/apis/sdb/v1alpha1/zz_groupversion_info.go +++ /dev/null @@ -1,32 +0,0 @@ -/* -Copyright 2022 Upbound Inc. -*/ - -// Code generated by upjet. DO NOT EDIT. - -// +kubebuilder:object:generate=true -// +groupName=sdb.scaleway.upbound.io -// +versionName=v1alpha1 -package v1alpha1 - -import ( - "k8s.io/apimachinery/pkg/runtime/schema" - "sigs.k8s.io/controller-runtime/pkg/scheme" -) - -// Package type metadata. -const ( - CRDGroup = "sdb.scaleway.upbound.io" - CRDVersion = "v1alpha1" -) - -var ( - // CRDGroupVersion is the API Group Version used to register the objects - CRDGroupVersion = schema.GroupVersion{Group: CRDGroup, Version: CRDVersion} - - // SchemeBuilder is used to add go types to the GroupVersionKind scheme - SchemeBuilder = &scheme.Builder{GroupVersion: CRDGroupVersion} - - // AddToScheme adds the types in this group-version to the given scheme. - AddToScheme = SchemeBuilder.AddToScheme -) diff --git a/apis/sdb/v1alpha1/zz_sqldatabase_terraformed.go b/apis/sdb/v1alpha1/zz_sqldatabase_terraformed.go deleted file mode 100755 index 7d1f77b..0000000 --- a/apis/sdb/v1alpha1/zz_sqldatabase_terraformed.go +++ /dev/null @@ -1,129 +0,0 @@ -/* -Copyright 2022 Upbound Inc. -*/ - -// Code generated by upjet. DO NOT EDIT. - -package v1alpha1 - -import ( - "dario.cat/mergo" - "github.com/pkg/errors" - - "github.com/crossplane/upjet/pkg/resource" - "github.com/crossplane/upjet/pkg/resource/json" -) - -// GetTerraformResourceType returns Terraform resource type for this SQLDatabase -func (mg *SQLDatabase) GetTerraformResourceType() string { - return "scaleway_sdb_sql_database" -} - -// GetConnectionDetailsMapping for this SQLDatabase -func (tr *SQLDatabase) GetConnectionDetailsMapping() map[string]string { - return nil -} - -// GetObservation of this SQLDatabase -func (tr *SQLDatabase) GetObservation() (map[string]any, error) { - o, err := json.TFParser.Marshal(tr.Status.AtProvider) - if err != nil { - return nil, err - } - base := map[string]any{} - return base, json.TFParser.Unmarshal(o, &base) -} - -// SetObservation for this SQLDatabase -func (tr *SQLDatabase) SetObservation(obs map[string]any) error { - p, err := json.TFParser.Marshal(obs) - if err != nil { - return err - } - return json.TFParser.Unmarshal(p, &tr.Status.AtProvider) -} - -// GetID returns ID of underlying Terraform resource of this SQLDatabase -func (tr *SQLDatabase) GetID() string { - if tr.Status.AtProvider.ID == nil { - return "" - } - return *tr.Status.AtProvider.ID -} - -// GetParameters of this SQLDatabase -func (tr *SQLDatabase) GetParameters() (map[string]any, error) { - p, err := json.TFParser.Marshal(tr.Spec.ForProvider) - if err != nil { - return nil, err - } - base := map[string]any{} - return base, json.TFParser.Unmarshal(p, &base) -} - -// SetParameters for this SQLDatabase -func (tr *SQLDatabase) SetParameters(params map[string]any) error { - p, err := json.TFParser.Marshal(params) - if err != nil { - return err - } - return json.TFParser.Unmarshal(p, &tr.Spec.ForProvider) -} - -// GetInitParameters of this SQLDatabase -func (tr *SQLDatabase) GetInitParameters() (map[string]any, error) { - p, err := json.TFParser.Marshal(tr.Spec.InitProvider) - if err != nil { - return nil, err - } - base := map[string]any{} - return base, json.TFParser.Unmarshal(p, &base) -} - -// GetInitParameters of this SQLDatabase -func (tr *SQLDatabase) GetMergedParameters(shouldMergeInitProvider bool) (map[string]any, error) { - params, err := tr.GetParameters() - if err != nil { - return nil, errors.Wrapf(err, "cannot get parameters for resource '%q'", tr.GetName()) - } - if !shouldMergeInitProvider { - return params, nil - } - - initParams, err := tr.GetInitParameters() - if err != nil { - return nil, errors.Wrapf(err, "cannot get init parameters for resource '%q'", tr.GetName()) - } - - // Note(lsviben): mergo.WithSliceDeepCopy is needed to merge the - // slices from the initProvider to forProvider. As it also sets - // overwrite to true, we need to set it back to false, we don't - // want to overwrite the forProvider fields with the initProvider - // fields. - err = mergo.Merge(¶ms, initParams, mergo.WithSliceDeepCopy, func(c *mergo.Config) { - c.Overwrite = false - }) - if err != nil { - return nil, errors.Wrapf(err, "cannot merge spec.initProvider and spec.forProvider parameters for resource '%q'", tr.GetName()) - } - - return params, nil -} - -// LateInitialize this SQLDatabase using its observed tfState. -// returns True if there are any spec changes for the resource. -func (tr *SQLDatabase) LateInitialize(attrs []byte) (bool, error) { - params := &SQLDatabaseParameters{} - if err := json.TFParser.Unmarshal(attrs, params); err != nil { - return false, errors.Wrap(err, "failed to unmarshal Terraform state parameters for late-initialization") - } - opts := []resource.GenericLateInitializerOption{resource.WithZeroValueJSONOmitEmptyFilter(resource.CNameWildcard)} - - li := resource.NewGenericLateInitializer(opts...) - return li.LateInitialize(&tr.Spec.ForProvider, params) -} - -// GetTerraformSchemaVersion returns the associated Terraform schema version -func (tr *SQLDatabase) GetTerraformSchemaVersion() int { - return 0 -} diff --git a/apis/sdb/v1alpha1/zz_sqldatabase_types.go b/apis/sdb/v1alpha1/zz_sqldatabase_types.go deleted file mode 100755 index 66e262b..0000000 --- a/apis/sdb/v1alpha1/zz_sqldatabase_types.go +++ /dev/null @@ -1,143 +0,0 @@ -/* -Copyright 2022 Upbound Inc. -*/ - -// Code generated by upjet. DO NOT EDIT. - -package v1alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" - - v1 "github.com/crossplane/crossplane-runtime/apis/common/v1" -) - -type SQLDatabaseInitParameters struct { - - // The maximum number of CPU units for your database. Defaults to 15. - // The maximum number of CPU units for your Serverless SQL Database - MaxCPU *float64 `json:"maxCpu,omitempty" tf:"max_cpu,omitempty"` - - // The minimum number of CPU units for your database. Defaults to 0. - // The minimum number of CPU units for your Serverless SQL Database - MinCPU *float64 `json:"minCpu,omitempty" tf:"min_cpu,omitempty"` - - // The ID of the database, which is of the form {region}/{id} e.g. fr-par/11111111-1111-1111-1111-111111111111 - // The project_id you want to attach the resource to - ProjectID *string `json:"projectId,omitempty" tf:"project_id,omitempty"` - - // (Defaults to provider region) The region in which the resource exists. - // The region you want to attach the resource to - Region *string `json:"region,omitempty" tf:"region,omitempty"` -} - -type SQLDatabaseObservation struct { - - // Endpoint of the database - // endpoint of the database - Endpoint *string `json:"endpoint,omitempty" tf:"endpoint,omitempty"` - - // The ID of the database, which is of the form {region}/{id} e.g. fr-par/11111111-1111-1111-1111-111111111111 - ID *string `json:"id,omitempty" tf:"id,omitempty"` - - // The maximum number of CPU units for your database. Defaults to 15. - // The maximum number of CPU units for your Serverless SQL Database - MaxCPU *float64 `json:"maxCpu,omitempty" tf:"max_cpu,omitempty"` - - // The minimum number of CPU units for your database. Defaults to 0. - // The minimum number of CPU units for your Serverless SQL Database - MinCPU *float64 `json:"minCpu,omitempty" tf:"min_cpu,omitempty"` - - // The ID of the database, which is of the form {region}/{id} e.g. fr-par/11111111-1111-1111-1111-111111111111 - // The project_id you want to attach the resource to - ProjectID *string `json:"projectId,omitempty" tf:"project_id,omitempty"` - - // (Defaults to provider region) The region in which the resource exists. - // The region you want to attach the resource to - Region *string `json:"region,omitempty" tf:"region,omitempty"` -} - -type SQLDatabaseParameters struct { - - // The maximum number of CPU units for your database. Defaults to 15. - // The maximum number of CPU units for your Serverless SQL Database - // +kubebuilder:validation:Optional - MaxCPU *float64 `json:"maxCpu,omitempty" tf:"max_cpu,omitempty"` - - // The minimum number of CPU units for your database. Defaults to 0. - // The minimum number of CPU units for your Serverless SQL Database - // +kubebuilder:validation:Optional - MinCPU *float64 `json:"minCpu,omitempty" tf:"min_cpu,omitempty"` - - // The ID of the database, which is of the form {region}/{id} e.g. fr-par/11111111-1111-1111-1111-111111111111 - // The project_id you want to attach the resource to - // +kubebuilder:validation:Optional - ProjectID *string `json:"projectId,omitempty" tf:"project_id,omitempty"` - - // (Defaults to provider region) The region in which the resource exists. - // The region you want to attach the resource to - // +kubebuilder:validation:Optional - Region *string `json:"region,omitempty" tf:"region,omitempty"` -} - -// SQLDatabaseSpec defines the desired state of SQLDatabase -type SQLDatabaseSpec struct { - v1.ResourceSpec `json:",inline"` - ForProvider SQLDatabaseParameters `json:"forProvider"` - // THIS IS A BETA FIELD. It will be honored - // unless the Management Policies feature flag is disabled. - // InitProvider holds the same fields as ForProvider, with the exception - // of Identifier and other resource reference fields. The fields that are - // in InitProvider are merged into ForProvider when the resource is created. - // The same fields are also added to the terraform ignore_changes hook, to - // avoid updating them after creation. This is useful for fields that are - // required on creation, but we do not desire to update them after creation, - // for example because of an external controller is managing them, like an - // autoscaler. - InitProvider SQLDatabaseInitParameters `json:"initProvider,omitempty"` -} - -// SQLDatabaseStatus defines the observed state of SQLDatabase. -type SQLDatabaseStatus struct { - v1.ResourceStatus `json:",inline"` - AtProvider SQLDatabaseObservation `json:"atProvider,omitempty"` -} - -// +kubebuilder:object:root=true -// +kubebuilder:subresource:status -// +kubebuilder:storageversion - -// SQLDatabase is the Schema for the SQLDatabases API. -// +kubebuilder:printcolumn:name="SYNCED",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status" -// +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status" -// +kubebuilder:printcolumn:name="EXTERNAL-NAME",type="string",JSONPath=".metadata.annotations.crossplane\\.io/external-name" -// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp" -// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,scaleway} -type SQLDatabase struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - Spec SQLDatabaseSpec `json:"spec"` - Status SQLDatabaseStatus `json:"status,omitempty"` -} - -// +kubebuilder:object:root=true - -// SQLDatabaseList contains a list of SQLDatabases -type SQLDatabaseList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []SQLDatabase `json:"items"` -} - -// Repository type metadata. -var ( - SQLDatabase_Kind = "SQLDatabase" - SQLDatabase_GroupKind = schema.GroupKind{Group: CRDGroup, Kind: SQLDatabase_Kind}.String() - SQLDatabase_KindAPIVersion = SQLDatabase_Kind + "." + CRDGroupVersion.String() - SQLDatabase_GroupVersionKind = CRDGroupVersion.WithKind(SQLDatabase_Kind) -) - -func init() { - SchemeBuilder.Register(&SQLDatabase{}, &SQLDatabaseList{}) -} diff --git a/go.mod b/go.mod index d6fd3f6..4f6d917 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ require ( github.com/crossplane/crossplane-tools v0.0.0-20230925130601-628280f8bf79 github.com/crossplane/upjet v1.4.1 github.com/pkg/errors v0.9.1 + golang.org/x/text v0.14.0 gopkg.in/yaml.v3 v3.0.1 k8s.io/apimachinery v0.30.3 k8s.io/client-go v0.29.4 @@ -108,7 +109,6 @@ require ( golang.org/x/oauth2 v0.15.0 // indirect golang.org/x/sys v0.18.0 // indirect golang.org/x/term v0.18.0 // indirect - golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.5.0 // indirect golang.org/x/tools v0.18.0 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect From a6631a37f74c1c5fdd5b14edca07d5b50ce5b2e0 Mon Sep 17 00:00:00 2001 From: Yacine FODIL Date: Wed, 7 Aug 2024 10:10:36 +0200 Subject: [PATCH 17/24] fix --- .../v1alpha1/zz_definition_terraformed.go | 129 ++++++ apis/jobs/v1alpha1/zz_definition_types.go | 240 ++++++++++ .../v1alpha1/zz_generated.conversion_hubs.go | 10 + apis/jobs/v1alpha1/zz_generated.deepcopy.go | 436 ++++++++++++++++++ apis/jobs/v1alpha1/zz_generated.managed.go | 68 +++ .../jobs/v1alpha1/zz_generated.managedlist.go | 17 + apis/jobs/v1alpha1/zz_groupversion_info.go | 32 ++ 7 files changed, 932 insertions(+) create mode 100755 apis/jobs/v1alpha1/zz_definition_terraformed.go create mode 100755 apis/jobs/v1alpha1/zz_definition_types.go create mode 100755 apis/jobs/v1alpha1/zz_generated.conversion_hubs.go create mode 100644 apis/jobs/v1alpha1/zz_generated.deepcopy.go create mode 100644 apis/jobs/v1alpha1/zz_generated.managed.go create mode 100644 apis/jobs/v1alpha1/zz_generated.managedlist.go create mode 100755 apis/jobs/v1alpha1/zz_groupversion_info.go diff --git a/apis/jobs/v1alpha1/zz_definition_terraformed.go b/apis/jobs/v1alpha1/zz_definition_terraformed.go new file mode 100755 index 0000000..5c02d4f --- /dev/null +++ b/apis/jobs/v1alpha1/zz_definition_terraformed.go @@ -0,0 +1,129 @@ +/* +Copyright 2022 Upbound Inc. +*/ + +// Code generated by upjet. DO NOT EDIT. + +package v1alpha1 + +import ( + "dario.cat/mergo" + "github.com/pkg/errors" + + "github.com/crossplane/upjet/pkg/resource" + "github.com/crossplane/upjet/pkg/resource/json" +) + +// GetTerraformResourceType returns Terraform resource type for this Definition +func (mg *Definition) GetTerraformResourceType() string { + return "scaleway_job_definition" +} + +// GetConnectionDetailsMapping for this Definition +func (tr *Definition) GetConnectionDetailsMapping() map[string]string { + return nil +} + +// GetObservation of this Definition +func (tr *Definition) GetObservation() (map[string]any, error) { + o, err := json.TFParser.Marshal(tr.Status.AtProvider) + if err != nil { + return nil, err + } + base := map[string]any{} + return base, json.TFParser.Unmarshal(o, &base) +} + +// SetObservation for this Definition +func (tr *Definition) SetObservation(obs map[string]any) error { + p, err := json.TFParser.Marshal(obs) + if err != nil { + return err + } + return json.TFParser.Unmarshal(p, &tr.Status.AtProvider) +} + +// GetID returns ID of underlying Terraform resource of this Definition +func (tr *Definition) GetID() string { + if tr.Status.AtProvider.ID == nil { + return "" + } + return *tr.Status.AtProvider.ID +} + +// GetParameters of this Definition +func (tr *Definition) GetParameters() (map[string]any, error) { + p, err := json.TFParser.Marshal(tr.Spec.ForProvider) + if err != nil { + return nil, err + } + base := map[string]any{} + return base, json.TFParser.Unmarshal(p, &base) +} + +// SetParameters for this Definition +func (tr *Definition) SetParameters(params map[string]any) error { + p, err := json.TFParser.Marshal(params) + if err != nil { + return err + } + return json.TFParser.Unmarshal(p, &tr.Spec.ForProvider) +} + +// GetInitParameters of this Definition +func (tr *Definition) GetInitParameters() (map[string]any, error) { + p, err := json.TFParser.Marshal(tr.Spec.InitProvider) + if err != nil { + return nil, err + } + base := map[string]any{} + return base, json.TFParser.Unmarshal(p, &base) +} + +// GetInitParameters of this Definition +func (tr *Definition) GetMergedParameters(shouldMergeInitProvider bool) (map[string]any, error) { + params, err := tr.GetParameters() + if err != nil { + return nil, errors.Wrapf(err, "cannot get parameters for resource '%q'", tr.GetName()) + } + if !shouldMergeInitProvider { + return params, nil + } + + initParams, err := tr.GetInitParameters() + if err != nil { + return nil, errors.Wrapf(err, "cannot get init parameters for resource '%q'", tr.GetName()) + } + + // Note(lsviben): mergo.WithSliceDeepCopy is needed to merge the + // slices from the initProvider to forProvider. As it also sets + // overwrite to true, we need to set it back to false, we don't + // want to overwrite the forProvider fields with the initProvider + // fields. + err = mergo.Merge(¶ms, initParams, mergo.WithSliceDeepCopy, func(c *mergo.Config) { + c.Overwrite = false + }) + if err != nil { + return nil, errors.Wrapf(err, "cannot merge spec.initProvider and spec.forProvider parameters for resource '%q'", tr.GetName()) + } + + return params, nil +} + +// LateInitialize this Definition using its observed tfState. +// returns True if there are any spec changes for the resource. +func (tr *Definition) LateInitialize(attrs []byte) (bool, error) { + params := &DefinitionParameters{} + if err := json.TFParser.Unmarshal(attrs, params); err != nil { + return false, errors.Wrap(err, "failed to unmarshal Terraform state parameters for late-initialization") + } + opts := []resource.GenericLateInitializerOption{resource.WithZeroValueJSONOmitEmptyFilter(resource.CNameWildcard)} + + li := resource.NewGenericLateInitializer(opts...) + return li.LateInitialize(&tr.Spec.ForProvider, params) +} + +// GetTerraformSchemaVersion returns the associated Terraform schema version +func (tr *Definition) GetTerraformSchemaVersion() int { + return 0 +} diff --git a/apis/jobs/v1alpha1/zz_definition_types.go b/apis/jobs/v1alpha1/zz_definition_types.go new file mode 100755 index 0000000..31e2925 --- /dev/null +++ b/apis/jobs/v1alpha1/zz_definition_types.go @@ -0,0 +1,240 @@ +/* +Copyright 2022 Upbound Inc. +*/ + +// Code generated by upjet. DO NOT EDIT. + +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" + + v1 "github.com/crossplane/crossplane-runtime/apis/common/v1" +) + +type CronInitParameters struct { + + // Cron format string. + Schedule *string `json:"schedule,omitempty" tf:"schedule,omitempty"` + + // The timezone, must be a canonical TZ identifier as found in this list. + Timezone *string `json:"timezone,omitempty" tf:"timezone,omitempty"` +} + +type CronObservation struct { + + // Cron format string. + Schedule *string `json:"schedule,omitempty" tf:"schedule,omitempty"` + + // The timezone, must be a canonical TZ identifier as found in this list. + Timezone *string `json:"timezone,omitempty" tf:"timezone,omitempty"` +} + +type CronParameters struct { + + // Cron format string. + // +kubebuilder:validation:Optional + Schedule *string `json:"schedule" tf:"schedule,omitempty"` + + // The timezone, must be a canonical TZ identifier as found in this list. + // +kubebuilder:validation:Optional + Timezone *string `json:"timezone" tf:"timezone,omitempty"` +} + +type DefinitionInitParameters struct { + + // The amount of vCPU computing resources to allocate to each container running the job. + CPULimit *float64 `json:"cpuLimit,omitempty" tf:"cpu_limit,omitempty"` + + // The command that will be run in the container if specified. + Command *string `json:"command,omitempty" tf:"command,omitempty"` + + // The cron configuration + Cron []CronInitParameters `json:"cron,omitempty" tf:"cron,omitempty"` + + // The description of the job + Description *string `json:"description,omitempty" tf:"description,omitempty"` + + // The environment variables of the container. + // +mapType=granular + Env map[string]*string `json:"env,omitempty" tf:"env,omitempty"` + + // The uri of the container image that will be used for the job run. + ImageURI *string `json:"imageUri,omitempty" tf:"image_uri,omitempty"` + + // The memory computing resources in MB to allocate to each container running the job. + MemoryLimit *float64 `json:"memoryLimit,omitempty" tf:"memory_limit,omitempty"` + + // The name of the job. + // The job name + Name *string `json:"name,omitempty" tf:"name,omitempty"` + + // (Defaults to provider project_id) The ID of the project the Job is associated with. + // The project_id you want to attach the resource to + ProjectID *string `json:"projectId,omitempty" tf:"project_id,omitempty"` + + // (Defaults to provider region) The region of the Job. + // The region you want to attach the resource to + Region *string `json:"region,omitempty" tf:"region,omitempty"` + + // The job run timeout, in Go Time format (ex: 2h30m25s) + Timeout *string `json:"timeout,omitempty" tf:"timeout,omitempty"` +} + +type DefinitionObservation struct { + + // The amount of vCPU computing resources to allocate to each container running the job. + CPULimit *float64 `json:"cpuLimit,omitempty" tf:"cpu_limit,omitempty"` + + // The command that will be run in the container if specified. + Command *string `json:"command,omitempty" tf:"command,omitempty"` + + // The cron configuration + Cron []CronObservation `json:"cron,omitempty" tf:"cron,omitempty"` + + // The description of the job + Description *string `json:"description,omitempty" tf:"description,omitempty"` + + // The environment variables of the container. + // +mapType=granular + Env map[string]*string `json:"env,omitempty" tf:"env,omitempty"` + + // The ID of the Job Definition. + ID *string `json:"id,omitempty" tf:"id,omitempty"` + + // The uri of the container image that will be used for the job run. + ImageURI *string `json:"imageUri,omitempty" tf:"image_uri,omitempty"` + + // The memory computing resources in MB to allocate to each container running the job. + MemoryLimit *float64 `json:"memoryLimit,omitempty" tf:"memory_limit,omitempty"` + + // The name of the job. + // The job name + Name *string `json:"name,omitempty" tf:"name,omitempty"` + + // (Defaults to provider project_id) The ID of the project the Job is associated with. + // The project_id you want to attach the resource to + ProjectID *string `json:"projectId,omitempty" tf:"project_id,omitempty"` + + // (Defaults to provider region) The region of the Job. + // The region you want to attach the resource to + Region *string `json:"region,omitempty" tf:"region,omitempty"` + + // The job run timeout, in Go Time format (ex: 2h30m25s) + Timeout *string `json:"timeout,omitempty" tf:"timeout,omitempty"` +} + +type DefinitionParameters struct { + + // The amount of vCPU computing resources to allocate to each container running the job. + // +kubebuilder:validation:Optional + CPULimit *float64 `json:"cpuLimit,omitempty" tf:"cpu_limit,omitempty"` + + // The command that will be run in the container if specified. + // +kubebuilder:validation:Optional + Command *string `json:"command,omitempty" tf:"command,omitempty"` + + // The cron configuration + // +kubebuilder:validation:Optional + Cron []CronParameters `json:"cron,omitempty" tf:"cron,omitempty"` + + // The description of the job + // +kubebuilder:validation:Optional + Description *string `json:"description,omitempty" tf:"description,omitempty"` + + // The environment variables of the container. + // +kubebuilder:validation:Optional + // +mapType=granular + Env map[string]*string `json:"env,omitempty" tf:"env,omitempty"` + + // The uri of the container image that will be used for the job run. + // +kubebuilder:validation:Optional + ImageURI *string `json:"imageUri,omitempty" tf:"image_uri,omitempty"` + + // The memory computing resources in MB to allocate to each container running the job. + // +kubebuilder:validation:Optional + MemoryLimit *float64 `json:"memoryLimit,omitempty" tf:"memory_limit,omitempty"` + + // The name of the job. + // The job name + // +kubebuilder:validation:Optional + Name *string `json:"name,omitempty" tf:"name,omitempty"` + + // (Defaults to provider project_id) The ID of the project the Job is associated with. + // The project_id you want to attach the resource to + // +kubebuilder:validation:Optional + ProjectID *string `json:"projectId,omitempty" tf:"project_id,omitempty"` + + // (Defaults to provider region) The region of the Job. + // The region you want to attach the resource to + // +kubebuilder:validation:Optional + Region *string `json:"region,omitempty" tf:"region,omitempty"` + + // The job run timeout, in Go Time format (ex: 2h30m25s) + // +kubebuilder:validation:Optional + Timeout *string `json:"timeout,omitempty" tf:"timeout,omitempty"` +} + +// DefinitionSpec defines the desired state of Definition +type DefinitionSpec struct { + v1.ResourceSpec `json:",inline"` + ForProvider DefinitionParameters `json:"forProvider"` + // THIS IS A BETA FIELD. It will be honored + // unless the Management Policies feature flag is disabled. + // InitProvider holds the same fields as ForProvider, with the exception + // of Identifier and other resource reference fields. The fields that are + // in InitProvider are merged into ForProvider when the resource is created. + // The same fields are also added to the terraform ignore_changes hook, to + // avoid updating them after creation. This is useful for fields that are + // required on creation, but we do not desire to update them after creation, + // for example because of an external controller is managing them, like an + // autoscaler. + InitProvider DefinitionInitParameters `json:"initProvider,omitempty"` +} + +// DefinitionStatus defines the observed state of Definition. +type DefinitionStatus struct { + v1.ResourceStatus `json:",inline"` + AtProvider DefinitionObservation `json:"atProvider,omitempty"` +} + +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status +// +kubebuilder:storageversion + +// Definition is the Schema for the Definitions API. +// +kubebuilder:printcolumn:name="SYNCED",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status" +// +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status" +// +kubebuilder:printcolumn:name="EXTERNAL-NAME",type="string",JSONPath=".metadata.annotations.crossplane\\.io/external-name" +// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp" +// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,scaleway} +type Definition struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + // +kubebuilder:validation:XValidation:rule="!('*' in self.managementPolicies || 'Create' in self.managementPolicies || 'Update' in self.managementPolicies) || has(self.forProvider.cpuLimit) || (has(self.initProvider) && has(self.initProvider.cpuLimit))",message="spec.forProvider.cpuLimit is a required parameter" + // +kubebuilder:validation:XValidation:rule="!('*' in self.managementPolicies || 'Create' in self.managementPolicies || 'Update' in self.managementPolicies) || has(self.forProvider.memoryLimit) || (has(self.initProvider) && has(self.initProvider.memoryLimit))",message="spec.forProvider.memoryLimit is a required parameter" + Spec DefinitionSpec `json:"spec"` + Status DefinitionStatus `json:"status,omitempty"` +} + +// +kubebuilder:object:root=true + +// DefinitionList contains a list of Definitions +type DefinitionList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []Definition `json:"items"` +} + +// Repository type metadata. +var ( + Definition_Kind = "Definition" + Definition_GroupKind = schema.GroupKind{Group: CRDGroup, Kind: Definition_Kind}.String() + Definition_KindAPIVersion = Definition_Kind + "." + CRDGroupVersion.String() + Definition_GroupVersionKind = CRDGroupVersion.WithKind(Definition_Kind) +) + +func init() { + SchemeBuilder.Register(&Definition{}, &DefinitionList{}) +} diff --git a/apis/jobs/v1alpha1/zz_generated.conversion_hubs.go b/apis/jobs/v1alpha1/zz_generated.conversion_hubs.go new file mode 100755 index 0000000..3bd87d2 --- /dev/null +++ b/apis/jobs/v1alpha1/zz_generated.conversion_hubs.go @@ -0,0 +1,10 @@ +/* +Copyright 2022 Upbound Inc. +*/ + +// Code generated by upjet. DO NOT EDIT. + +package v1alpha1 + +// Hub marks this type as a conversion hub. +func (tr *Definition) Hub() {} diff --git a/apis/jobs/v1alpha1/zz_generated.deepcopy.go b/apis/jobs/v1alpha1/zz_generated.deepcopy.go new file mode 100644 index 0000000..fb55d94 --- /dev/null +++ b/apis/jobs/v1alpha1/zz_generated.deepcopy.go @@ -0,0 +1,436 @@ +//go:build !ignore_autogenerated + +/* +Copyright 2022 Upbound Inc. +*/ + +// Code generated by controller-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CronInitParameters) DeepCopyInto(out *CronInitParameters) { + *out = *in + if in.Schedule != nil { + in, out := &in.Schedule, &out.Schedule + *out = new(string) + **out = **in + } + if in.Timezone != nil { + in, out := &in.Timezone, &out.Timezone + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CronInitParameters. +func (in *CronInitParameters) DeepCopy() *CronInitParameters { + if in == nil { + return nil + } + out := new(CronInitParameters) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CronObservation) DeepCopyInto(out *CronObservation) { + *out = *in + if in.Schedule != nil { + in, out := &in.Schedule, &out.Schedule + *out = new(string) + **out = **in + } + if in.Timezone != nil { + in, out := &in.Timezone, &out.Timezone + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CronObservation. +func (in *CronObservation) DeepCopy() *CronObservation { + if in == nil { + return nil + } + out := new(CronObservation) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CronParameters) DeepCopyInto(out *CronParameters) { + *out = *in + if in.Schedule != nil { + in, out := &in.Schedule, &out.Schedule + *out = new(string) + **out = **in + } + if in.Timezone != nil { + in, out := &in.Timezone, &out.Timezone + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CronParameters. +func (in *CronParameters) DeepCopy() *CronParameters { + if in == nil { + return nil + } + out := new(CronParameters) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Definition) DeepCopyInto(out *Definition) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Definition. +func (in *Definition) DeepCopy() *Definition { + if in == nil { + return nil + } + out := new(Definition) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Definition) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DefinitionInitParameters) DeepCopyInto(out *DefinitionInitParameters) { + *out = *in + if in.CPULimit != nil { + in, out := &in.CPULimit, &out.CPULimit + *out = new(float64) + **out = **in + } + if in.Command != nil { + in, out := &in.Command, &out.Command + *out = new(string) + **out = **in + } + if in.Cron != nil { + in, out := &in.Cron, &out.Cron + *out = make([]CronInitParameters, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.Description != nil { + in, out := &in.Description, &out.Description + *out = new(string) + **out = **in + } + if in.Env != nil { + in, out := &in.Env, &out.Env + *out = make(map[string]*string, len(*in)) + for key, val := range *in { + var outVal *string + if val == nil { + (*out)[key] = nil + } else { + inVal := (*in)[key] + in, out := &inVal, &outVal + *out = new(string) + **out = **in + } + (*out)[key] = outVal + } + } + if in.ImageURI != nil { + in, out := &in.ImageURI, &out.ImageURI + *out = new(string) + **out = **in + } + if in.MemoryLimit != nil { + in, out := &in.MemoryLimit, &out.MemoryLimit + *out = new(float64) + **out = **in + } + if in.Name != nil { + in, out := &in.Name, &out.Name + *out = new(string) + **out = **in + } + if in.ProjectID != nil { + in, out := &in.ProjectID, &out.ProjectID + *out = new(string) + **out = **in + } + if in.Region != nil { + in, out := &in.Region, &out.Region + *out = new(string) + **out = **in + } + if in.Timeout != nil { + in, out := &in.Timeout, &out.Timeout + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DefinitionInitParameters. +func (in *DefinitionInitParameters) DeepCopy() *DefinitionInitParameters { + if in == nil { + return nil + } + out := new(DefinitionInitParameters) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DefinitionList) DeepCopyInto(out *DefinitionList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Definition, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DefinitionList. +func (in *DefinitionList) DeepCopy() *DefinitionList { + if in == nil { + return nil + } + out := new(DefinitionList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *DefinitionList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DefinitionObservation) DeepCopyInto(out *DefinitionObservation) { + *out = *in + if in.CPULimit != nil { + in, out := &in.CPULimit, &out.CPULimit + *out = new(float64) + **out = **in + } + if in.Command != nil { + in, out := &in.Command, &out.Command + *out = new(string) + **out = **in + } + if in.Cron != nil { + in, out := &in.Cron, &out.Cron + *out = make([]CronObservation, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.Description != nil { + in, out := &in.Description, &out.Description + *out = new(string) + **out = **in + } + if in.Env != nil { + in, out := &in.Env, &out.Env + *out = make(map[string]*string, len(*in)) + for key, val := range *in { + var outVal *string + if val == nil { + (*out)[key] = nil + } else { + inVal := (*in)[key] + in, out := &inVal, &outVal + *out = new(string) + **out = **in + } + (*out)[key] = outVal + } + } + if in.ID != nil { + in, out := &in.ID, &out.ID + *out = new(string) + **out = **in + } + if in.ImageURI != nil { + in, out := &in.ImageURI, &out.ImageURI + *out = new(string) + **out = **in + } + if in.MemoryLimit != nil { + in, out := &in.MemoryLimit, &out.MemoryLimit + *out = new(float64) + **out = **in + } + if in.Name != nil { + in, out := &in.Name, &out.Name + *out = new(string) + **out = **in + } + if in.ProjectID != nil { + in, out := &in.ProjectID, &out.ProjectID + *out = new(string) + **out = **in + } + if in.Region != nil { + in, out := &in.Region, &out.Region + *out = new(string) + **out = **in + } + if in.Timeout != nil { + in, out := &in.Timeout, &out.Timeout + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DefinitionObservation. +func (in *DefinitionObservation) DeepCopy() *DefinitionObservation { + if in == nil { + return nil + } + out := new(DefinitionObservation) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DefinitionParameters) DeepCopyInto(out *DefinitionParameters) { + *out = *in + if in.CPULimit != nil { + in, out := &in.CPULimit, &out.CPULimit + *out = new(float64) + **out = **in + } + if in.Command != nil { + in, out := &in.Command, &out.Command + *out = new(string) + **out = **in + } + if in.Cron != nil { + in, out := &in.Cron, &out.Cron + *out = make([]CronParameters, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.Description != nil { + in, out := &in.Description, &out.Description + *out = new(string) + **out = **in + } + if in.Env != nil { + in, out := &in.Env, &out.Env + *out = make(map[string]*string, len(*in)) + for key, val := range *in { + var outVal *string + if val == nil { + (*out)[key] = nil + } else { + inVal := (*in)[key] + in, out := &inVal, &outVal + *out = new(string) + **out = **in + } + (*out)[key] = outVal + } + } + if in.ImageURI != nil { + in, out := &in.ImageURI, &out.ImageURI + *out = new(string) + **out = **in + } + if in.MemoryLimit != nil { + in, out := &in.MemoryLimit, &out.MemoryLimit + *out = new(float64) + **out = **in + } + if in.Name != nil { + in, out := &in.Name, &out.Name + *out = new(string) + **out = **in + } + if in.ProjectID != nil { + in, out := &in.ProjectID, &out.ProjectID + *out = new(string) + **out = **in + } + if in.Region != nil { + in, out := &in.Region, &out.Region + *out = new(string) + **out = **in + } + if in.Timeout != nil { + in, out := &in.Timeout, &out.Timeout + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DefinitionParameters. +func (in *DefinitionParameters) DeepCopy() *DefinitionParameters { + if in == nil { + return nil + } + out := new(DefinitionParameters) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DefinitionSpec) DeepCopyInto(out *DefinitionSpec) { + *out = *in + in.ResourceSpec.DeepCopyInto(&out.ResourceSpec) + in.ForProvider.DeepCopyInto(&out.ForProvider) + in.InitProvider.DeepCopyInto(&out.InitProvider) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DefinitionSpec. +func (in *DefinitionSpec) DeepCopy() *DefinitionSpec { + if in == nil { + return nil + } + out := new(DefinitionSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DefinitionStatus) DeepCopyInto(out *DefinitionStatus) { + *out = *in + in.ResourceStatus.DeepCopyInto(&out.ResourceStatus) + in.AtProvider.DeepCopyInto(&out.AtProvider) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DefinitionStatus. +func (in *DefinitionStatus) DeepCopy() *DefinitionStatus { + if in == nil { + return nil + } + out := new(DefinitionStatus) + in.DeepCopyInto(out) + return out +} diff --git a/apis/jobs/v1alpha1/zz_generated.managed.go b/apis/jobs/v1alpha1/zz_generated.managed.go new file mode 100644 index 0000000..e0d8e80 --- /dev/null +++ b/apis/jobs/v1alpha1/zz_generated.managed.go @@ -0,0 +1,68 @@ +/* +Copyright 2022 Upbound Inc. +*/ +// Code generated by angryjet. DO NOT EDIT. + +package v1alpha1 + +import xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" + +// GetCondition of this Definition. +func (mg *Definition) GetCondition(ct xpv1.ConditionType) xpv1.Condition { + return mg.Status.GetCondition(ct) +} + +// GetDeletionPolicy of this Definition. +func (mg *Definition) GetDeletionPolicy() xpv1.DeletionPolicy { + return mg.Spec.DeletionPolicy +} + +// GetManagementPolicies of this Definition. +func (mg *Definition) GetManagementPolicies() xpv1.ManagementPolicies { + return mg.Spec.ManagementPolicies +} + +// GetProviderConfigReference of this Definition. +func (mg *Definition) GetProviderConfigReference() *xpv1.Reference { + return mg.Spec.ProviderConfigReference +} + +// GetPublishConnectionDetailsTo of this Definition. +func (mg *Definition) GetPublishConnectionDetailsTo() *xpv1.PublishConnectionDetailsTo { + return mg.Spec.PublishConnectionDetailsTo +} + +// GetWriteConnectionSecretToReference of this Definition. +func (mg *Definition) GetWriteConnectionSecretToReference() *xpv1.SecretReference { + return mg.Spec.WriteConnectionSecretToReference +} + +// SetConditions of this Definition. +func (mg *Definition) SetConditions(c ...xpv1.Condition) { + mg.Status.SetConditions(c...) +} + +// SetDeletionPolicy of this Definition. +func (mg *Definition) SetDeletionPolicy(r xpv1.DeletionPolicy) { + mg.Spec.DeletionPolicy = r +} + +// SetManagementPolicies of this Definition. +func (mg *Definition) SetManagementPolicies(r xpv1.ManagementPolicies) { + mg.Spec.ManagementPolicies = r +} + +// SetProviderConfigReference of this Definition. +func (mg *Definition) SetProviderConfigReference(r *xpv1.Reference) { + mg.Spec.ProviderConfigReference = r +} + +// SetPublishConnectionDetailsTo of this Definition. +func (mg *Definition) SetPublishConnectionDetailsTo(r *xpv1.PublishConnectionDetailsTo) { + mg.Spec.PublishConnectionDetailsTo = r +} + +// SetWriteConnectionSecretToReference of this Definition. +func (mg *Definition) SetWriteConnectionSecretToReference(r *xpv1.SecretReference) { + mg.Spec.WriteConnectionSecretToReference = r +} diff --git a/apis/jobs/v1alpha1/zz_generated.managedlist.go b/apis/jobs/v1alpha1/zz_generated.managedlist.go new file mode 100644 index 0000000..92f1c52 --- /dev/null +++ b/apis/jobs/v1alpha1/zz_generated.managedlist.go @@ -0,0 +1,17 @@ +/* +Copyright 2022 Upbound Inc. +*/ +// Code generated by angryjet. DO NOT EDIT. + +package v1alpha1 + +import resource "github.com/crossplane/crossplane-runtime/pkg/resource" + +// GetItems of this DefinitionList. +func (l *DefinitionList) GetItems() []resource.Managed { + items := make([]resource.Managed, len(l.Items)) + for i := range l.Items { + items[i] = &l.Items[i] + } + return items +} diff --git a/apis/jobs/v1alpha1/zz_groupversion_info.go b/apis/jobs/v1alpha1/zz_groupversion_info.go new file mode 100755 index 0000000..9d09474 --- /dev/null +++ b/apis/jobs/v1alpha1/zz_groupversion_info.go @@ -0,0 +1,32 @@ +/* +Copyright 2022 Upbound Inc. +*/ + +// Code generated by upjet. DO NOT EDIT. + +// +kubebuilder:object:generate=true +// +groupName=jobs.scaleway.upbound.io +// +versionName=v1alpha1 +package v1alpha1 + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + "sigs.k8s.io/controller-runtime/pkg/scheme" +) + +// Package type metadata. +const ( + CRDGroup = "jobs.scaleway.upbound.io" + CRDVersion = "v1alpha1" +) + +var ( + // CRDGroupVersion is the API Group Version used to register the objects + CRDGroupVersion = schema.GroupVersion{Group: CRDGroup, Version: CRDVersion} + + // SchemeBuilder is used to add go types to the GroupVersionKind scheme + SchemeBuilder = &scheme.Builder{GroupVersion: CRDGroupVersion} + + // AddToScheme adds the types in this group-version to the given scheme. + AddToScheme = SchemeBuilder.AddToScheme +) From 59ae88a4bf41bca19b78ab886f4769b7b7807646 Mon Sep 17 00:00:00 2001 From: Yacine FODIL Date: Wed, 7 Aug 2024 10:13:56 +0200 Subject: [PATCH 18/24] fix --- apis/zz_register.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/apis/zz_register.go b/apis/zz_register.go index efa0c38..208c5c2 100755 --- a/apis/zz_register.go +++ b/apis/zz_register.go @@ -30,7 +30,6 @@ import ( v1alpha1rdb "github.com/scaleway/provider-scaleway/apis/rdb/v1alpha1" v1alpha1redis "github.com/scaleway/provider-scaleway/apis/redis/v1alpha1" v1alpha1registry "github.com/scaleway/provider-scaleway/apis/registry/v1alpha1" - v1alpha1sdb "github.com/scaleway/provider-scaleway/apis/sdb/v1alpha1" v1alpha1tem "github.com/scaleway/provider-scaleway/apis/tem/v1alpha1" v1alpha1apis "github.com/scaleway/provider-scaleway/apis/v1alpha1" v1beta1 "github.com/scaleway/provider-scaleway/apis/v1beta1" @@ -60,7 +59,6 @@ func init() { v1alpha1rdb.SchemeBuilder.AddToScheme, v1alpha1redis.SchemeBuilder.AddToScheme, v1alpha1registry.SchemeBuilder.AddToScheme, - v1alpha1sdb.SchemeBuilder.AddToScheme, v1alpha1tem.SchemeBuilder.AddToScheme, v1alpha1apis.SchemeBuilder.AddToScheme, v1beta1.SchemeBuilder.AddToScheme, From 4929cbd8856a225b1f8c5e0c1cb369a05ccd6dbf Mon Sep 17 00:00:00 2001 From: Yacine FODIL Date: Wed, 7 Aug 2024 10:18:30 +0200 Subject: [PATCH 19/24] fix --- internal/controller/zz_setup.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/controller/zz_setup.go b/internal/controller/zz_setup.go index 296fcdd..c42dfd5 100755 --- a/internal/controller/zz_setup.go +++ b/internal/controller/zz_setup.go @@ -79,7 +79,6 @@ import ( userrdb "github.com/scaleway/provider-scaleway/internal/controller/rdb/user" clusterredis "github.com/scaleway/provider-scaleway/internal/controller/redis/cluster" registrynamespace "github.com/scaleway/provider-scaleway/internal/controller/registry/registrynamespace" - sqldatabase "github.com/scaleway/provider-scaleway/internal/controller/sdb/sqldatabase" domaintem "github.com/scaleway/provider-scaleway/internal/controller/tem/domain" gatewaynetwork "github.com/scaleway/provider-scaleway/internal/controller/vpc/gatewaynetwork" privatenetwork "github.com/scaleway/provider-scaleway/internal/controller/vpc/privatenetwork" @@ -164,7 +163,6 @@ func Setup(mgr ctrl.Manager, o controller.Options) error { userrdb.Setup, clusterredis.Setup, registrynamespace.Setup, - sqldatabase.Setup, domaintem.Setup, gatewaynetwork.Setup, privatenetwork.Setup, From b0bb34f519c26bdb1bccec0927a01a423645c570 Mon Sep 17 00:00:00 2001 From: Yacine FODIL Date: Wed, 7 Aug 2024 10:22:33 +0200 Subject: [PATCH 20/24] fix --- .../sdb/sqldatabase/zz_controller.go | 88 ------------------- 1 file changed, 88 deletions(-) delete mode 100755 internal/controller/sdb/sqldatabase/zz_controller.go diff --git a/internal/controller/sdb/sqldatabase/zz_controller.go b/internal/controller/sdb/sqldatabase/zz_controller.go deleted file mode 100755 index a4635e1..0000000 --- a/internal/controller/sdb/sqldatabase/zz_controller.go +++ /dev/null @@ -1,88 +0,0 @@ -/* -Copyright 2022 Upbound Inc. -*/ - -// Code generated by upjet. DO NOT EDIT. - -package sqldatabase - -import ( - "time" - - "github.com/crossplane/crossplane-runtime/pkg/connection" - "github.com/crossplane/crossplane-runtime/pkg/event" - "github.com/crossplane/crossplane-runtime/pkg/ratelimiter" - "github.com/crossplane/crossplane-runtime/pkg/reconciler/managed" - xpresource "github.com/crossplane/crossplane-runtime/pkg/resource" - "github.com/crossplane/crossplane-runtime/pkg/statemetrics" - tjcontroller "github.com/crossplane/upjet/pkg/controller" - "github.com/crossplane/upjet/pkg/controller/handler" - "github.com/crossplane/upjet/pkg/terraform" - "github.com/pkg/errors" - ctrl "sigs.k8s.io/controller-runtime" - - v1alpha1 "github.com/scaleway/provider-scaleway/apis/sdb/v1alpha1" - features "github.com/scaleway/provider-scaleway/internal/features" -) - -// Setup adds a controller that reconciles SQLDatabase managed resources. -func Setup(mgr ctrl.Manager, o tjcontroller.Options) error { - name := managed.ControllerName(v1alpha1.SQLDatabase_GroupVersionKind.String()) - var initializers managed.InitializerChain - initializers = append(initializers, managed.NewNameAsExternalName(mgr.GetClient())) - cps := []managed.ConnectionPublisher{managed.NewAPISecretPublisher(mgr.GetClient(), mgr.GetScheme())} - if o.SecretStoreConfigGVK != nil { - cps = append(cps, connection.NewDetailsManager(mgr.GetClient(), *o.SecretStoreConfigGVK, connection.WithTLSConfig(o.ESSOptions.TLSConfig))) - } - eventHandler := handler.NewEventHandler(handler.WithLogger(o.Logger.WithValues("gvk", v1alpha1.SQLDatabase_GroupVersionKind))) - ac := tjcontroller.NewAPICallbacks(mgr, xpresource.ManagedKind(v1alpha1.SQLDatabase_GroupVersionKind), tjcontroller.WithEventHandler(eventHandler)) - opts := []managed.ReconcilerOption{ - managed.WithExternalConnecter(tjcontroller.NewConnector(mgr.GetClient(), o.WorkspaceStore, o.SetupFn, o.Provider.Resources["scaleway_sdb_sql_database"], tjcontroller.WithLogger(o.Logger), tjcontroller.WithConnectorEventHandler(eventHandler), - tjcontroller.WithCallbackProvider(ac), - )), - managed.WithLogger(o.Logger.WithValues("controller", name)), - managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))), - managed.WithFinalizer(terraform.NewWorkspaceFinalizer(o.WorkspaceStore, xpresource.NewAPIFinalizer(mgr.GetClient(), managed.FinalizerName))), - managed.WithTimeout(3 * time.Minute), - managed.WithInitializers(initializers), - managed.WithConnectionPublishers(cps...), - managed.WithPollInterval(o.PollInterval), - } - if o.PollJitter != 0 { - opts = append(opts, managed.WithPollJitterHook(o.PollJitter)) - } - if o.Features.Enabled(features.EnableBetaManagementPolicies) { - opts = append(opts, managed.WithManagementPolicies()) - } - if o.MetricOptions != nil { - opts = append(opts, managed.WithMetricRecorder(o.MetricOptions.MRMetrics)) - } - - // register webhooks for the kind v1alpha1.SQLDatabase - // if they're enabled. - if o.StartWebhooks { - if err := ctrl.NewWebhookManagedBy(mgr). - For(&v1alpha1.SQLDatabase{}). - Complete(); err != nil { - return errors.Wrap(err, "cannot register webhook for the kind v1alpha1.SQLDatabase") - } - } - - if o.MetricOptions != nil && o.MetricOptions.MRStateMetrics != nil { - stateMetricsRecorder := statemetrics.NewMRStateRecorder( - mgr.GetClient(), o.Logger, o.MetricOptions.MRStateMetrics, &v1alpha1.SQLDatabaseList{}, o.MetricOptions.PollStateMetricInterval, - ) - if err := mgr.Add(stateMetricsRecorder); err != nil { - return errors.Wrap(err, "cannot register MR state metrics recorder for kind v1alpha1.SQLDatabaseList") - } - } - - r := managed.NewReconciler(mgr, xpresource.ManagedKind(v1alpha1.SQLDatabase_GroupVersionKind), opts...) - - return ctrl.NewControllerManagedBy(mgr). - Named(name). - WithOptions(o.ForControllerRuntime()). - WithEventFilter(xpresource.DesiredStateChanged()). - Watches(&v1alpha1.SQLDatabase{}, eventHandler). - Complete(ratelimiter.NewReconciler(name, r, o.GlobalRateLimiter)) -} From 9c4225ec0274b6c70fb1b0073559fbac57df9745 Mon Sep 17 00:00:00 2001 From: Yacine FODIL Date: Wed, 7 Aug 2024 10:29:27 +0200 Subject: [PATCH 21/24] fix --- .../workflows/update-terraform-provider.yaml | 2 +- .../sdb/v1alpha1/sqldatabase.yaml | 12 - .../sdb.scaleway.upbound.io_sqldatabases.yaml | 392 ------------------ 3 files changed, 1 insertion(+), 405 deletions(-) delete mode 100644 examples-generated/sdb/v1alpha1/sqldatabase.yaml delete mode 100644 package/crds/sdb.scaleway.upbound.io_sqldatabases.yaml diff --git a/.github/workflows/update-terraform-provider.yaml b/.github/workflows/update-terraform-provider.yaml index 8223965..f35b977 100755 --- a/.github/workflows/update-terraform-provider.yaml +++ b/.github/workflows/update-terraform-provider.yaml @@ -13,7 +13,7 @@ jobs: contents: write steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: ref: ${{ github.head_ref }} diff --git a/examples-generated/sdb/v1alpha1/sqldatabase.yaml b/examples-generated/sdb/v1alpha1/sqldatabase.yaml deleted file mode 100644 index b703adc..0000000 --- a/examples-generated/sdb/v1alpha1/sqldatabase.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: sdb.scaleway.upbound.io/v1alpha1 -kind: SQLDatabase -metadata: - annotations: - meta.upbound.io/example-id: sdb/v1alpha1/sqldatabase - labels: - testing.upbound.io/example-name: database - name: database -spec: - forProvider: - maxCpu: 8 - minCpu: 0 diff --git a/package/crds/sdb.scaleway.upbound.io_sqldatabases.yaml b/package/crds/sdb.scaleway.upbound.io_sqldatabases.yaml deleted file mode 100644 index dd65565..0000000 --- a/package/crds/sdb.scaleway.upbound.io_sqldatabases.yaml +++ /dev/null @@ -1,392 +0,0 @@ ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.14.0 - name: sqldatabases.sdb.scaleway.upbound.io -spec: - group: sdb.scaleway.upbound.io - names: - categories: - - crossplane - - managed - - scaleway - kind: SQLDatabase - listKind: SQLDatabaseList - plural: sqldatabases - singular: sqldatabase - scope: Cluster - versions: - - additionalPrinterColumns: - - jsonPath: .status.conditions[?(@.type=='Synced')].status - name: SYNCED - type: string - - jsonPath: .status.conditions[?(@.type=='Ready')].status - name: READY - type: string - - jsonPath: .metadata.annotations.crossplane\.io/external-name - name: EXTERNAL-NAME - type: string - - jsonPath: .metadata.creationTimestamp - name: AGE - type: date - name: v1alpha1 - schema: - openAPIV3Schema: - description: SQLDatabase is the Schema for the SQLDatabases API. - properties: - apiVersion: - description: |- - APIVersion defines the versioned schema of this representation of an object. - Servers should convert recognized schemas to the latest internal value, and - may reject unrecognized values. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources - type: string - kind: - description: |- - Kind is a string value representing the REST resource this object represents. - Servers may infer this from the endpoint the client submits requests to. - Cannot be updated. - In CamelCase. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds - type: string - metadata: - type: object - spec: - description: SQLDatabaseSpec defines the desired state of SQLDatabase - properties: - deletionPolicy: - default: Delete - description: |- - DeletionPolicy specifies what will happen to the underlying external - when this managed resource is deleted - either "Delete" or "Orphan" the - external resource. - This field is planned to be deprecated in favor of the ManagementPolicies - field in a future release. Currently, both could be set independently and - non-default values would be honored if the feature flag is enabled. - See the design doc for more information: https://github.com/crossplane/crossplane/blob/499895a25d1a1a0ba1604944ef98ac7a1a71f197/design/design-doc-observe-only-resources.md?plain=1#L223 - enum: - - Orphan - - Delete - type: string - forProvider: - properties: - maxCpu: - description: |- - The maximum number of CPU units for your database. Defaults to 15. - The maximum number of CPU units for your Serverless SQL Database - type: number - minCpu: - description: |- - The minimum number of CPU units for your database. Defaults to 0. - The minimum number of CPU units for your Serverless SQL Database - type: number - projectId: - description: |- - The ID of the database, which is of the form {region}/{id} e.g. fr-par/11111111-1111-1111-1111-111111111111 - The project_id you want to attach the resource to - type: string - region: - description: |- - (Defaults to provider region) The region in which the resource exists. - The region you want to attach the resource to - type: string - type: object - initProvider: - description: |- - THIS IS A BETA FIELD. It will be honored - unless the Management Policies feature flag is disabled. - InitProvider holds the same fields as ForProvider, with the exception - of Identifier and other resource reference fields. The fields that are - in InitProvider are merged into ForProvider when the resource is created. - The same fields are also added to the terraform ignore_changes hook, to - avoid updating them after creation. This is useful for fields that are - required on creation, but we do not desire to update them after creation, - for example because of an external controller is managing them, like an - autoscaler. - properties: - maxCpu: - description: |- - The maximum number of CPU units for your database. Defaults to 15. - The maximum number of CPU units for your Serverless SQL Database - type: number - minCpu: - description: |- - The minimum number of CPU units for your database. Defaults to 0. - The minimum number of CPU units for your Serverless SQL Database - type: number - projectId: - description: |- - The ID of the database, which is of the form {region}/{id} e.g. fr-par/11111111-1111-1111-1111-111111111111 - The project_id you want to attach the resource to - type: string - region: - description: |- - (Defaults to provider region) The region in which the resource exists. - The region you want to attach the resource to - type: string - type: object - managementPolicies: - default: - - '*' - description: |- - THIS IS A BETA FIELD. It is on by default but can be opted out - through a Crossplane feature flag. - ManagementPolicies specify the array of actions Crossplane is allowed to - take on the managed and external resources. - This field is planned to replace the DeletionPolicy field in a future - release. Currently, both could be set independently and non-default - values would be honored if the feature flag is enabled. If both are - custom, the DeletionPolicy field will be ignored. - See the design doc for more information: https://github.com/crossplane/crossplane/blob/499895a25d1a1a0ba1604944ef98ac7a1a71f197/design/design-doc-observe-only-resources.md?plain=1#L223 - and this one: https://github.com/crossplane/crossplane/blob/444267e84783136daa93568b364a5f01228cacbe/design/one-pager-ignore-changes.md - items: - description: |- - A ManagementAction represents an action that the Crossplane controllers - can take on an external resource. - enum: - - Observe - - Create - - Update - - Delete - - LateInitialize - - '*' - type: string - type: array - providerConfigRef: - default: - name: default - description: |- - ProviderConfigReference specifies how the provider that will be used to - create, observe, update, and delete this managed resource should be - configured. - properties: - name: - description: Name of the referenced object. - type: string - policy: - description: Policies for referencing. - properties: - resolution: - default: Required - description: |- - Resolution specifies whether resolution of this reference is required. - The default is 'Required', which means the reconcile will fail if the - reference cannot be resolved. 'Optional' means this reference will be - a no-op if it cannot be resolved. - enum: - - Required - - Optional - type: string - resolve: - description: |- - Resolve specifies when this reference should be resolved. The default - is 'IfNotPresent', which will attempt to resolve the reference only when - the corresponding field is not present. Use 'Always' to resolve the - reference on every reconcile. - enum: - - Always - - IfNotPresent - type: string - type: object - required: - - name - type: object - publishConnectionDetailsTo: - description: |- - PublishConnectionDetailsTo specifies the connection secret config which - contains a name, metadata and a reference to secret store config to - which any connection details for this managed resource should be written. - Connection details frequently include the endpoint, username, - and password required to connect to the managed resource. - properties: - configRef: - default: - name: default - description: |- - SecretStoreConfigRef specifies which secret store config should be used - for this ConnectionSecret. - properties: - name: - description: Name of the referenced object. - type: string - policy: - description: Policies for referencing. - properties: - resolution: - default: Required - description: |- - Resolution specifies whether resolution of this reference is required. - The default is 'Required', which means the reconcile will fail if the - reference cannot be resolved. 'Optional' means this reference will be - a no-op if it cannot be resolved. - enum: - - Required - - Optional - type: string - resolve: - description: |- - Resolve specifies when this reference should be resolved. The default - is 'IfNotPresent', which will attempt to resolve the reference only when - the corresponding field is not present. Use 'Always' to resolve the - reference on every reconcile. - enum: - - Always - - IfNotPresent - type: string - type: object - required: - - name - type: object - metadata: - description: Metadata is the metadata for connection secret. - properties: - annotations: - additionalProperties: - type: string - description: |- - Annotations are the annotations to be added to connection secret. - - For Kubernetes secrets, this will be used as "metadata.annotations". - - It is up to Secret Store implementation for others store types. - type: object - labels: - additionalProperties: - type: string - description: |- - Labels are the labels/tags to be added to connection secret. - - For Kubernetes secrets, this will be used as "metadata.labels". - - It is up to Secret Store implementation for others store types. - type: object - type: - description: |- - Type is the SecretType for the connection secret. - - Only valid for Kubernetes Secret Stores. - type: string - type: object - name: - description: Name is the name of the connection secret. - type: string - required: - - name - type: object - writeConnectionSecretToRef: - description: |- - WriteConnectionSecretToReference specifies the namespace and name of a - Secret to which any connection details for this managed resource should - be written. Connection details frequently include the endpoint, username, - and password required to connect to the managed resource. - This field is planned to be replaced in a future release in favor of - PublishConnectionDetailsTo. Currently, both could be set independently - and connection details would be published to both without affecting - each other. - properties: - name: - description: Name of the secret. - type: string - namespace: - description: Namespace of the secret. - type: string - required: - - name - - namespace - type: object - required: - - forProvider - type: object - status: - description: SQLDatabaseStatus defines the observed state of SQLDatabase. - properties: - atProvider: - properties: - endpoint: - description: |- - Endpoint of the database - endpoint of the database - type: string - id: - description: The ID of the database, which is of the form {region}/{id} - e.g. fr-par/11111111-1111-1111-1111-111111111111 - type: string - maxCpu: - description: |- - The maximum number of CPU units for your database. Defaults to 15. - The maximum number of CPU units for your Serverless SQL Database - type: number - minCpu: - description: |- - The minimum number of CPU units for your database. Defaults to 0. - The minimum number of CPU units for your Serverless SQL Database - type: number - projectId: - description: |- - The ID of the database, which is of the form {region}/{id} e.g. fr-par/11111111-1111-1111-1111-111111111111 - The project_id you want to attach the resource to - type: string - region: - description: |- - (Defaults to provider region) The region in which the resource exists. - The region you want to attach the resource to - type: string - type: object - conditions: - description: Conditions of the resource. - items: - description: A Condition that may apply to a resource. - properties: - lastTransitionTime: - description: |- - LastTransitionTime is the last time this condition transitioned from one - status to another. - format: date-time - type: string - message: - description: |- - A Message containing details about this condition's last transition from - one status to another, if any. - type: string - observedGeneration: - description: |- - ObservedGeneration represents the .metadata.generation that the condition was set based upon. - For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date - with respect to the current state of the instance. - format: int64 - type: integer - reason: - description: A Reason for this condition's last transition from - one status to another. - type: string - status: - description: Status of this condition; is it currently True, - False, or Unknown? - type: string - type: - description: |- - Type of this condition. At most one of each condition type may apply to - a resource at any point in time. - type: string - required: - - lastTransitionTime - - reason - - status - - type - type: object - type: array - x-kubernetes-list-map-keys: - - type - x-kubernetes-list-type: map - observedGeneration: - description: |- - ObservedGeneration is the latest metadata.generation - which resulted in either a ready state, or stalled due to error - it can not recover from without human intervention. - format: int64 - type: integer - type: object - required: - - spec - type: object - served: true - storage: true - subresources: - status: {} From f72314eec54255111a9f4e7b626ea5028c1a6d31 Mon Sep 17 00:00:00 2001 From: Yacine FODIL Date: Wed, 7 Aug 2024 10:53:12 +0200 Subject: [PATCH 22/24] extract check tf version to a script --- .github/workflows/update-terraform-provider.yaml | 6 +----- config/tools/comparator/main.go | 5 +++-- config/tools/generator/main.go | 2 +- scripts/check-version.sh | 7 +++++++ 4 files changed, 12 insertions(+), 8 deletions(-) create mode 100755 scripts/check-version.sh diff --git a/.github/workflows/update-terraform-provider.yaml b/.github/workflows/update-terraform-provider.yaml index f35b977..06bb80c 100755 --- a/.github/workflows/update-terraform-provider.yaml +++ b/.github/workflows/update-terraform-provider.yaml @@ -19,11 +19,7 @@ jobs: - name: Check for New Terraform Provider Release id: check_release - run: | - latest_release=$(gh release list -R scaleway/terraform-provider-scaleway --limit 1) - latest_version=$(echo $latest_release | awk '{print $1}' | sed 's/^v//') - echo "Latest version: $latest_version" - echo "new_version=$latest_version" >> $GITHUB_ENV + run: ./scripts/check_version.sh - name: Read Current Terraform Provider Version from Makefile id: current_version diff --git a/config/tools/comparator/main.go b/config/tools/comparator/main.go index 4048829..d9e57b6 100644 --- a/config/tools/comparator/main.go +++ b/config/tools/comparator/main.go @@ -4,11 +4,12 @@ import ( _ "embed" "encoding/json" "fmt" - "golang.org/x/text/cases" - "golang.org/x/text/language" "os" "strings" + "golang.org/x/text/cases" + "golang.org/x/text/language" + "github.com/crossplane/upjet/pkg/registry" "github.com/pkg/errors" "github.com/scaleway/provider-scaleway/config/tools" diff --git a/config/tools/generator/main.go b/config/tools/generator/main.go index 7c56e48..4112e2a 100644 --- a/config/tools/generator/main.go +++ b/config/tools/generator/main.go @@ -75,7 +75,7 @@ func createNewConfigFile(filePath string, resourceConfig tools.ResourceConfig) e return fmt.Errorf("invalid file path: %s", cleanFilePath) } - err = os.WriteFile(filePath, formattedCode, 0644) + err = os.WriteFile(filePath, formattedCode, 0600) if err != nil { return err } diff --git a/scripts/check-version.sh b/scripts/check-version.sh new file mode 100755 index 0000000..7776254 --- /dev/null +++ b/scripts/check-version.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +# Check for the latest Terraform Provider release +latest_release=$(gh release list -R scaleway/terraform-provider-scaleway --limit 1) +latest_version=$(echo $latest_release | awk '{print $1}' | sed 's/^v//') +echo "Latest version: $latest_version" +echo "new_version=$latest_version" >> $GITHUB_ENV From 7b318d2f73cd276576a1904f3f159258a872583e Mon Sep 17 00:00:00 2001 From: Yacine FODIL Date: Wed, 7 Aug 2024 11:10:23 +0200 Subject: [PATCH 23/24] extract to a func and add tests --- config/tools/comparator/main.go | 6 ++- config/tools/comparator/main_test.go | 59 ++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 config/tools/comparator/main_test.go diff --git a/config/tools/comparator/main.go b/config/tools/comparator/main.go index d9e57b6..86beec3 100644 --- a/config/tools/comparator/main.go +++ b/config/tools/comparator/main.go @@ -53,7 +53,7 @@ func main() { } config := tools.ResourceConfig{ - PackageName: strings.ToLower(strings.ReplaceAll(resource.SubCategory, " ", "")), // Convert "Apple Silicon" to "applesilicon" + PackageName: generatePackageName(resource.SubCategory), ShortGroup: strings.ToLower(resource.SubCategory), ResourceName: resource.Title, TerraformResourceName: resource.Name, @@ -102,3 +102,7 @@ func parseKindFromResourceName(resourceName string) string { return titleCaser.String(lastWord) } + +func generatePackageName(subCategory string) string { + return strings.ToLower(strings.ReplaceAll(subCategory, " ", "")) +} diff --git a/config/tools/comparator/main_test.go b/config/tools/comparator/main_test.go new file mode 100644 index 0000000..8496cbd --- /dev/null +++ b/config/tools/comparator/main_test.go @@ -0,0 +1,59 @@ +package main + +import ( + "testing" +) + +// TestParseKindFromResourceName tests the parseKindFromResourceName function. +func TestParseKindFromResourceName(t *testing.T) { + tests := []struct { + resourceName string + expected string + }{ + {"scaleway_object_bucket", "Bucket"}, // Normal case + {"scaleway_flexible_ip", "Ip"}, // Multiple words + {"simple_resource", "Resource"}, // Single word + {"", ""}, // Empty string + {"singleword", "Singleword"}, // No underscores + {"trailing_underscore_", ""}, // Trailing underscore + {"_leading_underscore", "Underscore"}, // Leading underscore + {"middle__double__underscore", "Underscore"}, // Double underscores + {"_underscore", "Underscore"}, // Starts with underscore + } + + for _, tt := range tests { + t.Run(tt.resourceName, func(t *testing.T) { + actual := parseKindFromResourceName(tt.resourceName) + if actual != tt.expected { + t.Errorf("parseKindFromResourceName(%s) = %s; expected %s", tt.resourceName, actual, tt.expected) + } + }) + } +} + +// TestGeneratePackageName tests the generatePackageName function. +func TestGeneratePackageName(t *testing.T) { + tests := []struct { + subCategory string + expected string + }{ + {"Apple Silicon", "applesilicon"}, + {"Virtual Machines", "virtualmachines"}, + {" ", ""}, + {"", ""}, + {"Special Chars *&^%$#", "specialchars*&^%$#"}, + {"MixedCASE Category", "mixedcasecategory"}, + {" Leading and Trailing ", "leadingandtrailing"}, + {"Dotted.Category", "dotted.category"}, + {"Hyphenated-Category", "hyphenated-category"}, + } + + for _, tt := range tests { + t.Run(tt.subCategory, func(t *testing.T) { + actual := generatePackageName(tt.subCategory) + if actual != tt.expected { + t.Errorf("generatePackageName(%s) = %s; expected %s", tt.subCategory, actual, tt.expected) + } + }) + } +} From 494988c3f86c50a86f6a9cb06b33ed56d0863aa8 Mon Sep 17 00:00:00 2001 From: Yacine FODIL Date: Wed, 7 Aug 2024 11:24:53 +0200 Subject: [PATCH 24/24] fix --- .github/workflows/codeql.yml | 1 - config/external_name.go | 1 - config/tools/comparator/main_test.go | 18 +++++++++--------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index e4d4d68..4c22c09 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -17,7 +17,6 @@ on: pull_request: # The branches below must be a subset of the branches above branches: [ "main" ] - merge_group: schedule: - cron: '26 4 * * 2' diff --git a/config/external_name.go b/config/external_name.go index 8f2124a..4f3ae07 100644 --- a/config/external_name.go +++ b/config/external_name.go @@ -79,7 +79,6 @@ var ExternalNameConfigs = map[string]config.ExternalName{ "scaleway_rdb_read_replica": config.NameAsIdentifier, "scaleway_redis_cluster": config.NameAsIdentifier, "scaleway_registry_namespace": config.NameAsIdentifier, - "scaleway_sdb_sql_database": config.NameAsIdentifier, "scaleway_tem_domain": config.NameAsIdentifier, "scaleway_vpc": config.NameAsIdentifier, "scaleway_vpc_gateway_network": config.NameAsIdentifier, diff --git a/config/tools/comparator/main_test.go b/config/tools/comparator/main_test.go index 8496cbd..bd18290 100644 --- a/config/tools/comparator/main_test.go +++ b/config/tools/comparator/main_test.go @@ -10,15 +10,15 @@ func TestParseKindFromResourceName(t *testing.T) { resourceName string expected string }{ - {"scaleway_object_bucket", "Bucket"}, // Normal case - {"scaleway_flexible_ip", "Ip"}, // Multiple words - {"simple_resource", "Resource"}, // Single word - {"", ""}, // Empty string - {"singleword", "Singleword"}, // No underscores - {"trailing_underscore_", ""}, // Trailing underscore - {"_leading_underscore", "Underscore"}, // Leading underscore - {"middle__double__underscore", "Underscore"}, // Double underscores - {"_underscore", "Underscore"}, // Starts with underscore + {"scaleway_object_bucket", "Bucket"}, + {"scaleway_flexible_ip", "Ip"}, + {"simple_resource", "Resource"}, + {"", ""}, + {"singleword", "Singleword"}, + {"trailing_underscore_", ""}, + {"_leading_underscore", "Underscore"}, + {"middle__double__underscore", "Underscore"}, + {"_underscore", "Underscore"}, } for _, tt := range tests {