-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathdata_source_kubernetes_server_version.go
More file actions
99 lines (93 loc) · 2.67 KB
/
data_source_kubernetes_server_version.go
File metadata and controls
99 lines (93 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright IBM Corp. 2017, 2025
// SPDX-License-Identifier: MPL-2.0
package kubernetes
import (
"context"
gversion "github.com/hashicorp/go-version"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceKubernetesServerVersion() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceKubernetesServerVersionRead,
Description: "This data source reads the versioning information of the server and makes specific attributes available to Terraform. Read more at [version info reference](https://pkg.go.dev/k8s.io/apimachinery/pkg/version#Info)",
Schema: map[string]*schema.Schema{
"version": {
Type: schema.TypeString,
Description: "Composite Kubernetes server version",
Computed: true,
},
"build_date": {
Type: schema.TypeString,
Description: "Kubernetes server build date",
Computed: true,
},
"compiler": {
Type: schema.TypeString,
Description: "Compiler used to build Kubernetes",
Computed: true,
},
"git_commit": {
Type: schema.TypeString,
Description: "Git commit SHA",
Computed: true,
},
"git_tree_state": {
Type: schema.TypeString,
Description: "Git commit tree state",
Computed: true,
},
"git_version": {
Type: schema.TypeString,
Description: "Composite version and git commit sha",
Computed: true,
},
"major": {
Type: schema.TypeString,
Description: "Major Kubernetes version",
Computed: true,
},
"minor": {
Type: schema.TypeString,
Description: "Minor Kubernetes version",
Computed: true,
},
"platform": {
Type: schema.TypeString,
Description: "Platform",
Computed: true,
},
"go_version": {
Type: schema.TypeString,
Description: "Go compiler version",
Computed: true,
},
},
}
}
func dataSourceKubernetesServerVersionRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn, err := meta.(KubeClientsets).MainClientset()
if err != nil {
return diag.FromErr(err)
}
sv, err := conn.ServerVersion()
if err != nil {
return diag.FromErr(err)
}
gv, err := gversion.NewVersion(sv.String())
if err != nil {
return diag.FromErr(err)
}
d.SetId(gv.String())
d.Set("version", gv.String())
d.Set("build_date", sv.BuildDate)
d.Set("compiler", sv.Compiler)
d.Set("git_commit", sv.GitCommit)
d.Set("git_tree_state", sv.GitTreeState)
d.Set("git_version", sv.GitVersion)
d.Set("go_version", sv.GoVersion)
d.Set("major", sv.Major)
d.Set("minor", sv.Minor)
d.Set("platform", sv.Platform)
return nil
}