Skip to content
This repository has been archived by the owner on Dec 5, 2020. It is now read-only.

Commit

Permalink
Merge pull request #56 from meyskens/no-cache
Browse files Browse the repository at this point in the history
Remove cache
  • Loading branch information
alexsomesan authored Oct 30, 2019
2 parents cbc7483 + 0c77cd9 commit 5a1af20
Show file tree
Hide file tree
Showing 45 changed files with 898 additions and 334 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ module github.com/terraform-providers/terraform-provider-ignition
require (
github.com/coreos/ignition v0.0.0-20170904171445-ea573e121f72
github.com/hashicorp/terraform v0.12.0
github.com/pkg/errors v0.8.1
github.com/vincent-petithory/dataurl v0.0.0-20160330182126-9a301d65acbb // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ github.com/packer-community/winrmcp v0.0.0-20180102160824-81144009af58/go.mod h1
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pkg/errors v0.0.0-20170505043639-c605e284fe17 h1:chPfVn+gpAM5CTpTyVU9j8J+xgRGwmoDlNDLjKnJiYo=
github.com/pkg/errors v0.0.0-20170505043639-c605e284fe17/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
Expand Down
147 changes: 0 additions & 147 deletions ignition/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,12 @@ import (
"encoding/json"
"fmt"
"log"
"sync"

"github.com/coreos/ignition/config/v2_1/types"
"github.com/coreos/ignition/config/validate/report"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)

// globalCache keeps the instances of the internal types of ignition generated
// by the different data resources with the goal to be reused by the
// ignition_config data resource. The key of the maps are a hash of the types
// calculated on the type serialized to JSON.
var globalCache = &cache{
disks: make(map[string]*types.Disk, 0),
arrays: make(map[string]*types.Raid, 0),
filesystems: make(map[string]*types.Filesystem, 0),
files: make(map[string]*types.File, 0),
directories: make(map[string]*types.Directory, 0),
links: make(map[string]*types.Link, 0),
systemdUnits: make(map[string]*types.Unit, 0),
networkdUnits: make(map[string]*types.Networkdunit, 0),
users: make(map[string]*types.PasswdUser, 0),
groups: make(map[string]*types.PasswdGroup, 0),
}

func Provider() terraform.ResourceProvider {
return &schema.Provider{
DataSourcesMap: map[string]*schema.Resource{
Expand All @@ -49,121 +30,6 @@ func Provider() terraform.ResourceProvider {
}
}

type cache struct {
disks map[string]*types.Disk
arrays map[string]*types.Raid
filesystems map[string]*types.Filesystem
files map[string]*types.File
directories map[string]*types.Directory
links map[string]*types.Link
systemdUnits map[string]*types.Unit
networkdUnits map[string]*types.Networkdunit
users map[string]*types.PasswdUser
groups map[string]*types.PasswdGroup

sync.Mutex
}

func (c *cache) addDisk(g *types.Disk) string {
c.Lock()
defer c.Unlock()

id := id(g)
c.disks[id] = g

return id
}

func (c *cache) addRaid(r *types.Raid) string {
c.Lock()
defer c.Unlock()

id := id(r)
c.arrays[id] = r

return id
}

func (c *cache) addFilesystem(f *types.Filesystem) string {
c.Lock()
defer c.Unlock()

id := id(f)
c.filesystems[id] = f

return id
}

func (c *cache) addFile(f *types.File) string {
c.Lock()
defer c.Unlock()

id := id(f)
c.files[id] = f

return id
}

func (c *cache) addDirectory(d *types.Directory) string {
c.Lock()
defer c.Unlock()

id := id(d)
c.directories[id] = d

return id
}

func (c *cache) addLink(l *types.Link) string {
c.Lock()
defer c.Unlock()

id := id(l)
c.links[id] = l

return id
}

func (c *cache) addSystemdUnit(u *types.Unit) string {
c.Lock()
defer c.Unlock()

id := id(u)
c.systemdUnits[id] = u

return id
}

func (c *cache) addNetworkdUnit(u *types.Networkdunit) string {
c.Lock()
defer c.Unlock()

id := id(u)
c.networkdUnits[id] = u

return id
}

func (c *cache) addUser(u *types.PasswdUser) string {
c.Lock()
defer c.Unlock()

id := id(u)
c.users[id] = u

return id
}

func (c *cache) addGroup(g *types.PasswdGroup) string {
c.Lock()
defer c.Unlock()

id := id(g)
c.groups[id] = g

return id
}

func id(input interface{}) string {
b, _ := json.Marshal(input)
return hash(string(b))
Expand All @@ -174,19 +40,6 @@ func hash(s string) string {
return hex.EncodeToString(sha[:])
}

func castSliceInterface(i []interface{}) []string {
var o []string
for _, value := range i {
if value == nil {
continue
}

o = append(o, value.(string))
}

return o
}

func getInt(d *schema.ResourceData, key string) *int {
var i *int
if value, ok := d.GetOk(key); ok {
Expand Down
Loading

0 comments on commit 5a1af20

Please sign in to comment.