-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move resources to own package. Create data source: k8s_apps_v1_deploy…
…ment_image
- Loading branch information
1 parent
f1947ad
commit 4bf6bb5
Showing
176 changed files
with
300 additions
and
333 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package image | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/pkg/errors" | ||
corev1 "k8s.io/api/core/v1" | ||
kerrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
"github.com/previousnext/terraform-provider-k8s/internal/terraform/config" | ||
"github.com/previousnext/terraform-provider-k8s/internal/terraform/id" | ||
) | ||
|
||
// Read the Deployment. | ||
func Read(d *schema.ResourceData, m interface{}) error { | ||
conn := m.(*config.Client) | ||
|
||
var ( | ||
namespace = d.Get(FieldNamespace).(string) | ||
name = d.Get(FieldName).(string) | ||
container = d.Get(FieldContainer).(string) | ||
fallback = d.Get(FieldFallback).(string) | ||
) | ||
|
||
d.SetId(id.Join(metav1.ObjectMeta{ | ||
Namespace: namespace, | ||
Name: name, | ||
})) | ||
|
||
deployment, err := conn.Kubernetes().AppsV1().Deployments(namespace).Get(name, metav1.GetOptions{}) | ||
if kerrors.IsNotFound(err) { | ||
d.Set(FieldResult, fallback) | ||
return nil | ||
} else if err != nil { | ||
return errors.Wrap(err, "failed to get") | ||
} | ||
|
||
getImage := func(containers []corev1.Container, name, fallback string) string { | ||
for _, c := range deployment.Spec.Template.Spec.Containers { | ||
if c.Name == container { | ||
return c.Image | ||
} | ||
} | ||
|
||
return fallback | ||
} | ||
|
||
result := getImage(deployment.Spec.Template.Spec.Containers, container, fallback) | ||
|
||
d.Set(FieldResult, result) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package image | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
const ( | ||
// FieldName is a field identifier. | ||
FieldName = "name" | ||
// FieldNamespace is a field identifier. | ||
FieldNamespace = "namespace" | ||
// FieldContainer is a field identifier. | ||
FieldContainer = "container" | ||
// FieldFallback is a field identifier. | ||
FieldFallback = "fallback" | ||
// FieldResult is a field identifier. | ||
FieldResult = "result" | ||
) | ||
|
||
// Source returns this packages data source. | ||
func Source() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: Read, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
FieldName: { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
FieldNamespace: { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
FieldContainer: { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
FieldFallback: { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
FieldResult: { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package datasources | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/helper/schema" | ||
|
||
deploymentimage "github.com/previousnext/terraform-provider-k8s/internal/datasources/apps/v1/deployment/image" | ||
) | ||
|
||
const ( | ||
// FieldDeploymentImage identifier for the Kubernetes Deployment. | ||
FieldDeploymentImage = "k8s_apps_v1_deployment_image" | ||
) | ||
|
||
// DataSourcesMap returns a list of data sources. | ||
func DataSourcesMap() map[string]*schema.Resource { | ||
return map[string]*schema.Resource{ | ||
FieldDeploymentImage: deploymentimage.Source(), | ||
} | ||
} |
30 changes: 0 additions & 30 deletions
30
internal/kubernetes/core/v1/pod/container/hostalias/expand.go
This file was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
internal/kubernetes/core/v1/pod/container/hostalias/fields.go
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
internal/kubernetes/core/v1/pod/container/hostalias/flatten.go
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
internal/kubernetes/core/v1/pod/container/hostalias/hostname/expand.go
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
internal/kubernetes/core/v1/pod/container/hostalias/hostname/fields.go
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.